1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-21 11:54:15 +01:00

version-info.py: reformat source according to python style guide

http://www.python.org/dev/peps/pep-0008/#indentation
"Use 4 spaces per indentation level."
This commit is contained in:
Oleg Semyonov 2012-12-14 03:10:33 +02:00
parent 58e62d4f86
commit 1e3c47dffa

View File

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