changeset 102:a09fab386ed7

unrolling this to look more like the installed version of gitpoller
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 22 Jan 2011 15:57:02 -0800
parents 21ce7537d80d
children 7c63adbb5eec
files autobot/changes/poller.py
diffstat 1 files changed, 72 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/autobot/changes/poller.py	Tue Jan 18 17:54:19 2011 -0800
+++ b/autobot/changes/poller.py	Sat Jan 22 15:57:02 2011 -0800
@@ -58,27 +58,30 @@
         self.initLock = defer.DeferredLock()
         
         if not self.workdir:
-            self.workdir = tempfile.gettempdir()
+            self.workdir = tempfile.mkdtemp()
 
         self.name = self.__class__.__name__
 
-    def startService(self):
+#     def startService(self):
 
-        base.PollingChangeSource.startService(self)
+#         base.PollingChangeSource.startService(self)
 
-        # initialize the repository we'll use to get changes; note that
-        # startService is not an event-driven method, so this method will
-        # instead acquire self.initLock immediately when it is called.
-        if not self.isInitialized():
-            d = self.initRepository()
-            d.addErrback(log.err, 'while initializing %s repository' % self.name)
-        else:
-            log.msg("%s repository already exists" % self.name)
+#         # initialize the repository we'll use to get changes; note that
+#         # startService is not an event-driven method, so this method will
+#         # instead acquire self.initLock immediately when it is called.
+#         if not self.isInitialized():
+#             log.msg('Initializing new repository')
+# #            d = self.initRepository()
+# #            d.addErrback(log.err, 'while initializing %s repository at %s' % (self.name, self.workdir))
+#         else:
+#             log.msg("%s repository already exists" % self.name)
 
-        # call this *after* initRepository, so that the initLock is locked first
+#         log.msg("%s startService with repository %s" % (self.name, self.workdir))
+
+#         # call this *after* initRepository, so that the initLock is locked first
 
 
-    def initRepository(self):
+    def initRepository(self, _):
         """initialize a repository or whatever"""
 
         # make the directory, if necessary
@@ -102,7 +105,7 @@
 
         # finish up
         def log_finished(_):
-            log.msg("%s: finished initializing working dir from %s" % (self.name, self.repourl))
+            log.msg("%s: finished initializing working dir %s from %s" % (self.name, self.workdir, self.repourl))
         d.addCallback(log_finished)
         return d
 
@@ -116,35 +119,65 @@
 
     def poll(self):
         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._process_changes)
+#        d.addErrback(self._process_changes_failure)
+#        d.addCallback(self._catch_up)
+#        d.addErrback(self._catch_up_failure)
         return d
 
-    @defer.deferredGenerator
+    
+
+    def _setPreHash(self, _hash):
+        self.preHash = _hash.strip()
+        log.msg("The secret key is %s" % _hash)
+
+    def _setPostHash(self, _hash):
+        self.postHash = _hash.strip()
+        log.msg("The *NEW* secret key is %s" % _hash)
+
+#    @defer.deferredGenerator
     def _get_changes(self):
         """update the changes if the hash doesnt match"""
-        
-        log.msg('%s: polling repo at %s' % (self.name, self.repourl))
+
         self.lastPoll = time.time()
+        log.msg('%s: polling repo at %s : %s' % (self.name, self.repourl, self.lastPoll))
+
+        d = defer.succeed(None)
+        # ensure the repository is initialized
+        if not self.isInitialized():
+            log.msg('Initialing new repository')
+#            d = self.initRepository()
+            d.addCallback(self.initRepository)
 
         # get the hash before updating
-        d = self._hash()
-        wfd = defer.waitForDeferred(d)
-        yield wfd
-        results = wfd.getResult()
-        self.preHash = results.strip()
+        log.msg("About to get prehash")
+        d.addCallback(self._hash)
+        d.addCallback(self._setPreHash)
+
+        # update
+        d.addCallback(self._fetch)
+
+        # set the post hash
+        d.addCallback(self._hash)
+        d.addCallback(self._setPostHash)
+        
+        return d
 
-        # get a deferred object that performs the fetch
-        yield self._fetch()
+#         wfd = defer.waitForDeferred(d)
+#         yield wfd
+#         results = wfd.getResult()
+#         self.preHash = results.strip()
+#         log.msg('prehash = %s' % self.preHash)
+
+#         # get a deferred object that performs the fetch
+#         yield self._fetch()
         
-        # get the hash after updating
-        d = self._hash()
-        wfd = defer.waitForDeferred(d)
-        yield wfd
-        results = wfd.getResult()
-        self.postHash = results.strip()
+#         # get the hash after updating
+#         d = self._hash()
+#         wfd = defer.waitForDeferred(d)
+#         yield wfd
+#         results = wfd.getResult()
+#         self.postHash = results.strip()
 
 
     @defer.deferredGenerator
@@ -240,12 +273,12 @@
         return os.path.exists(os.path.join(self.workdir, '.hg'))
 
     def initializationCommands(self):
-        return [ [ 'clone', self.repourl ] ]
+        return [ [ 'clone', self.repourl, self.workdir ] ]
 
-    def _fetch(self):
+    def _fetch(self, _):
 
         # get a deferred object that performs the fetch
-        args = ['pull']
+        args = ['pull', self.repourl]
         # This command always produces data on stderr, but we actually do not care
         # about the stderr or stdout from this command. We set errortoo=True to
         # avoid an errback from the deferred. The callback which will be added to this
@@ -255,13 +288,13 @@
         return d
 
 
-    @defer.deferredGenerator
-    def _hash(self):
+    def _hash(self, _):
         d = utils.getProcessOutput(self.binary, ['tip', '--template', '{node}\\n'],
                                    path=self.workdir,
                                    env=dict(PATH=os.environ['PATH']), errortoo=False )
         return d
 
+
     def _change_list(self):
         """
         return a deferred something-or-other that has the changes to be