-
Notifications
You must be signed in to change notification settings - Fork 8
/
main_utilities.py
46 lines (37 loc) · 1.37 KB
/
main_utilities.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
# pylint: disable=duplicate-code
# util functions for the classes in main.py
import os
import sys
import json
if getattr(sys, 'frozen', False):
ABS_PATH = os.path.dirname(sys.executable)
else:
PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
ABS_PATH = '{0}/unplatform_v2'.format(os.path.abspath(os.path.join(PROJECT_PATH, os.pardir)))
CONFIG_DIR = '{0}/webapps/unplatform/configuration'.format(ABS_PATH)
CONFIG_FILE = '{0}/config.json'.format(CONFIG_DIR)
USER_DATA_DIR = '{0}/webapps/unplatform/user_data'.format(ABS_PATH)
def get_configuration_file():
if not os.path.isfile(CONFIG_FILE):
return {}
else:
with open(CONFIG_FILE, 'rb') as config_file:
return json.load(config_file)
def set_configuration_file(data):
if not os.path.isdir(CONFIG_DIR):
os.makedirs(CONFIG_DIR)
with open(CONFIG_FILE, 'wb') as config_file:
if not isinstance(data, dict):
data = json.loads(data)
json.dump(data, config_file)
return data
def set_user_data_file(data):
if not os.path.isdir(USER_DATA_DIR):
os.makedirs(USER_DATA_DIR)
if not isinstance(data, dict):
data = json.loads(dict)
user_file = '{0}/{1}.json'.format(USER_DATA_DIR,
data['sessionId'])
with open(user_file, 'wb') as user_file:
json.dump(data, user_file)
return data