diff options
author | Bob Mottram <bob.mottram@codethink.co.uk> | 2015-03-31 15:12:34 +0100 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-06-12 12:25:37 +0100 |
commit | f01a184b2694d7aa2bc153641b44f89ffcf47687 (patch) | |
tree | f9ccf5f5a392a979d87966df7325359397887b0c | |
parent | 6d9d053d70240a559b8c3b58701d42b240310f1a (diff) | |
download | firehose-f01a184b2694d7aa2bc153641b44f89ffcf47687.tar.gz |
Remove hash file on subsequent error
If an error occurs after the hash has been saved to a file
then delete the file so that it's possible to try again
Also, fix file descriptor leaks.
Change-Id: Ibe3edab5310357b23c64d8afccab53bf88db888c
-rw-r--r-- | firehose/plugin/firehose_plugin.py | 25 |
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))) |