forked from aegis-icons/aegis-icons
-
Notifications
You must be signed in to change notification settings - Fork 4
/
make-pack.py
67 lines (56 loc) · 2.46 KB
/
make-pack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
import argparse
import io
import json
import os
import pathlib
import zipfile
def _do_gen_def(args):
pack = {
"uuid": "18400066-2748-11ee-be56-0242ac120002",
"name": "delta-aegis-icons",
"version": 0,
"icons": []
}
# Change the "icons" from line 17 to set a different dir
root = os.path.join(args.root, "icons")
for root, _, files in os.walk(root):
for f in files:
filename = os.path.join(root, f)
if os.path.isfile(filename):
pack["icons"].append({
"filename": pathlib.Path(filename).as_posix(),
"category": None,
"issuer": [os.path.splitext(os.path.basename(filename))[0]]
})
filename = os.path.join(args.root, "pack.json")
pack["icons"].sort(key=lambda icon: icon["filename"])
with io.open(filename, "w") as f:
f.write(json.dumps(pack, indent=4))
print(f"generated {filename}")
def _do_gen(args):
with io.open(os.path.join(args.root, "pack.json"), "r") as f:
pack = json.load(f)
count = 0
pack["version"] = args.version
with zipfile.ZipFile(args.output, "w", zipfile.ZIP_DEFLATED) as zipf:
for icon in pack["icons"]:
zipf.write(icon["filename"])
count += 1
zipf.writestr("pack.json", json.dumps(pack, indent=4).encode("utf-8"))
print(f"generated pack with {count} icons")
def main():
parser = argparse.ArgumentParser(description="Script used to generate an Aegis Authenticator icon pack", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--root", dest="root", default="", help="the root directory of the icon pack repository")
subparsers = parser.add_subparsers()
gen_parser = subparsers.add_parser("gen", help="Generate the icon pack .ZIP file", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
gen_parser.add_argument("--output", dest="output", required=True, help="icon pack output filename")
gen_parser.add_argument("--version", dest="version", required=True, type=int, help="the version of the icon pack")
gen_parser.set_defaults(func=_do_gen)
update_parser = subparsers.add_parser("gen-def", help="Generate the pack.json file", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
update_parser.set_defaults(func=_do_gen_def)
args = parser.parse_args()
if args.func:
args.func(args)
if __name__ == "__main__":
main()