forked from Moussa/TF2IdleGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.py
62 lines (46 loc) · 1.47 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import ConfigParser, os, sys
class _settings(ConfigParser.SafeConfigParser):
""" Easy option getting/setting """
def __init__(self, filename):
self._parser = ConfigParser.SafeConfigParser()
self.filename = filename
try:
self._parser.read(self.filename)
except:
pass
def has_section(self, sectionname):
return self._parser.has_section(sectionname)
def set_section(self, sectionname):
self.sectionname = sectionname
def add_section(self):
self._parser.add_section(self.sectionname)
def remove_section(self, section=None):
if section:
self._parser.remove_section(section)
else:
self._parser.remove_section(self.sectionname)
def get_sections(self):
return self._parser.sections()
def get_option(self, opt):
return self._parser.get(self.sectionname, opt)
def set_option(self, opt, value = None):
return self._parser.set(self.sectionname, opt, value)
def has_option(self, opt):
return self._parser.has_option(self.sectionname, opt)
def flush_configuration(self):
self._parser.write(open(self.filename, "w"))
def __del__(self):
self.flush_configuration()
def __setitem__(self, key, value):
return self.set_option(key, value)
def __getitem__(self, key):
try:
return self.get_option(key)
except ConfigParser.NoOptionError as E:
raise KeyError(E)
def __contains__(self, item):
return self._parser.has_option(self.sectionname, item)
settings = None
def init(filename):
global settings
settings = _settings(filename)