##// END OF EJS Templates
disable string macros
MinRK -
Show More
@@ -405,11 +405,7 b' class KeyValueConfigLoader(CommandLineConfigLoader):'
405 if macro is None:
405 if macro is None:
406 raise ValueError("Unrecognized argument: %r"%item)
406 raise ValueError("Unrecognized argument: %r"%item)
407 macro = macros[m]
407 macro = macros[m]
408 if isinstance(macro, basestring):
408 if isinstance(macro, (dict, Configurable)):
409 # macro is simply a 'Class.trait=value' string
410 exec_str = 'self.config.' + macro
411 exec exec_str in locals(), globals()
412 elif isinstance(macro, (dict, Configurable)):
413 # update self.config with Config:
409 # update self.config with Config:
414 self.config.update(macros[m])
410 self.config.update(macros[m])
415 else:
411 else:
@@ -57,7 +57,7 b' class MyApp(Application):'
57 shortnames = dict(i='Foo.i',j='Foo.j',name='Foo.name',
57 shortnames = dict(i='Foo.i',j='Foo.j',name='Foo.name',
58 enabled='Bar.enabled', log_level='MyApp.log_level')
58 enabled='Bar.enabled', log_level='MyApp.log_level')
59
59
60 macros = dict(enable='Bar.enabled=True', disable='Bar.enabled=False')
60 macros = dict(enable={'Bar': {'enabled' : True}}, disable={'Bar': {'enabled' : False}})
61
61
62 macro_help = dict(
62 macro_help = dict(
63 enable="""Enable bar""",
63 enable="""Enable bar""",
@@ -44,29 +44,29 b' class Foo(Configurable):'
44
44
45 """
45 """
46
46
47 i = Int(0, config=True, shortname='i', help="The integer i.")
47 i = Int(0, config=True, help="The integer i.")
48 j = Int(1, config=True, shortname='j', help="The integer j.")
48 j = Int(1, config=True, help="The integer j.")
49 name = Unicode(u'Brian', config=True, shortname='name', help="First name.")
49 name = Unicode(u'Brian', config=True, help="First name.")
50
50
51
51
52 class Bar(Configurable):
52 class Bar(Configurable):
53
53
54 enabled = Bool(True, config=True, shortname="enabled", help="Enable bar.")
54 enabled = Bool(True, config=True, help="Enable bar.")
55
55
56
56
57 class MyApp(Application):
57 class MyApp(Application):
58
58
59 app_name = Unicode(u'myapp')
59 app_name = Unicode(u'myapp')
60 running = Bool(False, config=True, shortname="running",
60 running = Bool(False, config=True,
61 help="Is the app running?")
61 help="Is the app running?")
62 classes = List([Bar, Foo])
62 classes = List([Bar, Foo])
63 config_file = Unicode(u'', config=True, shortname="config_file",
63 config_file = Unicode(u'', config=True,
64 help="Load this config file")
64 help="Load this config file")
65
65
66 shortnames = dict(i='Foo.i',j='Foo.j',name='Foo.name',
66 shortnames = dict(i='Foo.i',j='Foo.j',name='Foo.name', running='MyApp.running',
67 enabled='Bar.enabled')
67 enabled='Bar.enabled')
68
68
69 macros = dict(enable='Bar.enabled=True', disable='Bar.enabled=False')
69 macros = dict(enable={'Bar': {'enabled' : True}}, disable={'Bar': {'enabled' : False}})
70 macro_help = dict(
70 macro_help = dict(
71 enable="""Set Bar.enabled to True""",
71 enable="""Set Bar.enabled to True""",
72 disable="""Set Bar.enabled to False"""
72 disable="""Set Bar.enabled to False"""
@@ -91,6 +91,7 b' def main():'
91 app.init_bar()
91 app.init_bar()
92 print "app.config:"
92 print "app.config:"
93 print app.config
93 print app.config
94 print app.bar.enabled
94
95
95
96
96 if __name__ == "__main__":
97 if __name__ == "__main__":
General Comments 0
You need to be logged in to leave comments. Login now