-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
executable file
·44 lines (42 loc) · 1.11 KB
/
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
#!/usr/bin/python3 -u
"""
Description:
Author:
"""
import os
import json
import re
def load(path):
""" Load config from file """
config_path = os.path.expanduser(path)
if not os.path.exists(config_path):
os.makedirs(config_path)
default_config = """// vim:ft=jsonc
{
"modules-left": ["workspaces", "privacy"],
"modules-center": ["updates"],
"modules-right": [
"weather", "volume", "network", "clock", "power"],
"modules": {
"weather": {
"zip_code": "94102"
},
"updates": {
"interval": 300
},
"network": {
"always_show": true
}
}
}"""
with open(f"{config_path}/config.json", 'w', encoding='utf-8') as file:
file.write(default_config)
return default_config
with open(
os.path.expanduser(f'{config_path}/config.json'),
'r', encoding='utf=8'
) as file:
output = file.read()
output = re.sub(re.compile(r"/\*.*?\*/", re.DOTALL), "", output)
output = re.sub(re.compile(r"//.*?\n"), "", output)
return json.loads(output)