-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrcst_config.py
executable file
·111 lines (85 loc) · 2.6 KB
/
rcst_config.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/python3
# Imports
import os, json
import argparse
info = 'INF: '
sets = 'SET: '
error = 'ERR: '
parser = argparse.ArgumentParser()
parser.add_argument('new_num_dst')
args = parser.parse_args()
#num_dst = int(args.new_num_dst)
num_dst = 0
if (args.new_num_dst == 'add'):
num_dst = 1
print(f'{info}Adding 1 new destination...')
elif (args.new_num_dst != 'edit'):
quit(1)
def fix_type(cap: str, typ: str):
if (typ == 'str'):
return cap
elif (typ == 'bool'):
return (cap in ['True', 'true', 'TRUE', 't', 'T', 'y', 'Y'])
elif (typ == 'int'):
return int(cap)
else:
print(f'{error}Invalid type specified.')
exit(1)
def prop_in(conf, prop, typ):
val = ''
cap = ''
try:
val = conf[prop]
except:
print(f'{info}[{prop}] has not been set.')
default = defaults[prop]
while (True):
if (val == ''):
print(f'{sets}[{prop}] (blank for default: {str(default)})')
else:
print(f'{sets}[{prop}] (blank for loaded: {val})')
cap = input()
if (cap == ''):
if (val == ''):
if (default is None):
print(f'{error}{prop} must be set.')
else:
conf.update({prop: default})
break
else:
break
else:
conf.update({prop: fix_type(cap, typ)})
break
# Get Working Directory
working_dir: str = os.path.dirname(os.path.realpath(__file__))
# Load defaults
defaults = {}
with open(f'{working_dir}/config_defaults.json') as f:
defaults = json.load(f)
# Load config
config = {}
with open(f'{working_dir}/config.json') as f:
config = json.load(f)
try:
temp = config['destinations']
except:
config.update({'destinations': []})
for i in range(num_dst):
config['destinations'].append({})
fin_len = len(config['destinations'])
for i in range(fin_len):
print(f'{info}Modiying object: {i + 1} / {fin_len}')
# Set properties
prop_in(config['destinations'][i], 'name', 'str')
prop_in(config['destinations'][i], 'icon', 'str')
prop_in(config['destinations'][i], 'dst_route', 'str')
prop_in(config['destinations'][i], 'dst_dir', 'str')
prop_in(config['destinations'][i], 'direct_link', 'bool')
prop_in(config['destinations'][i], 'notif_decay_time', 'int')
for i in range(fin_len):
config['destinations'][i].update({'id': i})
config.update({'size': fin_len})
# Save config
with open(f'{working_dir}/config.json', 'w', encoding='utf-8') as f:
json.dump(config, f, ensure_ascii=False, indent=4)