-
Notifications
You must be signed in to change notification settings - Fork 4
/
configurer.py
55 lines (43 loc) · 1.32 KB
/
configurer.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
import configparser
import sys
import os
from pathlib import Path
class nx_config(object):
'''Constructor'''
def __init__(self):
self.config = configparser.ConfigParser(allow_no_value=True,interpolation=configparser.ExtendedInterpolation())
self.file = "./config/config.ini"
'''Simple Config Reader'''
def load_config(self,filename=None):
if filename:
self.file = filename
try:
self.config.read(self.file)
except FileNotFoundError:
print ("The file specified does not exists")
except configparser.ParsingError:
print ("Error encountered while parsing, check configuration file syntax")
except:
print ("Unhandled exception, contact support")
def save_config(self):
with open(self.file, 'w') as configfile:
config.write(configfile)
def rebase(self):
for key, directory in self.config["GLOBAL_DIRS"].items():
if not directory is None and not directory=="":
p = Path(directory)
print(directory)
p.mkdir(parents = True, exist_ok=True)
return self
def get_config(self):
return self.config
def get_section(self,s):
return self.config[s]
def get_doc_template(self):
return self.get_section("FILES")["TEMPLATE"]
def get(self,s,v):
return self.config[s][v]
def get_mode(self):
return self.config["GLOBAL"]["MODE"]
def set(self,s,v, newvalue):
self.config[s][v] = newvalue