gbp.config.GbpOptionParser(OptionParser)
class documentationgbp.config
(View In Hierarchy)
Known subclasses: gbp.config.GbpOptionParserDebian, gbp.config.GbpOptionParserRpm
Handles commandline options and parsing of config files
Instance Variable | command | the gbp command we store the options for |
Instance Variable | prefix | prefix to prepend to all commandline options |
Instance Variable | config | current configuration parameters |
Class Variable | defaults | defaults value of an option if not in the config file or given on the command line |
Class Variable | help | help messages |
Class Variable | def_config_files | config files we parse |
Class Variable | short_opts | Undocumented |
Class Variable | list_opts | Undocumented |
Class Method | get_config_files | Get list of config files from the GBP_CONF_FILES environment variable. |
Method | config_file_sections | List of all found config file sections |
Method | parse_lists | Parse options that can be given as lists |
Method | parse_config_files | Parse the possible config files and set appropriate values default values |
Method | __init__ | No summary |
Instance Variable | sections | Undocumented |
Instance Variable | valid_options | Undocumented |
Instance Variable | config_parser | Undocumented |
Method | get_default | get the default value |
Method | get_opt_names | Undocumented |
Method | add_config_file_option | No summary |
Method | add_boolean_config_file_option | Undocumented |
Method | get_config_file_value | Query a single interpolated config file value. |
Method | print_help | Print an extended help message, listing all options and any help text provided with them, to 'file' (default stdout). |
Method | _read_config_file | Read config file |
Method | _warn_old_config_section | Undocumented |
Method | _warn_old_gbp_conf | Undocumented |
Instance Variable | _warned_old_gbp_conf | Undocumented |
Static Method | _listify | No summary |
Method | _is_boolean | is option_name a boolean option |
Method | _get_bool_default | get default for boolean options this way we can handle no-foo=True and foo=False |
Class Method | _name_to_filename | Translate a name like 'system' to a config file name |
Class Method | _set_config_file_value | Write a config value to a file creating it if needed |
Get list of config files from the GBP_CONF_FILES environment variable.
Parameters | no_local | don't return the per-repo configuration files (type: bool ) |
Returns | list of config files we need to parse (type: list >>> import re >>> conf_backup = os.getenv('GBP_CONF_FILES') >>> if conf_backup is not None: del os.environ['GBP_CONF_FILES'] >>> homedir = os.path.expanduser("~") >>> files = GbpOptionParser.get_config_files() >>> files_mangled = [re.sub("^%s" % homedir, 'HOME', file) for file in files] >>> sorted(files_mangled) ['%(git_dir)s/gbp.conf', '%(top_dir)s/.gbp.conf', '%(top_dir)s/debian/gbp.conf', '/etc/git-buildpackage/gbp.conf', 'HOME/.gbp.conf'] >>> files = GbpOptionParser.get_config_files(no_local=True) >>> files_mangled = [re.sub("^%s" % homedir, 'HOME', file) for file in files] >>> sorted(files_mangled) ['/etc/git-buildpackage/gbp.conf', 'HOME/.gbp.conf'] >>> os.environ['GBP_CONF_FILES'] = 'test1:test2' >>> GbpOptionParser.get_config_files() ['test1', 'test2'] >>> del os.environ['GBP_CONF_FILES'] >>> if conf_backup is not None: os.environ['GBP_CONF_FILES'] = conf_backup) |
>>> GbpOptionParser._listify(None) [] >>> GbpOptionParser._listify('string') ['string'] >>> GbpOptionParser._listify('["q", "e", "d"] ') ['q', 'e', 'd'] >>> GbpOptionParser._listify('[') Traceback (most recent call last): ... configparser.Error: [ is not a proper list
Parse options that can be given as lists
Since they take multiple arguments they can also be given in plural form e.g. components instead of component.
Parse the possible config files and set appropriate values default values
Parameters | command | the command to build the config parser for (type: str ) |
prefix | A prefix to add to all command line options (type: str ) | |
usage | a usage description (type: str ) | |
sections | additional (non optional) config file sections to parse (type: list of str ) |
get default for boolean options this way we can handle no-foo=True and foo=False
set a option for the command line parser, the default is read from the config file param option_name: name of the option type option_name: string param dest: where to store this option type dest: string param help: help text type help: string
Query a single interpolated config file value.
Parameters | option_name | the config file option to look up (type: string) |
Returns | The config file option value or None if it doesn't exist (type: str or None ) |
Print an extended help message, listing all options and any help text provided with them, to 'file' (default stdout).
Translate a name like 'system' to a config file name
>>> GbpOptionParser._name_to_filename('foo') >>> GbpOptionParser._name_to_filename('system') '/etc/git-buildpackage/gbp.conf' >>> GbpOptionParser._name_to_filename('global') '~/.gbp.conf' >>> GbpOptionParser._name_to_filename('debian') '%(top_dir)s/debian/gbp.conf'