Show More
@@ -61,6 +61,10 b' This line is evaluated in Python, so simple expressions are allowed, e.g.' | |||||
61 | #----------------------------------------------------------------------------- |
|
61 | #----------------------------------------------------------------------------- | |
62 |
|
62 | |||
63 |
|
63 | |||
|
64 | class ApplicationError(Exception): | |||
|
65 | pass | |||
|
66 | ||||
|
67 | ||||
64 | class Application(SingletonConfigurable): |
|
68 | class Application(SingletonConfigurable): | |
65 | """A singleton application with full configuration support.""" |
|
69 | """A singleton application with full configuration support.""" | |
66 |
|
70 | |||
@@ -112,6 +116,11 b' class Application(SingletonConfigurable):' | |||||
112 | assert isinstance(value[1], basestring), "Bad flag: %r:%s"%(key,value) |
|
116 | assert isinstance(value[1], basestring), "Bad flag: %r:%s"%(key,value) | |
113 | self.init_logging() |
|
117 | self.init_logging() | |
114 |
|
118 | |||
|
119 | def _config_changed(self, name, old, new): | |||
|
120 | SingletonConfigurable._config_changed(self, name, old, new) | |||
|
121 | self.log.debug('Config changed:') | |||
|
122 | self.log.debug(repr(new)) | |||
|
123 | ||||
115 | def init_logging(self): |
|
124 | def init_logging(self): | |
116 | """Start logging for this application. |
|
125 | """Start logging for this application. | |
117 |
|
126 | |||
@@ -210,11 +219,11 b' class Application(SingletonConfigurable):' | |||||
210 | if '-h' in argv or '--help' in argv: |
|
219 | if '-h' in argv or '--help' in argv: | |
211 | self.print_description() |
|
220 | self.print_description() | |
212 | self.print_help() |
|
221 | self.print_help() | |
213 |
s |
|
222 | self.exit(1) | |
214 |
|
223 | |||
215 | if '--version' in argv: |
|
224 | if '--version' in argv: | |
216 | self.print_version() |
|
225 | self.print_version() | |
217 |
s |
|
226 | self.exit(1) | |
218 |
|
227 | |||
219 | loader = KeyValueConfigLoader(argv=argv, aliases=self.aliases, |
|
228 | loader = KeyValueConfigLoader(argv=argv, aliases=self.aliases, | |
220 | flags=self.flags) |
|
229 | flags=self.flags) | |
@@ -223,8 +232,10 b' class Application(SingletonConfigurable):' | |||||
223 |
|
232 | |||
224 | def load_config_file(self, filename, path=None): |
|
233 | def load_config_file(self, filename, path=None): | |
225 | """Load a .py based config file by filename and path.""" |
|
234 | """Load a .py based config file by filename and path.""" | |
226 | # TODO: this raises IOError if filename does not exist. |
|
|||
227 | loader = PyFileConfigLoader(filename, path=path) |
|
235 | loader = PyFileConfigLoader(filename, path=path) | |
228 | config = loader.load_config() |
|
236 | config = loader.load_config() | |
229 | self.update_config(config) |
|
237 | self.update_config(config) | |
230 |
|
238 | |||
|
239 | def exit(self, exit_status=0): | |||
|
240 | self.log.debug("Exiting application: %s" % self.name) | |||
|
241 | sys.exit(exit_status) |
General Comments 0
You need to be logged in to leave comments.
Login now