-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
43 lines (31 loc) · 920 Bytes
/
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
import os
import json
config = {
"secret": "",
"uuid": "",
"endpointURL": ""
}
def getDeviceSecret():
return config["secret"]
def getDeviceUUID():
return config["uuid"]
def getServerAddress():
addr = config["endpointURL"]
if addr.endswith("/"):
addr = addr[:-1]
return addr
def is_file_empty(file_path):
""" Check if file is empty by confirming if its size is 0 bytes"""
# Check if file exist and it is empty
return os.path.exists(file_path) and os.stat(file_path).st_size == 0 and os.path.getsize(file_path) == 0
def load():
with open('../../config.json', 'r') as file:
configData = config
if not is_file_empty('config.json'):
configData = json.load(file)
file.close()
return configData
def save(config):
with open('../../config.json', 'w') as file:
json.dump(config, file)
file.close()