-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate-config.py
More file actions
executable file
·39 lines (29 loc) · 1011 Bytes
/
update-config.py
File metadata and controls
executable file
·39 lines (29 loc) · 1011 Bytes
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
#!/usr/bin/env python
# vim:se fileencoding=utf8 :
# (c) 2015-2019 Michał Górny
# 2-clause BSD license
import argparse
import json
import subprocess
import sys
def main(argv):
argp = argparse.ArgumentParser(prog=argv[0])
argp.add_argument('--delete-old', action='store_true',
help='Delete old options (kept by default)')
argp.add_argument('path',
help='Path to .conf file')
args = argp.parse_args(argv[1:])
s = subprocess.Popen(['pkgcheck', 'show', '--keywords'],
stdout=subprocess.PIPE)
sout, serr = s.communicate()
all_classes = sout.decode().split()
with open(args.path, 'r') as f:
conf = json.load(f)
if not args.delete_old:
all_classes.extend(conf.keys())
new_conf = dict((k, conf.get(str(k), '')) for k in all_classes)
with open(args.path, 'w') as f:
json.dump(new_conf, f, sort_keys=True, indent=4)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))