Package gbp :: Module config :: Class GbpOptionParser
[hide private]
[frames] | no frames]

Class GbpOptionParser

optparse.OptionContainer --+    
                           |    
       optparse.OptionParser --+
                               |
                              GbpOptionParser
Known Subclasses:

Handles commandline options and parsing of config files

Instance Methods [hide private]
 
_read_config_file(self, parser, repo, filename)
Read config file
 
_warn_old_config_section(self, oldcmd, cmd)
 
parse_lists(self)
Parse options that can be given as lists
 
parse_config_files(self)
Parse the possible config files and set appropriate values default values
 
__init__(self, command, prefix='', usage=None, sections=[])
 
_is_boolean(self, dummy, *unused, **kwargs)
is option_name a boolean option
 
_get_bool_default(self, option_name)
get default for boolean options this way we can handle no-foo=True and foo=False
 
get_default(self, option_name, **kwargs)
get the default value
 
get_opt_names(self, option_name)
 
add_config_file_option(self, *args, **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
 
add_boolean_config_file_option(self, option_name, dest)
str or None
get_config_file_value(self, option_name)
Query a single interpolated config file value.
 
print_help(self, file=None)
Print an extended help message, listing all options and any help text provided with them, to 'file' (default stdout).

Inherited from optparse.OptionParser: add_option_group, check_values, destroy, disable_interspersed_args, enable_interspersed_args, error, exit, expand_prog_name, format_epilog, format_help, format_option_help, get_default_values, get_description, get_option_group, get_prog_name, get_usage, get_version, parse_args, print_usage, print_version, set_default, set_defaults, set_process_default_values, set_usage

Inherited from optparse.OptionParser (private): _add_help_option, _add_version_option, _create_option_list, _get_all_options, _get_args, _get_encoding, _init_parsing_state, _match_long_opt, _populate_option_list, _process_args, _process_long_opt, _process_short_opts

Inherited from optparse.OptionContainer: add_option, add_options, format_description, get_option, has_option, remove_option, set_conflict_handler, set_description

Inherited from optparse.OptionContainer (private): _check_conflict, _create_option_mappings, _share_option_mappings

Class Methods [hide private]
list
>>> 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 = [file.replace(homedir, 'HOME') 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 = [file.replace(homedir, 'HOME') 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
get_config_files(klass, no_local=False)
Get list of config files from the GBP_CONF_FILES environment variable.
 
_name_to_filename(cls, name)
Translate a name like 'system' to a config file name
 
_set_config_file_value(cls, section, option, value, name=None, filename=None)
Write a config value to a file creating it if needed
Static Methods [hide private]
 
_listify(value)
Class Variables [hide private]
dict defaults = {'allow-unauthenticated': 'False', 'arch': '', 'aut...
defaults value of an option if not in the config file or given on the command line
dict help = {'allow-unauthenticated': 'Don\'t verify integrity of d...
help messages
  short_opts = {'urgency': '-U'}
dict (type, path) def_config_files = {'%(git_dir)s/gbp.conf': None, '%(top_dir)s...
config files we parse
  list_opts = ['filter', 'component']

Inherited from optparse.OptionParser: standard_option_list

Instance Variables [hide private]
string command
the gbp command we store the options for
dict config
current configuration parameters
string prefix
prefix to prepend to all commandline options
Method Details [hide private]

get_config_files(klass, no_local=False)
Class Method

 

Get list of config files from the GBP_CONF_FILES environment variable.

Parameters:
  • no_local (bool) - don't return the per-repo configuration files
Returns: list
>>> 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 = [file.replace(homedir, 'HOME') 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 = [file.replace(homedir, 'HOME') 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

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.

__init__(self, command, prefix='', usage=None, sections=[])
(Constructor)

 
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
Overrides: optparse.OptionContainer.__init__

add_config_file_option(self, *args, **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

Decorators:
  • @save_option

get_config_file_value(self, option_name)

 

Query a single interpolated config file value.

Parameters:
  • option_name (string) - the config file option to look up
Returns: str or None
The config file option value or None if it doesn't exist

print_help(self, file=None)

 

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

Overrides: optparse.OptionParser.print_help

_name_to_filename(cls, name)
Class Method

 

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'

_set_config_file_value(cls, section, option, value, name=None, filename=None)
Class Method

 

Write a config value to a file creating it if needed

On errors a ConfigParserError is raised


Class Variable Details [hide private]

defaults

defaults value of an option if not in the config file or given on the command line
Type:
dict
Value:
{'allow-unauthenticated': 'False',
 'arch': '',
 'author-date-is-committer-date': 'False',
 'author-is-committer': 'False',
 'bare': 'True',
 'cleaner': '/bin/true',
 'color': 'auto',
 'color-scheme': '',
...

help

help messages
Type:
dict
Value:
{'allow-unauthenticated': 'Don\'t verify integrity of downloaded sourc\
e, default is \'%(allow-unauthenticated)s\'',
 'arch': 'Build for this architecture when using git-pbuilder, default\
 is \'%(arch)s\'',
 'author-date-is-committer-date': 'Use the authors\'s date as the comm\
itter\'s date, default is \'%(author-date-is-committer-date)s\'',
 'author-is-committer': 'Use the authors\'s name also as the committer\
\'s name, default is \'%(author-is-committer)s\'',
...

def_config_files

config files we parse
Type:
dict (type, path)
Value:
{'%(git_dir)s/gbp.conf': None,
 '%(top_dir)s/.gbp.conf': None,
 '%(top_dir)s/debian/gbp.conf': 'debian',
 '/etc/git-buildpackage/gbp.conf': 'system',
 '~/.gbp.conf': 'global'}