class GbpOptionParser(OptionParser):
Known subclasses: gbp.config.GbpOptionParserDebian
, gbp.config.GbpOptionParserRpm
Handles commandline options and parsing of config files
Class Method | get |
Get list of config files from the GBP_CONF_FILES environment variable. |
Method | __init__ |
No summary |
Method | add |
Undocumented |
Method | add |
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... |
Method | get |
Query a single interpolated config file value. |
Method | get |
get the default value |
Method | get |
Undocumented |
Method | parse |
Parse the possible config files and set appropriate values default values |
Method | parse |
Parse options that can be given as lists |
Method | print |
Print an extended help message, listing all options and any help text provided with them, to 'file' (default stdout). |
Class Variable | def |
config files we parse |
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 | list |
Undocumented |
Class Variable | short |
Undocumented |
Instance Variable | command |
the gbp command we store the options for |
Instance Variable | config |
current configuration parameters |
Instance Variable | config |
Undocumented |
Instance Variable | prefix |
prefix to prepend to all commandline options |
Instance Variable | sections |
Undocumented |
Instance Variable | valid |
Undocumented |
Property | config |
List of all found config file sections |
Class Method | _name |
Translate a name like 'system' to a config file name |
Class Method | _set |
Write a config value to a file creating it if needed |
Static Method | _listify |
No summary |
Method | _get |
get default for boolean options this way we can handle no-foo=True and foo=False |
Method | _is |
is option_name a boolean option |
Method | _read |
Read config file |
Method | _warn |
Undocumented |
Method | _warn |
Undocumented |
Instance Variable | _warned |
Undocumented |
Get list of config files from the GBP_CONF_FILES environment variable.
Parameters | |
no | don't return the per-repo configuration files |
Returns | |
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 | list of config files we need to parse |
Parameters | |
command:str | the command to build the config parser for |
prefix:str | A prefix to add to all command line options |
usage:str | a usage description |
sections:list of str | additional (non optional) config file sections to parse |
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 | the config file option to look up |
Returns | |
str or None | The config file option value or None if it doesn't exist |
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.
Print an extended help message, listing all options and any help text provided with them, to 'file' (default stdout).
gbp.config.GbpOptionParserDebian
, gbp.config.GbpOptionParserRpm
defaults value of an option if not in the config file or given on the command line
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'
>>> 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