|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
3 | | -from argparse import ArgumentParser |
4 | | -from collections import OrderedDict |
5 | | -import errno |
| 3 | +from argparse import ArgumentParser, FileType |
6 | 4 | import json |
7 | 5 | import os |
8 | 6 | import sys |
9 | 7 |
|
10 | 8 | aparser = ArgumentParser(description='Write icon grid json file') |
11 | 9 | aparser.add_argument('-o', '--output', help='output file') |
12 | | -aparser.add_argument('input', help='input template file') |
13 | | -aparser.add_argument('blacklist', help='blacklist file') |
14 | | -aparser.add_argument('cpu', help='CPU for blacklisting') |
| 10 | +aparser.add_argument('input', help='input template file', type=FileType("r")) |
15 | 11 | args = aparser.parse_args() |
16 | 12 |
|
17 | | -# Load with template and blacklist. Use OrderedDict for the grid to |
18 | | -# maintain sorting of the keys. |
19 | | -with open(args.input, 'r') as infile: |
20 | | - grid = json.load(infile, object_pairs_hook=OrderedDict) |
21 | | -with open(args.blacklist, 'r') as blfile: |
22 | | - blacklist = json.load(blfile) |
| 13 | +# Load template |
| 14 | +grid = json.load(args.input) |
23 | 15 |
|
24 | 16 | # Open the a temporary version of the output file if specified, ensuring |
25 | 17 | # that leading directories are created first. |
|
28 | 20 | else: |
29 | 21 | outdir = os.path.dirname(args.output) |
30 | 22 | if len(outdir) > 0: |
31 | | - try: |
32 | | - os.makedirs(outdir) |
33 | | - except OSError as err: |
34 | | - if err.errno != errno.EEXIST: |
35 | | - raise |
| 23 | + os.makedirs(outdir, exist_ok=True) |
36 | 24 | outfile = open(args.output + '.tmp', 'w') |
37 | 25 |
|
38 | | -# Strip out blacklisted apps |
39 | | -cpu_blacklist = blacklist.get(args.cpu, []) |
40 | | -for app in cpu_blacklist: |
41 | | - if app in grid: |
42 | | - del grid[app] |
43 | | - for sect, apps in grid.items(): |
44 | | - if app in apps: |
45 | | - grid[sect].remove(app) |
46 | | - |
47 | 26 | # Check that all directories are in the top-level "desktop" pseudo-directory |
48 | 27 | desktop = grid["desktop"] |
49 | 28 | for directory in grid: |
|
0 commit comments