equal
deleted
inserted
replaced
39 self.name = name |
39 self.name = name |
40 self.options={ |
40 self.options={ |
41 "port":Option(partial(vInteger,minv=0),long="Port under that twisted is running",must=True), |
41 "port":Option(partial(vInteger,minv=0),long="Port under that twisted is running",must=True), |
42 "dburl":Option(lambda x,y:x,long="Connection URL to database",must=True), |
42 "dburl":Option(lambda x,y:x,long="Connection URL to database",must=True), |
43 } |
43 } |
44 self.read=False |
44 self._init=True |
45 |
45 |
46 |
46 |
47 def _read(self, cfg, write=False): |
47 def _read(self, cfg, write=False): |
48 c = dict(cfg) |
48 c = dict(cfg) |
49 for o in self.options: |
49 for o in self.options: |
50 option = self.options[o] |
50 option = self.options[o] |
51 try: |
51 try: |
52 value = option.validate(c[o],o) |
52 value = option.validate(c[o],o) |
53 if write: |
53 if write: |
54 self.read = True |
54 self.init = False |
55 setattr(self,o,value) |
55 setattr(self,o,value) |
56 except KeyError: |
56 except KeyError: |
57 if option.must: |
57 if option.must: |
58 raise NeededOption(self.name, o) |
58 raise NeededOption(self.name, o) |
59 elif write and option.default is not None: |
59 elif write and option.default is not None: |
73 return True |
73 return True |
74 |
74 |
75 def readConfig(): |
75 def readConfig(): |
76 configParser.read(confFiles) |
76 configParser.read(confFiles) |
77 configParser.reload() |
77 configParser.reload() |
78 if not main.read: |
78 if main._init: |
79 main.load(configParser.items("main")) |
79 main.load(configParser.items("main")) |
80 else: |
80 else: |
81 m = Config("main").load(configParser.items("main")) |
81 m = Config("main") |
|
82 m.load(configParser.items("main")) |
82 if not main.same(m): |
83 if not main.same(m): |
83 raise Exception("Main options can't be reloaded, you have to restart.") |
84 raise Exception("Main options can't be reloaded, please restart your Application.") |
84 |
85 |
85 def registerSignal(): |
86 def registerSignal(): |
86 '''register readConfig to SIGUSR2''' |
87 '''register readConfig to SIGUSR2''' |
87 def rC(signal, frame): |
88 def rC(signal, frame): |
88 readConfig() |
89 readConfig() |