|
|
"""A simple example of how to use IPython.config.application.Application.
|
|
|
|
|
|
This should serve as a simple example that shows how the IPython config
|
|
|
system works. The main classes are:
|
|
|
|
|
|
* IPython.config.configurable.Configurable
|
|
|
* IPython.config.configurable.SingletonConfigurable
|
|
|
* IPython.config.loader.Config
|
|
|
* IPython.config.application.Application
|
|
|
"""
|
|
|
|
|
|
import sys
|
|
|
|
|
|
from IPython.config.configurable import Configurable
|
|
|
from IPython.config.application import Application
|
|
|
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="enabled", help="Enable bar.")
|
|
|
|
|
|
|
|
|
class MyApp(Application):
|
|
|
|
|
|
app_name = Unicode(u'myapp')
|
|
|
running = Bool(False, config=True, shortname="running",
|
|
|
help="Is the app running?")
|
|
|
classes = List([Bar, Foo])
|
|
|
config_file = Unicode(u'', config=True, shortname="config_file",
|
|
|
help="Load this config file")
|
|
|
|
|
|
def init_foo(self):
|
|
|
self.foo = Foo(config=self.config)
|
|
|
|
|
|
def init_bar(self):
|
|
|
self.bar = Bar(config=self.config)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
app = MyApp()
|
|
|
app.parse_command_line()
|
|
|
if app.config_file:
|
|
|
app.load_config_file(app.config_file)
|
|
|
app.init_foo()
|
|
|
app.init_bar()
|
|
|
print "app.config:"
|
|
|
print app.config
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
main()
|
|
|
|