burnin: move decorators out of classes
authorIustin Pop <iustin@google.com>
Tue, 29 Dec 2009 14:02:32 +0000 (15:02 +0100)
committerIustin Pop <iustin@google.com>
Mon, 4 Jan 2010 09:15:29 +0000 (10:15 +0100)
Similar to commit c881c5, we move the decorators out of classes, such
that they become simple functions instead of methods. This more clean,
since only the wrapped functions need to be methods/have access to
‘self’.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Olivier Tharan <olive@google.com>

tools/burnin

index 8b35058..3d70161 100755 (executable)
@@ -201,6 +201,39 @@ OPTIONS = [
 ARGUMENTS = [cli.ArgInstance(min=1)]
 
 
+def _DoCheckInstances(fn):
+  """Decorator for checking instances.
+
+  """
+  def wrapper(self, *args, **kwargs):
+    val = fn(self, *args, **kwargs)
+    for instance in self.instances:
+      self._CheckInstanceAlive(instance)
+    return val
+
+  return wrapper
+
+
+def _DoBatch(retry):
+  """Decorator for possible batch operations.
+
+  Must come after the _DoCheckInstances decorator (if any).
+
+  @param retry: whether this is a retryable batch, will be
+      passed to StartBatch
+
+  """
+  def wrap(fn):
+    def batched(self, *args, **kwargs):
+      self.StartBatch(retry)
+      val = fn(self, *args, **kwargs)
+      self.CommitQueue()
+      return val
+    return batched
+
+  return wrap
+
+
 class Burner(object):
   """Burner class."""
 
@@ -350,37 +383,6 @@ class Burner(object):
       raise BurninFailure()
     return results
 
-  def _DoCheckInstances(fn):
-    """Decorator for checking instances.
-
-    """
-    def wrapper(self, *args, **kwargs):
-      val = fn(self, *args, **kwargs)
-      for instance in self.instances:
-        self._CheckInstanceAlive(instance)
-      return val
-
-    return wrapper
-
-  def _DoBatch(retry):
-    """Decorator for possible batch operations.
-
-    Must come after the _DoCheckInstances decorator (if any).
-
-    @param retry: whether this is a retryable batch, will be
-        passed to StartBatch
-
-    """
-    def wrap(fn):
-      def batched(self, *args, **kwargs):
-        self.StartBatch(retry)
-        val = fn(self, *args, **kwargs)
-        self.CommitQueue()
-        return val
-      return batched
-
-    return wrap
-
   def ParseOptions(self):
     """Parses the command line options.