Skip to content
This repository has been archived by the owner on Mar 7, 2021. It is now read-only.

Commit

Permalink
begonia: update-sha1sums: Handle line with opts
Browse files Browse the repository at this point in the history
Change-Id: Ia41000b36f3535a3cf0ef8d7650d0d540de728de
  • Loading branch information
moetayuko authored and theimpulson committed Nov 30, 2020
1 parent d3df4a4 commit f0594df
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions update-sha1sums.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
# limitations under the License.
#

from hashlib import sha1
import os
import sys
from hashlib import sha1

device='begonia'
vendor='xiaomi'
Expand All @@ -31,13 +32,11 @@
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():
Expand All @@ -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)


Expand Down

0 comments on commit f0594df

Please sign in to comment.