diff options
author | lihongsx <lihongx.sun@intel.com> | 2014-08-04 23:23:47 +0800 |
---|---|---|
committer | admin <yuhuan.yang@samsung.com> | 2016-02-04 18:21:06 +0800 |
commit | f6dd9c1d9fe81e12763f1b8f57f8fa8ac9655df2 (patch) | |
tree | e9f56df3e9fe0dd24a05b0f4451b1416079261c7 | |
parent | 21e9247b403b8b98e10ac6f2d1b1b40d71ef290e (diff) | |
download | mic-f6dd9c1d9fe81e12763f1b8f57f8fa8ac9655df2.tar.gz mic-f6dd9c1d9fe81e12763f1b8f57f8fa8ac9655df2.tar.bz2 mic-f6dd9c1d9fe81e12763f1b8f57f8fa8ac9655df2.zip |
Add sha1sum and sha256sum
Fixes: #1956
Change-Id: I9eca40309e4a7eabb1cbc46424266312b3f2b10c
-rw-r--r-- | mic/imager/baseimager.py | 42 | ||||
-rwxr-xr-x | mic/utils/misc.py | 5 |
2 files changed, 31 insertions, 16 deletions
diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index 63ac3b9..dc7807d 100644 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -1309,22 +1309,32 @@ class BaseImageCreator(object): os.rename(_rpath(f), _rpath(newf)) outimages.append(_rpath(newf)) - # generate MD5SUMS - with open(_rpath("MD5SUMS"), "w") as wf: - for f in os.listdir(destdir): - if f == "MD5SUMS": - continue - - if os.path.isdir(os.path.join(destdir, f)): - continue - - md5sum = misc.get_md5sum(_rpath(f)) - # There needs to be two spaces between the sum and - # filepath to match the syntax with md5sum. - # This way also md5sum -c MD5SUMS can be used by users - wf.write("%s %s\n" % (md5sum, f)) - - outimages.append("%s/MD5SUMS" % destdir) + # generate MD5SUMS SHA1SUMS SHA256SUMS + def generate_hashsum(hash_name, hash_method): + with open(_rpath(hash_name), "w") as wf: + for f in os.listdir(destdir): + if f.endswith('SUMS'): + continue + + if os.path.isdir(os.path.join(destdir, f)): + continue + + hash_value = hash_method(_rpath(f)) + # There needs to be two spaces between the sum and + # filepath to match the syntax with md5sum,sha1sum, + # sha256sum. This way also *sum -c *SUMS can be used. + wf.write("%s %s\n" % (hash_value, f)) + + outimages.append("%s/%s" % (destdir, hash_name)) + + hash_dict = { + 'MD5SUMS' : misc.get_md5sum, + 'SHA1SUMS' : misc.get_sha1sum, + 'SHA256SUMS' : misc.get_sha256sum + } + + for k, v in hash_dict.items(): + generate_hashsum(k, v) # Filter out the nonexist file for fp in outimages[:]: diff --git a/mic/utils/misc.py b/mic/utils/misc.py index cd3e01a..bf377b4 100755 --- a/mic/utils/misc.py +++ b/mic/utils/misc.py @@ -261,6 +261,11 @@ def calc_hashes(file_path, hash_names, start = 0, end = None): def get_md5sum(fpath): return calc_hashes(fpath, ('md5', ))[0] +def get_sha1sum(fpath): + return calc_hashes(fpath, ('sha1', ))[0] + +def get_sha256sum(fpath): + return calc_hashes(fpath, ('sha256', ))[0] def normalize_ksfile(ksconf, release, arch): ''' |