forked from Yubico/yubioath-flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_qrc.py
executable file
·45 lines (33 loc) · 1009 Bytes
/
build_qrc.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
#!/usr/bin/env python
import os
import sys
import json
def read_conf(fname):
if not os.path.isfile(fname):
return {}
with open(fname, 'r') as conf:
return json.load(conf)
def build_qrc(resources):
yield '<RCC>'
yield '<qresource>'
for d in resources:
for root, dirs, files in os.walk(d):
dirs.sort()
files.sort()
for f in files:
yield '<file>{}</file>'.format(os.path.join(root, f))
yield '</qresource>'
yield '</RCC>'
def build_resources(resources, target):
with open(target, 'w') as f:
for line in build_qrc(resources):
f.write(line + os.linesep)
def build(source):
conf = read_conf(source)
target = os.path.basename(source)
if '.' in target:
target = target.rsplit('.', 1)[0]
target += '.qrc'
build_resources(conf.get('resources', []), target)
if __name__ == '__main__':
build(sys.argv[1] if len(sys.argv) >= 1 else 'resources.json')