diff --git a/make/scripts/version-info.py b/make/scripts/version-info.py index 2dc0d4381..e3a3724d6 100644 --- a/make/scripts/version-info.py +++ b/make/scripts/version-info.py @@ -267,58 +267,59 @@ def xtrim(string, suffix, length): return ''.join([string[:n], '+', suffix]) def GetHashofDirs(directory, verbose=0, raw=0): - import hashlib, os - SHAhash = hashlib.sha1() - if not os.path.exists (directory): - return -1 - - try: - for root, dirs, files in os.walk(directory): - # os.walk() is unsorted. Must make sure we process files in sorted order so - # that the hash is stable across invocations and across OSes. - if files: - files.sort() + """Return hash of XML files from UAVObject definition directory""" + import hashlib, os + SHAhash = hashlib.sha1() + if not os.path.exists (directory): + return -1 - for names in files: - if verbose == 1: - print 'Hashing', names - filepath = os.path.join(root,names) - try: - f1 = open(filepath, 'rU') - except: - # You can't open the file for some reason - f1.close() - continue + try: + for root, dirs, files in os.walk(directory): + # os.walk() is unsorted. Must make sure we process files in sorted + # order so that the hash is stable across invocations and across OSes. + if files: + files.sort() - # Compute file hash. Same as running "sha1sum ". - f1hash = hashlib.sha1() - while 1: - # Read file in as little chunks - buf = f1.read(4096) - if not buf : break - f1hash.update(buf) - f1.close() + for names in files: + if verbose == 1: + print 'Hashing', names + filepath = os.path.join(root, names) + try: + f1 = open(filepath, 'rU') + except: + # You can't open the file for some reason + f1.close() + continue - if verbose == 1: - print 'Hash is', f1hash.hexdigest() + # Compute file hash. Same as running "sha1sum ". + f1hash = hashlib.sha1() + while 1: + # Read file in as little chunks + buf = f1.read(4096) + if not buf : break + f1hash.update(buf) + f1.close() - # Append the hex representation of the current file's hash into the cumulative hash - SHAhash.update(f1hash.hexdigest()) + if verbose == 1: + print 'Hash is', f1hash.hexdigest() - except: - import traceback - # Print the stack traceback - traceback.print_exc() - return -2 + # Append the hex representation of the current file's hash into the cumulative hash + SHAhash.update(f1hash.hexdigest()) - if verbose == 1: - print 'Final hash is', SHAhash.hexdigest() + except: + import traceback + # Print the stack traceback + traceback.print_exc() + return -2 - if raw == 1: - return SHAhash.hexdigest() - else: - hex_stream = lambda s:",".join(['0x'+hex(ord(c))[2:].zfill(2) for c in s]) - return hex_stream(SHAhash.digest()) + if verbose == 1: + print 'Final hash is', SHAhash.hexdigest() + + if raw == 1: + return SHAhash.hexdigest() + else: + hex_stream = lambda s:",".join(['0x'+hex(ord(c))[2:].zfill(2) for c in s]) + return hex_stream(SHAhash.digest()) def main(): """This utility uses git repository in the current working directory @@ -409,8 +410,8 @@ string given. BOARD_TYPE = args.type, BOARD_REVISION = args.revision, SHA1 = sha1(args.image), - UAVOSHA1TXT = GetHashofDirs(args.uavodir,verbose=0,raw=1), - UAVOSHA1 = GetHashofDirs(args.uavodir,verbose=0,raw=0), + UAVOSHA1TXT = GetHashofDirs(args.uavodir, verbose=0, raw=1), + UAVOSHA1 = GetHashofDirs(args.uavodir, verbose=0, raw=0), ) # Process positional arguments in the form of: