changeset 108:3f4e4bbde2e4

get the metadata
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 22 Jan 2011 17:43:49 -0800
parents 2de1c1410b77
children 2cd364f793e2
files autobot/changes/poller.py
diffstat 1 files changed, 59 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/autobot/changes/poller.py	Sat Jan 22 17:20:01 2011 -0800
+++ b/autobot/changes/poller.py	Sat Jan 22 17:43:49 2011 -0800
@@ -194,41 +194,34 @@
         d.addCallback(self._process_change_list)
         return d
 
-    def _process_change_list(self, changelist):
+    def _process_change_list(self, revList):
 
         log.msg('this is the changelist: %s' % changelist)
-        return
-        # process oldest change first
-        revList = changelist.split()
-        if not revList or revList == ['']:
-            return
-        revList.reverse()
         self.changeCount = len(revList)
         log.msg('%s: processing %d changes: %s in "%s"'
                 % (self.name, self.changeCount, revList, self.workdir) )
 
         # get metadata for changes and send them to master
         for rev in revList:
-            pass
+            self.commitInfo = {}
+
+            # 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)
 
-#             # 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()
+            # add the change, apparently
+            dl.addCallback(self.add_change, rev)
 
-#             # 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]
+    def _add_change(self, change):
+        log.msg("_add_change results")
 
-#             # send the change to the master
+        
+
+        # send the change to the master
 #             timestamp, name, files, comments = [ r[1] for r in results ]
 #             d = self.master.addChange(
 #                    who=name,
@@ -332,55 +325,68 @@
 
     ### functions for retrieving various metadatas
 
+    ### timestamp
+
     def _get_commit_timestamp(self, rev):
         # unix timestamp
         args = ['log', '-r', rev, '--template', '{date|hgdate}']
         d = utils.getProcessOutput(self.binary, args, path=self.workdir, env=dict(PATH=os.environ['PATH']), errortoo=False )
-        def process(output):
-            stripped_output = output.strip()
-            if self.usetimestamps:
-                try:
-                    _stamp, offset = output.split()
-                    stamp = float(_stamp)
-                except Exception, e:
-                        log.msg('%s: caught exception converting output "%s" to timestamp' % (self.name, stripped_output))
-                        raise e
-                return stamp
-            else:
-                return None
-        d.addCallback(process)
+        d.addCallback(self._get_commit_timestamp_from_output)
         return d
 
+    def _get_commit_timestamp_from_output(self, output):
+        stripped_output = output.strip()
+        if self.usetimestamps:
+            try:
+                _stamp, offset = output.split()
+                stamp = float(_stamp)
+            except Exception, e:
+                log.msg('%s: caught exception converting output "%s" to timestamp' % (self.name, stripped_output))
+                raise e
+            self.commitInfo['timestamp'] = stamp
+        else:
+            self.commitInfo['timestamp'] = None
+
+    ### commit author ('name')
+
     def _get_commit_name(self, rev):
         """get the author of a commit"""
         args = ['log', '-r', rev, '--template', '{author}']
         d = utils.getProcessOutput(self.binary, args, path=self.workdir, env=dict(PATH=os.environ['PATH']), errortoo=False )
-        def process(output):
-            stripped_output = output.strip()
-            if len(stripped_output) == 0:
-                raise EnvironmentError('could not get commit name for rev')
-            return stripped_output
-        d.addCallback(process)
+        d.addCallback(self._get_commit_name_from_output)
         return d
 
+    def process(self, output):
+        stripped_output = output.strip()
+        if len(stripped_output) == 0:
+            raise EnvironmentError('could not get commit name for rev')
+        self.commitInfo['name'] = stripped_output
+        return self.commitInfo['name'] # for tests, or so gitpoller says
+
+    ### files
+
     def _get_commit_files(self, rev):
         """get the files associated with a commit"""
         args = ['log', '-r', rev, '--template', '{files}']
         d = utils.getProcessOutput(self.binary, args, path=self.workdir, env=dict(PATH=os.environ['PATH']), errortoo=False )
-        def process(output):
-            fileList = output.split()
-            return fileList
-        d.addCallback(process)
+        d.addCallback(self._get_commit_files_from_output)
         return d
 
+    def _get_commit_files_from_output(self, output):
+        fileList = output.strip.split()
+        self.commitInfo['files'] = fileList
+        return self.commitInfo['files']
+
+    ### comments
+
     def _get_commit_comments(self, rev):
         """get the commit message"""
         args = ['log', '-r', rev, '--template', '{desc}']
         d = utils.getProcessOutput(self.binary, args, path=self.workdir, env=dict(PATH=os.environ['PATH']), errortoo=False )
-        def process(output):
-            stripped_output = output.strip()
-            if len(stripped_output) == 0:
-                raise EnvironmentError('could not get commit comment for rev')
-            return stripped_output
-        d.addCallback(process)
+        d.addCallback(self._get_commit_comments_from_output)
         return d
+
+    def _get_commit_comments_from_output(self, output):
+        stripped_output = output.strip()
+        self.commitInfo['comments'] = stripped_output
+        return self.commitInfo['comments']