41 self.options={ |
41 self.options={ |
42 "port":Option(partial(vInteger,minv=0),long="Port under that twisted is running",must=True), |
42 "port":Option(partial(vInteger,minv=0),long="Port under that twisted is running",must=True), |
43 "dburl":Option(lambda x,y:x,long="Connection URL to database",must=True), |
43 "dburl":Option(lambda x,y:x,long="Connection URL to database",must=True), |
44 } |
44 } |
45 self.order = ["dburl","port"] |
45 self.order = ["dburl","port"] |
46 self._init=True |
46 self._init = True |
47 |
47 |
48 |
48 |
49 def _read(self, cfg, write=False): |
49 def _read(self, cfg, write=False): |
50 c = dict(cfg) |
50 c = dict(cfg) |
|
51 |
51 for o in self.options: |
52 for o in self.options: |
52 option = self.options[o] |
53 option = self.options[o] |
53 try: |
54 try: |
54 value = option.validate(c[o],o) |
55 value = option.validate(c[o],o) |
55 if write: |
56 if write: |
56 self.init = False |
57 self._init = False |
57 setattr(self,o,value) |
58 setattr(self,o,value) |
58 except KeyError: |
59 except KeyError: |
59 if option.must: |
60 if option.must: |
60 raise NeededOption(self.name, o) |
61 raise NeededOption(self.name, o) |
61 elif write and option.default is not None: |
62 elif write and option.default is not None: |
91 |
92 |
92 return ["[%s]"%self.name,]+ret |
93 return ["[%s]"%self.name,]+ret |
93 |
94 |
94 def readConfig(): |
95 def readConfig(): |
95 configParser.read(confFiles) |
96 configParser.read(confFiles) |
96 configParser.reload() |
97 configParser.reload_() |
97 if main._init: |
98 if main._init: |
98 main.load(configParser.items("main")) |
99 main.load(configParser.items("main")) |
99 else: |
100 else: |
100 m = Config("main") |
101 m = Config("main") |
101 m.load(configParser.items("main")) |
102 m.load(configParser.items("main")) |
102 if not main.same(m): |
103 if not main.same(m): |
103 raise Exception("Main options can't be reloaded, please restart your Application.") |
104 raise Exception("Main options can't be reloaded, please restart your Application.") |
|
105 |
|
106 def init(): |
|
107 configParser.read(confFiles) |
|
108 main.load(configParser.items("main")) |
104 |
109 |
105 def registerSignal(): |
110 def registerSignal(): |
106 '''register readConfig to SIGUSR2''' |
111 '''register readConfig to SIGUSR2''' |
107 def rC(signal, frame): |
112 def rC(signal, frame): |
108 readConfig() |
113 readConfig() |