summaryrefslogtreecommitdiff
path: root/update-sha1sums.py
diff options
context:
space:
mode:
Diffstat (limited to 'update-sha1sums.py')
-rwxr-xr-xupdate-sha1sums.py84
1 files changed, 47 insertions, 37 deletions
diff --git a/update-sha1sums.py b/update-sha1sums.py
index 56a94ff..f5623fd 100755
--- a/update-sha1sums.py
+++ b/update-sha1sums.py
@@ -20,54 +20,64 @@ import os
import sys
from hashlib import sha1
-device = 'sdm660-common'
-vendor = 'xiaomi'
+DEVICE = 'sdm660-common'
+VENDOR = 'xiaomi'
+VENDOR_PATH = os.path.join(
+ *['..', '..', '..', 'vendor', VENDOR, DEVICE, 'proprietary'])
-with open('proprietary-files.txt', 'r') as f:
- lines = f.read().splitlines()
-vendorPath = '../../../vendor/' + vendor + '/' + device + '/proprietary'
-needSHA1 = False
+class Updater:
+ def __init__(self, filename):
+ self.filename = filename
+ with open(self.filename, 'r') as f:
+ self.lines = f.read().splitlines()
-def cleanup():
- for index, line in enumerate(lines):
- # Skip empty or commented lines
- if len(line) == 0 or line[0] == '#' or '|' not in line:
- continue
+ def write(self):
+ with open(self.filename, 'w') as f:
+ f.write('\n'.join(self.lines) + '\n')
- # Drop SHA1 hash, if existing
- lines[index] = line.split('|')[0]
+ def cleanup(self):
+ for index, line in enumerate(self.lines):
+ # Skip empty or commented lines
+ if len(line) == 0 or line[0] == '#' or '|' not in line:
+ continue
+ # Drop SHA1 hash, if existing
+ self.lines[index] = line.split('|')[0]
-def update():
- for index, line in enumerate(lines):
- # Skip empty lines
- if len(line) == 0:
- continue
+ self.write()
- # Check if we need to set SHA1 hash for the next files
- if line[0] == '#':
- needSHA1 = (' - from' in line)
- continue
+ def update(self):
+ need_sha1 = False
+ for index, line in enumerate(self.lines):
+ # Skip empty lines
+ if len(line) == 0:
+ continue
- if needSHA1:
- # Remove existing SHA1 hash
- line = line.split('|')[0]
+ # Check if we need to set SHA1 hash for the next files
+ if line[0] == '#':
+ need_sha1 = (' - from' in line)
+ continue
- filePath = line.split(';')[0].split(':')[-1]
- if filePath[0] == '-':
- filePath = filePath[1:]
+ if need_sha1:
+ # Remove existing SHA1 hash
+ line = line.split('|')[0]
- with open(os.path.join(vendorPath, filePath), 'rb') as f:
- hash = sha1(f.read()).hexdigest()
+ file_path = line.split(';')[0].split(':')[-1]
+ if file_path[0] == '-':
+ file_path = file_path[1:]
- lines[index] = '%s|%s' % (line, hash)
+ with open(os.path.join(VENDOR_PATH, file_path), 'rb') as f:
+ hash = sha1(f.read()).hexdigest()
+ self.lines[index] = '{}|{}'.format(line, hash)
-if len(sys.argv) == 2 and sys.argv[1] == '-c':
- cleanup()
-else:
- update()
+ self.write()
-with open('proprietary-files.txt', 'w') as file:
- file.write('\n'.join(lines) + '\n')
+
+for file in ['proprietary-files.txt', 'proprietary-files-fm.txt']:
+ updater = Updater(file)
+ if len(sys.argv) == 2 and sys.argv[1] == '-c':
+ updater.cleanup()
+ else:
+ updater.update()