# HG changeset patch # User Jeff Hammel # Date 1296525090 28800 # Node ID dba6bcae15759c03589dee7076f565d1e4f49477 # Parent 6396220f937ef4eadcb034fd49a1f230b6023ab5 * removal of some excessive logging * more stubbing of our very own GitPoller diff -r 6396220f937e -r dba6bcae1575 autobot/changes/poller.py --- a/autobot/changes/poller.py Mon Jan 31 17:05:54 2011 -0800 +++ b/autobot/changes/poller.py Mon Jan 31 17:51:30 2011 -0800 @@ -111,6 +111,9 @@ d.addCallback(log_finished) return d + def log(self, msg): + log.msg('%s: %s' % (self.name, msg)) + def describe(self): status = "" if not self.parent: @@ -121,6 +124,7 @@ def poll(self): """poll for new changes""" + d = self._get_changes() d.addCallback(self._process_changes) d.addErrback(self._process_changes_failure) @@ -132,22 +136,22 @@ def _setPreHash(self, _hash): self.preHash = _hash.strip() - log.msg("preHash is %s" % self.preHash) + self.log("preHash is %s" % self.preHash) def _setPostHash(self, _hash): self.postHash = _hash.strip() - log.msg("postHash is %s" % self.postHash) + self.log("postHash is %s" % self.postHash) def _get_changes(self): """update the changes if the hash doesnt match""" self.lastPoll = time.time() - log.msg('%s: polling repo at %s : %s' % (self.name, self.repourl, self.lastPoll)) + self.log('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') + self.log('Initialing new repository') d.addCallback(self.initRepository) # get the hash before updating @@ -166,6 +170,7 @@ ### functions related to processing changes def _process_changes(self, _): + """processes the changes between the preHash and the postHash""" d = defer.succeed(None) @@ -180,16 +185,14 @@ def _process_change_list(self, revList): - log.msg('this is the changelist: %s' % revList) self.changeCount = len(revList) - log.msg('%s: processing %d changes: %s in "%s"' - % (self.name, self.changeCount, revList, self.workdir) ) + self.log('processing %d changes: %s in "%s"' + % (self.changeCount, revList, self.workdir) ) # get metadata for changes and send them to master d = defer.succeed(None) for rev in revList: d.addCallback(self._process_change, rev) - return d def _process_change(self, something, rev): @@ -257,7 +260,11 @@ return os.path.exists(os.path.join(self.workdir, '.hg')) def initializationCommands(self): - return [ [ 'clone', self.repourl, self.workdir ] ] + commands = [ [ 'clone', self.repourl, self.workdir ] ] + if self.branch != 'default': + # TODO + pass + return commands def _fetch(self, _): @@ -273,6 +280,7 @@ def _hash(self, _): + """commit hash""" d = utils.getProcessOutput(self.binary, ['tip', '--template', '{node}\\n'], path=self.workdir, env=dict(PATH=os.environ['PATH']), errortoo=False ) @@ -386,3 +394,33 @@ def isInitialized(self): """is the repository initialized?""" return os.path.exists(os.path.join(self.workdir, '.git')) + + def initializationCommands(self): + """commands needed to initialize the repository""" + + commands = [ [ 'clone', self.repourl, self.workdir ] ] + if self.branch != 'master': + commands.append(['checkout', self.branch]) + return commands + + def _fetch(self, _): + args = ['pull', 'origin', self.branch] + d = utils.getProcessOutput(self.binary, args, path=self.workdir, + env=dict(PATH=os.environ['PATH']), + errortoo=True) + return d + + def _hash(self, _): + """ + get hash of where you are now: + git show-ref HEAD --hash + """ + + d = utils.getProcessOutput(self.binary, ['show-ref', 'HEAD', '--hash'], + path=self.workdir, + env=dict(PATH=os.environ['PATH']), errortoo=False ) + return d + + def _change_list(self, _): + range = '%s..%s' % (self.preHash, self.postHash) + # TODO: finish!