Show More
@@ -1,10 +1,10 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | # coding: utf-8 | |
2 | # encoding: utf-8 |
|
|||
3 | """A simple configuration system. |
|
2 | """A simple configuration system. | |
4 |
|
3 | |||
5 |
Authors |
|
4 | Authors | |
6 |
|
5 | ------- | ||
7 | * Brian Granger |
|
6 | * Brian Granger | |
|
7 | * Fernando Perez | |||
8 | """ |
|
8 | """ | |
9 |
|
9 | |||
10 | #----------------------------------------------------------------------------- |
|
10 | #----------------------------------------------------------------------------- | |
@@ -37,7 +37,25 b' class ConfigError(Exception):' | |||||
37 | class ConfigLoaderError(ConfigError): |
|
37 | class ConfigLoaderError(ConfigError): | |
38 | pass |
|
38 | pass | |
39 |
|
39 | |||
40 |
|
40 | #----------------------------------------------------------------------------- | ||
|
41 | # Argparse fix | |||
|
42 | #----------------------------------------------------------------------------- | |||
|
43 | # Unfortunately argparse by default prints help messages to stderr instead of | |||
|
44 | # stdout. This makes it annoying to capture long help screens at the command | |||
|
45 | # line, since one must know how to pipe stderr, which many users don't know how | |||
|
46 | # to do. So we override the print_help method with one that defaults to | |||
|
47 | # stdout and use our class instead. | |||
|
48 | ||||
|
49 | class ArgumentParser(argparse.ArgumentParser): | |||
|
50 | """Simple argparse subclass that prints help to stdout by default.""" | |||
|
51 | ||||
|
52 | def print_help(self, file=None): | |||
|
53 | if file is None: | |||
|
54 | file = sys.stdout | |||
|
55 | return super(ArgumentParser, self).print_help(file) | |||
|
56 | ||||
|
57 | print_help.__doc__ = argparse.ArgumentParser.print_help.__doc__ | |||
|
58 | ||||
41 | #----------------------------------------------------------------------------- |
|
59 | #----------------------------------------------------------------------------- | |
42 | # Config class for holding config information |
|
60 | # Config class for holding config information | |
43 | #----------------------------------------------------------------------------- |
|
61 | #----------------------------------------------------------------------------- | |
@@ -307,7 +325,7 b' class ArgParseConfigLoader(CommandLineConfigLoader):' | |||||
307 | return [] |
|
325 | return [] | |
308 |
|
326 | |||
309 | def _create_parser(self): |
|
327 | def _create_parser(self): | |
310 |
self.parser = |
|
328 | self.parser = ArgumentParser(*self.args, **self.kw) | |
311 | self._add_arguments() |
|
329 | self._add_arguments() | |
312 | self._add_other_arguments() |
|
330 | self._add_other_arguments() | |
313 |
|
331 | |||
@@ -333,4 +351,3 b' class ArgParseConfigLoader(CommandLineConfigLoader):' | |||||
333 | if v is not NoConfigDefault: |
|
351 | if v is not NoConfigDefault: | |
334 | exec_str = 'self.config.' + k + '= v' |
|
352 | exec_str = 'self.config.' + k + '= v' | |
335 | exec exec_str in locals(), globals() |
|
353 | exec exec_str in locals(), globals() | |
336 |
|
General Comments 0
You need to be logged in to leave comments.
Login now