Bug 1455143 - Handle directory inputs earlier; r?Build
This makes the logic in process_files() simpler.
MozReview-Commit-ID: KdphRJZLinx
--- a/build/checksums.py
+++ b/build/checksums.py
@@ -54,33 +54,30 @@ def process_files(files, output_filename
if os.path.exists(output_filename):
logger.debug('Overwriting existing checksums file "%s"' %
output_filename)
else:
logger.debug('Creating a new checksums file "%s"' % output_filename)
with open(output_filename, 'w+') as output:
for file in files:
- if os.path.isdir(file):
- logger.warn('%s is a directory, skipping' % file)
- else:
- for digest in digests:
- hash = digest_file(file, digest)
- if hash is None:
- logger.warn('Unable to generate a hash for %s. ' +
- 'Skipping.' % file)
- continue
- if file.startswith(strip):
- short_file = file[len(strip):]
- short_file = short_file.lstrip('/')
- else:
- short_file = file
- print >>output, '%s %s %s %s' % (hash, digest,
- os.path.getsize(file),
- short_file)
+ for digest in digests:
+ hash = digest_file(file, digest)
+ if hash is None:
+ logger.warn('Unable to generate a hash for %s. ' +
+ 'Skipping.' % file)
+ continue
+ if file.startswith(strip):
+ short_file = file[len(strip):]
+ short_file = short_file.lstrip('/')
+ else:
+ short_file = file
+ print >>output, '%s %s %s %s' % (hash, digest,
+ os.path.getsize(file),
+ short_file)
def setup_logging(level=logging.DEBUG):
'''This function sets up the logging module using a speficiable logging
module logging level. The default log level is DEBUG.
The output is in the format:
<level> - <message>
@@ -129,17 +126,19 @@ def main():
# Validate the digest type to use
if not options.digests:
options.digests = ['sha1']
# Validate the files to checksum
files = []
for i in args:
- if os.path.exists(i):
+ if os.path.isdir(i):
+ logger.warn('%s is a directory; ignoring' % i)
+ elif os.path.exists(i):
files.append(i)
else:
logger.info('File "%s" was not found on the filesystem' % i)
process_files(files, options.outfile, options.digests, options.strip)
if __name__ == '__main__':
main()