2020-06-07 20:05:26 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
2020-08-09 05:14:55 +02:00
|
|
|
import os.path
|
2020-06-07 20:05:26 +02:00
|
|
|
import zipfile
|
2020-08-09 05:14:55 +02:00
|
|
|
from shutil import copyfile
|
2020-08-09 05:51:19 +02:00
|
|
|
import hashlib
|
|
|
|
|
|
|
|
def md5(fname):
|
|
|
|
hash_md5 = hashlib.md5()
|
|
|
|
with open(fname, "rb") as f:
|
|
|
|
for chunk in iter(lambda: f.read(4096), b""):
|
|
|
|
hash_md5.update(chunk)
|
|
|
|
return hash_md5.hexdigest()
|
2020-06-07 20:05:26 +02:00
|
|
|
|
2020-08-18 11:19:09 +02:00
|
|
|
if len(sys.argv) < 4:
|
|
|
|
print('usage: mkzip <lstfile> <dstpath> <legacy>')
|
2020-06-07 20:05:26 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
lst = []
|
|
|
|
with open(sys.argv[1], 'r') as f:
|
|
|
|
for line in f:
|
|
|
|
line = line.strip()
|
|
|
|
if line == '' or line[0] == '#':
|
|
|
|
continue
|
|
|
|
tok = line.split()
|
|
|
|
lst.append((tok[0], tok[1]))
|
2020-08-18 11:19:09 +02:00
|
|
|
if not sys.argv[3] or not sys.argv[3] == "1":
|
|
|
|
for (fname, aname) in lst:
|
|
|
|
path = os.path.join(sys.argv[2], aname)
|
|
|
|
old_md5 = md5(fname)
|
|
|
|
if not os.path.exists(path) or os.path.exists(path) and old_md5 != md5(path):
|
|
|
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
|
|
copyfile(fname, path)
|
|
|
|
print("Copying: " + path)
|
|
|
|
else:
|
|
|
|
print("Skipping: " + path + " - MD5: "+md5(fname))
|
|
|
|
else:
|
2020-08-18 13:39:40 +02:00
|
|
|
zipPath = os.path.join(sys.argv[2], "awesome-legacy.zip")
|
2020-08-18 11:19:09 +02:00
|
|
|
print("Using Legacy System")
|
2020-08-18 13:39:40 +02:00
|
|
|
with zipfile.ZipFile(zipPath, 'w', allowZip64=False) as zipf:
|
|
|
|
for (fname, aname) in lst:
|
|
|
|
zipf.write(fname, arcname=aname)
|
|
|
|
print("Legacy - Copying: " + aname)
|