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, git_treeish)
Read config file
 
parse_config_files(self, git_treeish=None)
Parse the possible config files and set appropriate values default values
 
__init__(self, command, prefix='', usage=None, sections=[], git_treeish=None)
 
_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
 
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 help: help text type help: string
 
add_boolean_config_file_option(self, option_name, dest=None)
str or None
get_config_file_value(self, option_name)
Query a single interpolated config file value.

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_help, 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]
>>> files_mangled
['/etc/git-buildpackage/gbp.conf', 'HOME/.gbp.conf', '%(top_dir)s/.gbp.conf', '%(top_dir)s/debian/gbp.conf', '%(git_dir)s/gbp.conf']
>>> files = GbpOptionParser.get_config_files(no_local=True)
>>> files_mangled = [file.replace(homedir, 'HOME') for file in files]
>>> 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.
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
list def_config_files = ['/etc/git-buildpackage/gbp.conf', '~/.gbp....
list of default config files we parse

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 (str) - 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]
>>> files_mangled
['/etc/git-buildpackage/gbp.conf', 'HOME/.gbp.conf', '%(top_dir)s/.gbp.conf', '%(top_dir)s/debian/gbp.conf', '%(git_dir)s/gbp.conf']
>>> files = GbpOptionParser.get_config_files(no_local=True)
>>> files_mangled = [file.replace(homedir, 'HOME') for file in files]
>>> 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

__init__(self, command, prefix='', usage=None, sections=[], git_treeish=None)
(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 help: help text type help: string

Decorators:
  • @safe_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

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',
 'build': 'True',
 'color': 'auto',
 'color-scheme': '',
 'commit': 'False',
...

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

list of default config files we parse
Type:
list
Value:
['/etc/git-buildpackage/gbp.conf',
 '~/.gbp.conf',
 '%(top_dir)s/.gbp.conf',
 '%(top_dir)s/debian/gbp.conf',
 '%(git_dir)s/gbp.conf']