except: me...

This commit is contained in:
Barış Metin
2005-10-12 09:18:06 +00:00
parent 78d30dad2b
commit 1a6915dbe9
+20 -16
View File
@@ -255,9 +255,21 @@ def get_file_hashes(top, exclude_prefix=None, removePrefix=None):
used to remove prefix from filePath while matching excludes, if used to remove prefix from filePath while matching excludes, if
given.""" given."""
def sha1_sum(f, data=False):
func = None
if data:
func = sha1_data
else:
func = sha1_file
try:
return func(f)
except FileError:
return "0"
# also handle single files # also handle single files
if os.path.isfile(top): if os.path.isfile(top):
yield (top, sha1_file(top)) yield (top, sha1_sum(top))
return return
def has_excluded_prefix(filename): def has_excluded_prefix(filename):
@@ -273,7 +285,7 @@ def get_file_hashes(top, exclude_prefix=None, removePrefix=None):
if os.path.islink(root) and not has_excluded_prefix(root): if os.path.islink(root) and not has_excluded_prefix(root):
#yield the symlink.. #yield the symlink..
#bug 373 #bug 373
yield (root, sha1_data(os.readlink(root))) yield (root, sha1_sum(os.readlink(root)))
exclude_prefix.append(remove_prefix(removePrefix, root) + "/") exclude_prefix.append(remove_prefix(removePrefix, root) + "/")
continue continue
@@ -281,7 +293,7 @@ def get_file_hashes(top, exclude_prefix=None, removePrefix=None):
for dir in dirs: for dir in dirs:
d = os.path.join(root, dir) d = os.path.join(root, dir)
if os.path.islink(d) and not has_excluded_prefix(d): if os.path.islink(d) and not has_excluded_prefix(d):
yield (d, sha1_data(os.readlink(d))) yield (d, sha1_sum(os.readlink(d)))
exclude_prefix.append(remove_prefix(removePrefix, d) + "/") exclude_prefix.append(remove_prefix(removePrefix, d) + "/")
#bug 340 #bug 340
@@ -289,7 +301,7 @@ def get_file_hashes(top, exclude_prefix=None, removePrefix=None):
parent, r, d, f = root, '', '', '' parent, r, d, f = root, '', '', ''
for r, d, f in os.walk(parent, topdown=False): pass for r, d, f in os.walk(parent, topdown=False): pass
if not f and not d: if not f and not d:
yield (parent, sha1_file(parent)) yield (parent, sha1_sum(parent))
for fname in files: for fname in files:
f = os.path.join(root, fname) f = os.path.join(root, fname)
@@ -297,9 +309,9 @@ def get_file_hashes(top, exclude_prefix=None, removePrefix=None):
continue continue
#bug 373 #bug 373
elif os.path.islink(f): elif os.path.islink(f):
yield (f, sha1_data(os.readlink(f))) yield (f, sha1_sum(os.readlink(f)))
else: else:
yield (f, sha1_file(f)) yield (f, sha1_sum(f))
def copy_dir(src, dest): def copy_dir(src, dest):
"""copy source dir to destination dir recursively""" """copy source dir to destination dir recursively"""
@@ -322,11 +334,7 @@ def sha1_file(filename):
m.update(line) m.update(line)
return m.hexdigest() return m.hexdigest()
except IOError: except IOError:
# raise FileError(_("Cannot calculate SHA1 hash of %s") % filename) raise FileError(_("Cannot calculate SHA1 hash of %s") % filename)
#
# Don't raise Error here. Broken links can be present in
# package and returning 0 is totaly fine here!
return "0"
def sha1_data(data): def sha1_data(data):
"""calculate sha1 hash of given data""" """calculate sha1 hash of given data"""
@@ -335,11 +343,7 @@ def sha1_data(data):
m.update(data) m.update(data)
return m.hexdigest() return m.hexdigest()
except: except:
# raise Error(_("Cannot calculate SHA1 hash of given data")) raise Error(_("Cannot calculate SHA1 hash of given data"))
#
# Don't raise Error here. Broken links can be present in
# package and returning 0 is totaly fine here!
return "0"
def uncompress(patchFile, compressType="gz", targetDir=None): def uncompress(patchFile, compressType="gz", targetDir=None):
"""uncompresses a file and returns the path of the uncompressed """uncompresses a file and returns the path of the uncompressed