Show More
@@ -33,7 +33,7 b' from IPython.utils.traitlets import (' | |||
|
33 | 33 | from IPython.utils.text import indent |
|
34 | 34 | |
|
35 | 35 | #----------------------------------------------------------------------------- |
|
36 | # Descriptions for | |
|
36 | # Descriptions for the various sections | |
|
37 | 37 | #----------------------------------------------------------------------------- |
|
38 | 38 | |
|
39 | 39 | flag_description = """ |
@@ -91,7 +91,7 b' class Application(SingletonConfigurable):' | |||
|
91 | 91 | # The log level for the application |
|
92 | 92 | log_level = Enum((0,10,20,30,40,50), default_value=logging.WARN, |
|
93 | 93 | config=True, |
|
94 |
help="Set the log level |
|
|
94 | help="Set the log level.") | |
|
95 | 95 | |
|
96 | 96 | # the alias map for configurables |
|
97 | 97 | aliases = Dict(dict(log_level='Application.log_level')) |
@@ -143,11 +143,11 b' class Application(SingletonConfigurable):' | |||
|
143 | 143 | """print the alias part of the help""" |
|
144 | 144 | if not self.aliases: |
|
145 | 145 | return |
|
146 |
|
|
|
147 |
|
|
|
148 | print "-------" | |
|
149 |
|
|
|
150 | ||
|
146 | ||
|
147 | lines = ['Aliases'] | |
|
148 | lines.append('_'*len(lines[0])) | |
|
149 | lines.append(self.alias_description) | |
|
150 | lines.append('') | |
|
151 | 151 | |
|
152 | 152 | classdict = {} |
|
153 | 153 | for c in self.classes: |
@@ -158,31 +158,38 b' class Application(SingletonConfigurable):' | |||
|
158 | 158 | cls = classdict[classname] |
|
159 | 159 | |
|
160 | 160 | trait = cls.class_traits(config=True)[traitname] |
|
161 |
help = trait |
|
|
162 | print alias, "(%s)"%longname, ':', trait.__class__.__name__ | |
|
163 |
|
|
|
164 | print indent(help, flatten=True) | |
|
165 | ||
|
161 | help = cls.class_get_trait_help(trait) | |
|
162 | help = help.replace(longname, "%s (%s)"%(alias, longname), 1) | |
|
163 | lines.append(help) | |
|
164 | # header = "%s (%s) : %s"%(alias, longname, trait.__class__.__name__) | |
|
165 | # lines.append(header) | |
|
166 | # help = cls.class_get_trait_help(trait) | |
|
167 | # if help: | |
|
168 | # lines.append(indent(help, flatten=True)) | |
|
169 | lines.append('') | |
|
170 | print '\n'.join(lines) | |
|
166 | 171 | |
|
167 | 172 | def print_flag_help(self): |
|
168 | 173 | """print the flag part of the help""" |
|
169 | 174 | if not self.flags: |
|
170 | 175 | return |
|
171 | 176 | |
|
172 |
|
|
|
173 | print "-----" | |
|
174 |
|
|
|
175 | ||
|
177 | lines = ['Flags'] | |
|
178 | lines.append('_'*len(lines[0])) | |
|
179 | lines.append(self.flag_description) | |
|
180 | lines.append('') | |
|
176 | 181 | |
|
177 | 182 | for m, (cfg,help) in self.flags.iteritems(): |
|
178 |
|
|
|
179 |
|
|
|
180 | ||
|
183 | lines.append('--'+m) | |
|
184 | lines.append(indent(help, flatten=True)) | |
|
185 | lines.append('') | |
|
186 | print '\n'.join(lines) | |
|
181 | 187 | |
|
182 | 188 | def print_help(self): |
|
183 | 189 | """Print the help for each Configurable class in self.classes.""" |
|
184 | 190 | self.print_flag_help() |
|
185 | 191 | self.print_alias_help() |
|
192 | ||
|
186 | 193 | if self.classes: |
|
187 | 194 | print "Class parameters" |
|
188 | 195 | print "----------------" |
@@ -239,3 +246,41 b' class Application(SingletonConfigurable):' | |||
|
239 | 246 | def exit(self, exit_status=0): |
|
240 | 247 | self.log.debug("Exiting application: %s" % self.name) |
|
241 | 248 | sys.exit(exit_status) |
|
249 | ||
|
250 | #----------------------------------------------------------------------------- | |
|
251 | # utility functions, for convenience | |
|
252 | #----------------------------------------------------------------------------- | |
|
253 | ||
|
254 | def boolean_flag(name, configurable, set_help='', unset_help=''): | |
|
255 | """helper for building basic --trait, --no-trait flags | |
|
256 | ||
|
257 | Parameters | |
|
258 | ---------- | |
|
259 | ||
|
260 | name : str | |
|
261 | The name of the flag. | |
|
262 | configurable : str | |
|
263 | The 'Class.trait' string of the trait to be set/unset with the flag | |
|
264 | set_help : unicode | |
|
265 | help string for --name flag | |
|
266 | unset_help : unicode | |
|
267 | help string for --no-name flag | |
|
268 | ||
|
269 | Returns | |
|
270 | ------- | |
|
271 | ||
|
272 | cfg : dict | |
|
273 | A dict with two keys: 'name', and 'no-name', for setting and unsetting | |
|
274 | the trait, respectively. | |
|
275 | """ | |
|
276 | # default helpstrings | |
|
277 | set_help = set_help or "set %s=True"%configurable | |
|
278 | unset_help = unset_help or "set %s=False"%configurable | |
|
279 | ||
|
280 | cls,trait = configurable.split('.') | |
|
281 | ||
|
282 | setter = Config() | |
|
283 | setter[cls][trait] = True | |
|
284 | unsetter = Config() | |
|
285 | unsetter[cls][trait] = False | |
|
286 | return {name : (setter, set_help), 'no-'+name : (unsetter, unset_help)} |
@@ -145,13 +145,31 b' class Configurable(HasTraits):' | |||
|
145 | 145 | final_help = [] |
|
146 | 146 | final_help.append(u'%s options' % cls.__name__) |
|
147 | 147 | final_help.append(len(final_help[0])*u'-') |
|
148 |
for k, |
|
|
149 |
help = v |
|
|
150 | header = "%s.%s : %s" % (cls.__name__, k, v.__class__.__name__) | |
|
151 | final_help.append(header) | |
|
152 | if help is not None: | |
|
153 | final_help.append(indent(help, flatten=True)) | |
|
148 | for k,v in cls.class_traits(config=True).iteritems(): | |
|
149 | help = cls.class_get_trait_help(v) | |
|
150 | final_help.append(help) | |
|
154 | 151 | return '\n'.join(final_help) |
|
152 | ||
|
153 | @classmethod | |
|
154 | def class_get_trait_help(cls, trait): | |
|
155 | """Get the help string for a single """ | |
|
156 | lines = [] | |
|
157 | header = "%s.%s : %s" % (cls.__name__, trait.name, trait.__class__.__name__) | |
|
158 | try: | |
|
159 | dvr = repr(trait.get_default_value()) | |
|
160 | except Exception: | |
|
161 | dvr = None # ignore defaults we can't construct | |
|
162 | if dvr is not None: | |
|
163 | header += ' [default: %s]'%dvr | |
|
164 | lines.append(header) | |
|
165 | ||
|
166 | help = trait.get_metadata('help') | |
|
167 | if help is not None: | |
|
168 | lines.append(indent(help, flatten=True)) | |
|
169 | if 'Enum' in trait.__class__.__name__: | |
|
170 | # include Enum choices | |
|
171 | lines.append(indent('Choices: %r'%(trait.values,), flatten=True)) | |
|
172 | return '\n'.join(lines) | |
|
155 | 173 | |
|
156 | 174 | @classmethod |
|
157 | 175 | def class_print_help(cls): |
General Comments 0
You need to be logged in to leave comments.
Login now