diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-01-12 12:27:32 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-01-12 12:27:32 +0000 |
commit | c972012707f6555de6cf636d8eb5e2bf6e8ebf87 (patch) | |
tree | 47fa37403262b00e50ec8e7b2c29719e10b7e19b | |
parent | 9fe25bf02dceec04f0ffd6a05cc47146ceab9904 (diff) | |
parent | acf80a68ee41ec1d6bea531ea2fb00dc1227f2e3 (diff) | |
download | lorry-c972012707f6555de6cf636d8eb5e2bf6e8ebf87.tar.gz |
Merge branch 'sam/fix-tarball-failure'
Reviewed-By: Adam Coldrick <adam.coldrick@codethink.co.uk>
Reviewed-By: Francisco Redondo Marchena <francisco.marchena@codethink.co.uk>
-rwxr-xr-x | lorry | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -30,6 +30,12 @@ __version__ = '0.0' lorry_path = os.path.realpath(__file__) + +def file_missing_or_empty(filename): + ''' A more comprehensive alternative to os.path.exists(). ''' + return (not os.path.isfile(filename)) or (os.path.getsize(filename) <= 0) + + def quote_url(url): ''' Convert URIs to strings that only contain digits, letters, % and _. @@ -475,12 +481,17 @@ class Lorry(cliapp.Application): basename = os.path.basename(url_path) tardest = os.path.join(dirname, basename) self.progress('.. checking if we need to fetch %s' % basename) - if not os.path.exists(tardest): + if file_missing_or_empty(tardest): self.progress('.. attempting to fetch.') - with open(tardest, 'w') as tarfile: - urlfile = urllib2.urlopen(spec['url']) - tarfile.write(urlfile.read()) - urlfile.close() + try: + with open(tardest, 'w') as tarfile: + urlfile = urllib2.urlopen(spec['url']) + tarfile.write(urlfile.read()) + urlfile.close() + except Exception as e: + if os.path.exists(tardest): + os.unlink(tardest) + raise else: self.progress('.. no need to run, nothing to do') return |