Show More
@@ -24,7 +24,7 b' import sys' | |||
|
24 | 24 | |
|
25 | 25 | from IPython.config.configurable import SingletonConfigurable |
|
26 | 26 | from IPython.utils.traitlets import ( |
|
27 | Unicode, List, Int | |
|
27 | Unicode, List, Int, Enum | |
|
28 | 28 | ) |
|
29 | 29 | from IPython.config.loader import ( |
|
30 | 30 | KeyValueConfigLoader, PyFileConfigLoader |
@@ -52,7 +52,10 b' class Application(SingletonConfigurable):' | |||
|
52 | 52 | # The version string of this application. |
|
53 | 53 | version = Unicode(u'0.0') |
|
54 | 54 | |
|
55 | log_level = Int(logging.WARN, config=True, shortname="log_level") | |
|
55 | # The log level for the application | |
|
56 | log_level = Enum((0,10,20,30,40,50), default_value=logging.WARN, | |
|
57 | config=True, shortname="log_level", | |
|
58 | help="Set the log level (0,10,20,30,40,50).") | |
|
56 | 59 | |
|
57 | 60 | def __init__(self, **kwargs): |
|
58 | 61 | SingletonConfigurable.__init__(self, **kwargs) |
@@ -105,8 +108,7 b' class Application(SingletonConfigurable):' | |||
|
105 | 108 | |
|
106 | 109 | def parse_command_line(self, argv=None): |
|
107 | 110 | """Parse the command line arguments.""" |
|
108 | if argv is None: | |
|
109 | argv = sys.argv[1:] | |
|
111 | argv = sys.argv[1:] if argv is None else argv | |
|
110 | 112 | |
|
111 | 113 | if '-h' in argv or '--h' in argv: |
|
112 | 114 | self.print_description() |
@@ -1,3 +1,14 b'' | |||
|
1 | """A simple example of how to use IPython.config.application.Application. | |
|
2 | ||
|
3 | This should serve as a simple example that shows how the IPython config | |
|
4 | system works. The main classes are: | |
|
5 | ||
|
6 | * IPython.config.configurable.Configurable | |
|
7 | * IPython.config.configurable.SingletonConfigurable | |
|
8 | * IPython.config.loader.Config | |
|
9 | * IPython.config.application.Application | |
|
10 | """ | |
|
11 | ||
|
1 | 12 | import sys |
|
2 | 13 | |
|
3 | 14 | from IPython.config.configurable import Configurable |
@@ -15,15 +26,24 b' class Foo(Configurable):' | |||
|
15 | 26 | |
|
16 | 27 | class Bar(Configurable): |
|
17 | 28 | |
|
18 |
enabled = Bool(True, config=True, shortname=" |
|
|
29 | enabled = Bool(True, config=True, shortname="enabled", help="Enable bar.") | |
|
19 | 30 | |
|
20 | 31 | |
|
21 | 32 | class MyApp(Application): |
|
22 | 33 | |
|
23 | 34 | app_name = Unicode(u'myapp') |
|
24 |
running = Bool(False, config=True, shortname="running", |
|
|
35 | running = Bool(False, config=True, shortname="running", | |
|
36 | help="Is the app running?") | |
|
25 | 37 | classes = List([Bar, Foo]) |
|
26 |
config_file = Unicode(u'', config=True, shortname="config |
|
|
38 | config_file = Unicode(u'', config=True, shortname="config_file", | |
|
39 | help="Load this config file") | |
|
40 | ||
|
41 | def init_foo(self): | |
|
42 | self.foo = Foo(config=self.config) | |
|
43 | ||
|
44 | def init_bar(self): | |
|
45 | self.bar = Bar(config=self.config) | |
|
46 | ||
|
27 | 47 | |
|
28 | 48 | |
|
29 | 49 | def main(): |
@@ -31,6 +51,8 b' def main():' | |||
|
31 | 51 | app.parse_command_line() |
|
32 | 52 | if app.config_file: |
|
33 | 53 | app.load_config_file(app.config_file) |
|
54 | app.init_foo() | |
|
55 | app.init_bar() | |
|
34 | 56 | print "app.config:" |
|
35 | 57 | print app.config |
|
36 | 58 |
General Comments 0
You need to be logged in to leave comments.
Login now