This repository has been archived by the owner on Mar 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
config.py
61 lines (47 loc) · 1.43 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
import ConfigParser
import watchdog
from watchdog.observers import Observer
global options
class Options(watchdog.events.FileSystemEventHandler):
CONFIG_FILE = 'config.ini'
REQUIRED_SECTIONS = (
'credentials',
'general',
'building',
'attack',
'fleet',
'sms',
'farming',
'expedition'
)
def __init__(self, *args, **kwargs):
self._config = ConfigParser.RawConfigParser()
self.reload_config()
self._config_valid = False
self.observer = Observer()
self.observer.schedule(self, path='.', recursive=False)
self.observer.start()
def __del__(self):
self.observer.stop()
self.observer.join()
def on_any_event(self, event):
if self.CONFIG_FILE in event.src_path:
self.reload_config()
def reload_config(self):
print 'config reloaded'
self._config.read(self.CONFIG_FILE)
self.check_config()
def check_config(self):
self._config_valid = False
try:
for section in self.REQUIRED_SECTIONS:
self._config.items(section)
self._config_valid = True
except ConfigParser.NoSectionError:
self._config_valid = False
def __getitem__(self, section):
return dict(self._config.items(section))
@property
def valid(self):
return self._is_config_valid
options = Options()