summaryrefslogtreecommitdiff
path: root/firehose/plugin/firehose_plugin.py
diff options
context:
space:
mode:
Diffstat (limited to 'firehose/plugin/firehose_plugin.py')
-rw-r--r--firehose/plugin/firehose_plugin.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/firehose/plugin/firehose_plugin.py b/firehose/plugin/firehose_plugin.py
index 200467e..dbce376 100644
--- a/firehose/plugin/firehose_plugin.py
+++ b/firehose/plugin/firehose_plugin.py
@@ -39,6 +39,8 @@ def firehose_git(app):
app.runcmd(["git", "config", "--global", "user.email", email])
class FirehosePlugin(cliapp.Plugin):
+ sha_filename=""
+
def enable(self):
logging.basicConfig(filename='/var/log/firehose.log',level=logging.INFO)
logging.info("Firehose plugin enabled")
@@ -138,15 +140,17 @@ class FirehosePlugin(cliapp.Plugin):
def log_sha(self, name):
sha = self.app.runcmd(['git', 'rev-parse', 'HEAD'], cwd=self.gitpath).strip()
- filename = '/var/lib/firehose/'+name+'_log.json'
- if (os.path.exists(os.path.abspath(filename))):
- log = open(filename).read()
- if sha in log:
- logging.info('Everything up-to-date')
- print 'Everything up-to-date'
- exit(0)
- log = open(filename, 'w')
- log.write('{\"sha\":\"'+sha+'\"}')
+ self.sha_filename = '/var/lib/firehose/'+name+'_log.json'
+ if (os.path.exists(os.path.abspath(self.sha_filename))):
+ with open(self.sha_filename) as f:
+ log = f.read()
+ if sha in log:
+ logging.info('Everything up-to-date')
+ print 'Everything up-to-date'
+ exit(0)
+ # Save the hash to a file
+ with open(self.sha_filename, 'w') as log:
+ log.write('{\"sha\":\"'+sha+'\"}')
logging.info('log_sha: wrote {\"sha\":\"'+sha+'\"}')
def insert_githook(self):
@@ -194,6 +198,9 @@ class FirehosePlugin(cliapp.Plugin):
return False
self.morphs.traverse_specs(process_spec, wanted_spec)
if len(urls) != 1:
+ # Remove the previously recorded hash
+ if self.sha_filename != "":
+ os.remove(self.sha_filename)
raise cliapp.AppException(
"Woah! expected 1 chunk matching %s:%s (got %d)" % (
stratum, chunk, len(urls)))