Commits

Ronny Pfannschmidt committed cb73813

refactor event emission

  • Participants
  • Parent commits 7593b49

Comments (0)

Files changed (4)

glas_process/baseproc.py

 import gevent
 from gevent.queue import Queue
-from .model import Step
+from .model import Step, Event
 
 
 class Proc(object):
 
     def _store(self):
         for i, doc in enumerate(self.queue):
+            if isinstance(doc, dict):
+                doc = Event(**doc)
             if not doc._id:
                 doc._id = '%s:%s' %(self.step._id, i)
+            if not doc.step:
+                doc.step = self.step._id
+            doc.index = i
+
             self.save_with_batch(doc)
             returncode = getattr(doc, 'returncode', None)
             if returncode is not None and self.step is not None:

glas_process/scm.py

         if not target.check(dir=1):
             self.wd = anyvc.workdir.clone(repo, target)
         else:
-            pass  #XXX
+            pass  # XXX
 
     def reset_state(self):
         "undo patches, purge workdir if exists"

glas_process/subprocess.py

 
 import subprocess
 import gevent
-from gevent import socket
-
-from .model import Event
+from gevent.socket import wait_read
 from glas_process.baseproc import Proc
 
 
             for line in lines:
                 yield line
             remainder #XXX: pyflakes
-        socket.wait_read(fp.fileno())
+        wait_read(fp.fileno())
 
 
 def _stream_reader(step, proc, stream, queue):
     fp = getattr(proc, stream)
     for lineno, line in enumerate(stream_line_iter(fp)):
-        queue.put(Event(
-            step=step._id,
-            stream=stream,
-            lineno=lineno,
-            line=line,
-        ))
+        queue.put({
+            'stream': stream,
+            'lineno': lineno,
+            'line': line,
+        })
 
 def _exit_poller(step, proc, q):
     while True:
         gevent.sleep(.1)
         code = proc.poll()
         if code is not None:
-            q.put(Event(step=step._id, returncode=code))
+            q.put({'returncode': code})
             return
 
 def _joinall(queue, *greenlets):

testing/test_scmprocdir.py

     gevent.sleep(0)
     assert procdir.path.check()
     p.update_wd()
-