Bug 1455143 - Handle directory inputs earlier; r?Build draft
authorGregory Szorc <gps@mozilla.com>
Wed, 18 Apr 2018 15:35:57 -0700
changeset 785300 3bf7ce7764b4aaa32a9ddd01be70452664f63493
parent 785299 feb1ba3bbe0f5cb05925f176f0b191df5a7e9114
child 785301 02fe36000269a0a100bd7a5ca6fb6f32f3700dce
push id107184
push userbmo:gps@mozilla.com
push dateThu, 19 Apr 2018 21:22:59 +0000
reviewersBuild
bugs1455143
milestone61.0a1
Bug 1455143 - Handle directory inputs earlier; r?Build This makes the logic in process_files() simpler. MozReview-Commit-ID: KdphRJZLinx
build/checksums.py
--- 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()