appconfig.py
39 lines
| 1.0 KiB
| text/x-python
|
PythonLexer
Brian Granger
|
r3789 | import sys | ||
from IPython.config.configurable import Configurable | ||||
Brian Granger
|
r3790 | from IPython.config.application import Application | ||
Brian Granger
|
r3789 | from IPython.utils.traitlets import ( | ||
Bool, Unicode, Int, Float, List | ||||
) | ||||
class Foo(Configurable): | ||||
i = Int(0, config=True, shortname='i', help="The integer i.") | ||||
j = Int(1, config=True, shortname='j', help="The integer j.") | ||||
name = Unicode(u'Brian', config=True, shortname='name', help="First name.") | ||||
class Bar(Configurable): | ||||
enabled = Bool(True, config=True, shortname="bar-enabled", help="Enable bar.") | ||||
Brian Granger
|
r3790 | class MyApp(Application): | ||
Brian Granger
|
r3789 | |||
Brian Granger
|
r3790 | app_name = Unicode(u'myapp') | ||
Brian Granger
|
r3789 | running = Bool(False, config=True, shortname="running", help="Is the app running?") | ||
classes = List([Bar, Foo]) | ||||
Brian Granger
|
r3790 | config_file = Unicode(u'', config=True, shortname="config-file", help="Load this config file") | ||
Brian Granger
|
r3789 | |||
def main(): | ||||
app = MyApp() | ||||
app.parse_command_line() | ||||
Brian Granger
|
r3790 | if app.config_file: | ||
app.load_config_file(app.config_file) | ||||
Brian Granger
|
r3789 | print "app.config:" | ||
print app.config | ||||
if __name__ == "__main__": | ||||
main() | ||||