Commits

yml ...@gmail.com  committed 111c5ac Merge

Automated merge with ssh://hg@bitbucket.org/yml/fabric_factory/

  • Participants
  • Parent commits 76f4c3d, 0fa64a0

Comments (0)

Files changed (2)

File src/worker/__init__.py

 from glob import glob
 from imp import load_source
 from shutil import rmtree
+from StringIO import StringIO
 import logging
 import os
 import simplejson
+import sys
 import tarfile
 import urllib
 import urllib2
                             "fabfile.py")
         file_path = os.path.join(self.kitchen_path, file)
         self.output, self.error = self._execute_task_from_fabfile(file_path, self.task)  # We should collect this output
+        import ipdb; ipdb.set_trace()
         if self.error:
             self.success = True
         else:
                 rmtree(f)
     @staticmethod
     def _execute_task_from_fabfile(fabfile_path, task):
+
         fabfile = load_source("fabfile",
                     fabfile_path)
         if hasattr(fabfile, task):
             task = getattr(fabfile, task)
+            # capture sys.stdout and sys.stderr
+            # before executing the task
+            output = StringIO()
+            error = StringIO()
+            sys.stdout = output
+            sys.stderr = error
             # execute the task
-            output = task()  # We should collect this output
-            error = None # TODO : Find a way to collect the error
-            return (output, error)
+            task()
+            sys.stdout = sys.__stdout__
+            sys.stderr = sys.__stderr__
+            return (output.getvalue(), error.getvalue())
         else:
             raise WorkerError("No task %s in fabfile %s" %
                                             (task, fabfile_path))

File src/worker/tests/__init__.py

         self.wrong_task = "wrong task"
         
     def test_execute_task_from_fabfile(self):
-        result = Worker._execute_task_from_fabfile(self.fabfile_path, self.task)
-        self.assertEqual(result, "")
+        output, error = Worker._execute_task_from_fabfile(self.fabfile_path, self.task)
+        self.assertEqual(output, 'hello world\n')
+        self.assertEqual(error, "")
         
     # TODO this test fails because I do not know hos to collect output and error
     # from Fabric