class documentation

class GbpOptionParser(OptionParser):

Known subclasses: gbp.config.GbpOptionParserDebian, gbp.config.GbpOptionParserRpm

View In Hierarchy

Handles commandline options and parsing of config files

Class Method get_config_files Get list of config files from the GBP_CONF_FILES environment variable.
Method __init__ No summary
Method add_boolean_config_file_option Undocumented
Method add_config_file_option 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_config_file_value Query a single interpolated config file value.
Method get_default get the default value
Method get_opt_names Undocumented
Method parse_config_files Parse the possible config files and set appropriate values default values
Method parse_lists Parse options that can be given as lists
Method print_help Print an extended help message, listing all options and any help text provided with them, to 'file' (default stdout).
Class Variable def_config_files 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_opts Undocumented
Class Variable short_opts Undocumented
Instance Variable command the gbp command we store the options for
Instance Variable config current configuration parameters
Instance Variable config_parser Undocumented
Instance Variable prefix prefix to prepend to all commandline options
Instance Variable sections Undocumented
Instance Variable valid_options Undocumented
Property config_file_sections List of all found config file sections
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
Static Method _listify No summary
Method _get_bool_default get default for boolean options this way we can handle no-foo=True and foo=False
Method _is_boolean is option_name a boolean option
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
@classmethod
def get_config_files(cls, no_local=False):

Get list of config files from the GBP_CONF_FILES environment variable.

Parameters
no_local:booldon'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
def __init__(self, command, prefix='', usage=None, sections=[]):
Parameters
command:strthe command to build the config parser for
prefix:strA prefix to add to all command line options
usage:stra usage description
sections:list of stradditional (non optional) config file sections to parse
def add_boolean_config_file_option(self, option_name, dest):

Undocumented

@save_option
def add_config_file_option(self, option_name, dest, help=None, **kwargs):

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

def get_config_file_value(self, option_name):

Query a single interpolated config file value.

Parameters
option_name:stringthe config file option to look up
Returns
str or NoneThe config file option value or None if it doesn't exist
def get_default(self, option_name, **kwargs):

get the default value

def get_opt_names(self, option_name):

Undocumented

def parse_config_files(self):

Parse the possible config files and set appropriate values default values

def parse_lists(self):

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.

def print_help(self, file=None):

Print an extended help message, listing all options and any help text provided with them, to 'file' (default stdout).

def_config_files: dict (type, path) =

config files we parse

defaults: dict =

defaults value of an option if not in the config file or given on the command line

help: dict =

help messages

list_opts: list[str] =

Undocumented

short_opts: dict[str, str] =

Undocumented

command: string =

the gbp command we store the options for

config: dict =

current configuration parameters

config_parser =

Undocumented

prefix: string =

prefix to prepend to all commandline options

sections =

Undocumented

valid_options: list =

Undocumented

@property
config_file_sections =

List of all found config file sections

@classmethod
def _name_to_filename(cls, name):

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'
@classmethod
def _set_config_file_value(cls, section, option, value, name=None, filename=None):

Write a config value to a file creating it if needed

On errors a ConfigParserError is raised

@staticmethod
def _listify(value):
>>> 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
def _get_bool_default(self, option_name):

get default for boolean options this way we can handle no-foo=True and foo=False

def _is_boolean(self, dummy, *unused, **kwargs):

is option_name a boolean option

def _read_config_file(self, repo, filename):

Read config file

def _warn_old_config_section(self, oldcmd, cmd):

Undocumented

def _warn_old_gbp_conf(self, gbp_conf):
_warned_old_gbp_conf: bool =

Undocumented