summaryrefslogtreecommitdiff
path: root/src/utils/add-config-sync-exclude-paths.py
blob: 54a209490d3248626a3c9eac60287b1a27e1f3d9 (plain)
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
#!/usr/bin/env python3

import sys
import json
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('--file', default='data/config-sync-exclude.json')
parser.add_argument('--paths', nargs='+')

args = parser.parse_args()
paths = args.paths
file = args.file

try:
    with open(file) as f:
        exclude_str = json.load(f)
except FileNotFoundError:
    print(f'Adding new file: {file}')
    exclude_str = []
except json.JSONDecodeError as e:
    sys.exit(e)

for path in (paths or []):
    exclude_str.append(path.split())

with open(file, 'w') as f:
    json.dump(exclude_str, f, indent=1)
    f.write('\n')