changeset 103:7c63adbb5eec

rearrange functions
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 22 Jan 2011 17:05:40 -0800
parents a09fab386ed7
children 41370b2f96e0
files autobot/changes/poller.py
diffstat 1 files changed, 50 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/autobot/changes/poller.py	Sat Jan 22 15:57:02 2011 -0800
+++ b/autobot/changes/poller.py	Sat Jan 22 17:05:40 2011 -0800
@@ -121,19 +121,19 @@
         d = self._get_changes()
 #        d.addCallback(self._process_changes)
 #        d.addErrback(self._process_changes_failure)
-#        d.addCallback(self._catch_up)
-#        d.addErrback(self._catch_up_failure)
+        d.addCallback(self._catch_up)
+        d.addErrback(self._catch_up_failure)
         return d
 
     
 
     def _setPreHash(self, _hash):
         self.preHash = _hash.strip()
-        log.msg("The secret key is %s" % _hash)
+        log.msg("The secret key is %s" % self.preHash)
 
     def _setPostHash(self, _hash):
         self.postHash = _hash.strip()
-        log.msg("The *NEW* secret key is %s" % _hash)
+        log.msg("The *NEW* secret key is %s" % self.postHash)
 
 #    @defer.deferredGenerator
     def _get_changes(self):
@@ -180,21 +180,25 @@
 #         self.postHash = results.strip()
 
 
-    @defer.deferredGenerator
+#    @defer.deferredGenerator
     def _process_changes(self, unused_output):
 
+        d = defer.succeed(None)
+
         # get the change list
         self.changeCount = 0
         if self.preHash == self.postHash:
-            return
-        d = self._change_list()
-        wfd = defer.waitForDeferred(d)
-        yield wfd
-        results = wfd.getResult()
+            return d
+
+        d.addCallback(self._change_list)
+        d.addCallback(self._process_change_list)
+        return d
+
+    def _process_change_list(self, changelist):
         
         # process oldest change first
-        revList = results.split()
-        if not revList:
+        revList = changelist.split()
+        if not revList or revList == ['']:
             return
         revList.reverse()
         self.changeCount = len(revList)
@@ -203,39 +207,40 @@
 
         # get metadata for changes and send them to master
         for rev in revList:
+            pass
 
-            # get metadata
-            dl = defer.DeferredList([
-                self._get_commit_timestamp(rev),
-                self._get_commit_name(rev),
-                self._get_commit_files(rev),
-                self._get_commit_comments(rev),
-            ], consumeErrors=True)
-            wfd = defer.waitForDeferred(dl)
-            yield wfd
-            results = wfd.getResult()
+#             # get metadata
+#             dl = defer.DeferredList([
+#                 self._get_commit_timestamp(rev),
+#                 self._get_commit_name(rev),
+#                 self._get_commit_files(rev),
+#                 self._get_commit_comments(rev),
+#             ], consumeErrors=True)
+#             wfd = defer.waitForDeferred(dl)
+#             yield wfd
+#             results = wfd.getResult()
 
-            # check for failures
-            failures = [ r[1] for r in results if not r[0] ]
-            if failures:
-                # just fail on the first error; they're probably all related!
-                raise failures[0]
+#             # check for failures
+#             failures = [ r[1] for r in results if not r[0] ]
+#             if failures:
+#                 # just fail on the first error; they're probably all related!
+#                 raise failures[0]
 
-            # send the change to the master
-            timestamp, name, files, comments = [ r[1] for r in results ]
-            d = self.master.addChange(
-                   who=name,
-                   revision=rev,
-                   files=files,
-                   comments=comments,
-                   when=timestamp,
-                   branch=self.branch,
-                   category=self.category,
-                   project=self.project,
-                   repository=self.repourl)
-            wfd = defer.waitForDeferred(d)
-            yield wfd
-            results = wfd.getResult()
+#             # send the change to the master
+#             timestamp, name, files, comments = [ r[1] for r in results ]
+#             d = self.master.addChange(
+#                    who=name,
+#                    revision=rev,
+#                    files=files,
+#                    comments=comments,
+#                    when=timestamp,
+#                    branch=self.branch,
+#                    category=self.category,
+#                    project=self.project,
+#                    repository=self.repourl)
+#             wfd = defer.waitForDeferred(d)
+#             yield wfd
+#             results = wfd.getResult()
 
     def _process_changes_failure(self, f):
         log.msg('%s: repo poll failed' % self.name)
@@ -295,7 +300,7 @@
         return d
 
 
-    def _change_list(self):
+    def _change_list(self, _):
         """
         return a deferred something-or-other that has the changes to be
         processed.  XXX the format is pretty particular
@@ -306,11 +311,11 @@
                                    env=dict(PATH=os.environ['PATH']), errortoo=False )
         return d
         
-    def _catch_up(self, res):
+    def _catch_up(self, rev):
+        log.msg('%s: catching up to %s' % (self.name, self.postHash))
         if self.changeCount == 0:
             log.msg('%s: no changes, no catch_up' % self.name)
             return
-        log.msg('%s: catching up' % self.name)
         args = ['update']
         d = utils.getProcessOutputAndValue(self.binary, args, path=self.workdir, env=dict(PATH=os.environ['PATH']))
         d.addCallback(self._convert_nonzero_to_failure)