-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathini.py
40 lines (30 loc) · 1.14 KB
/
ini.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
import configparser
import settings
import utils
class Ini:
def __init__(self, sec='tables'):
self.ini = self.__class__.read_ini(sec)
def get_ini(self):
return self.ini
def get_fields(self, section):
return dict(self.ini.items(section))
def get_visible_fields(self, section):
return {key: val for key, val in self.get_fields(section).items()
if not key.startswith("_")}
def get_value(self, section, key):
return self.ini.get(section, key)
def get_values(self, section, key):
return utils.Utils.comma_split(self.ini.get(section, key))
def is_multiline(self, section):
return "_line_types" in self.get_fields(section)
def get_files(self):
return self.get_values('GENERAL', 'files')
@classmethod
def read_ini(cls, sec='tables'):
utils.Utils.print_debug(
"Reading configuration using file {file}.".format(
file=settings.settings[sec]))
ini = configparser.ConfigParser()
ini._interpolation = configparser.ExtendedInterpolation()
ini.read(settings.settings[sec])
return ini