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 @ivar command: the gbp command we store the options for @type command: string @ivar prefix: prefix to prepend to all commandline options @type prefix: string @ivar config: current configuration parameters @type config: dict @cvar defaults: defaults value of an option if not in the config file or given on the command line @type defaults: dict @cvar help: help messages @type help: dict @cvar def_config_files: config files we parse @type def_config_files: dict (type, path)
Class Method | get_config_files | Get list of config files from the I{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 |
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 |
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 I{GBP_CONF_FILES} environment variable. @param no_local: don't return the per-repo configuration files @type no_local: C{bool} @return: list of config files we need to parse @rtype: C{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
@param command: the command to build the config parser for @type command: C{str} @param prefix: A prefix to add to all command line options @type prefix: C{str} @param usage: a usage description @type usage: C{str} @param sections: additional (non optional) config file sections to parse @type sections: C{list} of C{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. @param option_name: the config file option to look up @type option_name: string @returns: The config file option value or C{None} if it doesn't exist @rtype: C{str} or C{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'