-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
57 lines (44 loc) · 1.58 KB
/
Copy pathconfig.py
File metadata and controls
57 lines (44 loc) · 1.58 KB
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
import logging
import os
import configparser
import json
config = configparser.ConfigParser()
def getConfigPath():
script_path = os.path.abspath(__file__)
return os.path.dirname(script_path) + '/config'
read = config.read(getConfigPath() + '/config.ini')
if not read:
config['Settings'] = {
'anisette_url': os.getenv('ANISETTE_URL', 'http://anisette:6969'),
'appleid_email': os.getenv('APPLEID_EMAIL', ''),
'appleid_pwd': os.getenv('APPLEID_PWD', ''),
'loglevel': os.getenv('LOG_LEVEL', 'INFO')
}
config['Auth'] = {}
try:
os.mkdir(getConfigPath())
except:
pass
finally:
with open(getConfigPath() + '/config.ini', 'w') as configfile:
config.write(configfile)
def getAnisetteServer():
return config.get('Settings', 'anisette_url', fallback='http://anisette:6969')
def getPort():
return 6176
def getUser():
return config.get('Settings', 'appleid_email', fallback='')
def getPass():
return config.get('Settings', 'appleid_pwd', fallback='')
def getLogLevel():
logLevel = config.get('Settings', 'loglevel', fallback='INFO')
return logging.getLevelName(logLevel)
def getAuth():
return dict(config.items('Auth'))
def setAuth(auth: dict):
config['Auth'] = auth
with open(getConfigPath() + '/config.ini', 'w') as configfile:
config.write(configfile)
logging.basicConfig(level=getLogLevel(),
format='%(asctime)s - %(levelname)s - %(message)s')
logging.debug('Config => ' + str({section: dict(config[section]) for section in config.sections()}))