diff options
author | dianlujitao <dianlujitao@lineageos.org> | 2020-01-31 22:09:57 +0800 |
---|---|---|
committer | Michael Bestas <mkbestas@lineageos.org> | 2020-04-30 00:48:54 +0300 |
commit | 29498375c40f9f84c2b5efe50ba0092250050f46 (patch) | |
tree | fa43b0200bb1dce20b7b34e603d8afc6d8d42167 /update-sha1sums.py | |
parent | a38b083458f6fce17a58c984551196d843453e2b (diff) |
sdm660-common: update-sha1sums: Handle line with opts
Change-Id: Ia41000b36f3535a3cf0ef8d7650d0d540de728de
Diffstat (limited to 'update-sha1sums.py')
-rwxr-xr-x | update-sha1sums.py | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/update-sha1sums.py b/update-sha1sums.py index 52429be..56a94ff 100755 --- a/update-sha1sums.py +++ b/update-sha1sums.py @@ -16,8 +16,9 @@ # limitations under the License. # -from hashlib import sha1 +import os import sys +from hashlib import sha1 device = 'sdm660-common' vendor = 'xiaomi' @@ -31,13 +32,11 @@ needSHA1 = False def cleanup(): for index, line in enumerate(lines): # Skip empty or commented lines - if len(line) == 0 or line[0] == '#': + if len(line) == 0 or line[0] == '#' or '|' not in line: continue # Drop SHA1 hash, if existing - if '|' in line: - line = line.split('|')[0] - lines[index] = '%s' % (line) + lines[index] = line.split('|')[0] def update(): @@ -54,15 +53,14 @@ def update(): if needSHA1: # Remove existing SHA1 hash line = line.split('|')[0] - filePath = line.split(':')[1] if len( - line.split(':')) == 2 else line + filePath = line.split(';')[0].split(':')[-1] if filePath[0] == '-': - file = open('%s/%s' % (vendorPath, filePath[1:]), 'rb').read() - else: - file = open('%s/%s' % (vendorPath, filePath), 'rb').read() + filePath = filePath[1:] + + with open(os.path.join(vendorPath, filePath), 'rb') as f: + hash = sha1(f.read()).hexdigest() - hash = sha1(file).hexdigest() lines[index] = '%s|%s' % (line, hash) |