Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions gen_mirror_json.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
#!/usr/bin/env python
#!/usr/bin/env python3
from __future__ import print_function
import hashlib
import json
import os
import re
import sys
import zipfile

from datetime import datetime
from time import mktime

if len(sys.argv) < 2:
print("usage python {} /path/to/mirror/base/url".format(sys.argv[0]))
print("usage python3 {} /path/to/mirror/base/url".format(sys.argv[0]))
sys.exit()

FILE_BASE = sys.argv[1]
builds = {}

for f in [os.path.join(dp, f) for dp, dn, fn in os.walk(FILE_BASE) for f in fn]:
data = open(f)
data = open(f, 'rb')
filename = f.split('/')[-1]
# lineage-14.1-20171129-nightly-hiaeul-signed.zip
_, version, builddate, buildtype, device = os.path.splitext(filename)[0].split('-')
print('hashing sha256 for {}'.format(filename), file=sys.stderr)
sha256 = hashlib.sha256()
for buf in iter(lambda : data.read(128 * 1024), b''):
for buf in iter(lambda: data.read(128 * 1024), b''):
sha256.update(buf)

try:
with zipfile.ZipFile('{}{}'.format(BASE_PATH, filepath), 'r') as update_zip:
build_prop = update_zip.read('system/build.prop').decode('utf-8')
timestamp = int(re.findall('ro.build.date.utc=([0-9]+)', build_prop)[0])
except:
with zipfile.ZipFile(f'{FILE_BASE}/{filename}', 'r') as update_zip:
build_prop = update_zip.read('META-INF/com/android/metadata').decode('utf-8')
timestamp = (re.findall('post-timestamp=([0-9]+)', build_prop)[0])
except Exception as e:
print(e)
timestamp = int(mktime(datetime.strptime(builddate, '%Y%m%d').timetuple()))

builds.setdefault(device, []).append({
Expand Down