Package gbp :: Module config :: Class GbpOptionParser

[hide private]
[frames] | no frames]

# Class GbpOptionParser

    optparse.OptionContainer --+
                               |
           optparse.OptionParser --+
                                   |
                                  GbpOptionParser

Known Subclasses:
  - GbpOptionParserDebian

Handles commandline options and parsing of config files

Instance Methods | [hide private]

_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 |

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 |

add_boolean_config_file_option(self, option_name, dest) |

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']
    >>> files = GbpOptionParser.get_config_files()

# Remove the ~-expanded one >>> del files[1] >>> files ['/etc/git-buildpackage/gbp.conf', '.gbp.conf', 'debian/gbp.conf', '.git/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) 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)
Class Method

Get list of config files from the GBP_CONF_FILES environment variable.

Returns: `list`

    >>> conf_backup = os.getenv('GBP_CONF_FILES')
    >>> if conf_backup is not None: del os.environ['GBP_CONF_FILES']
    >>> files = GbpOptionParser.get_config_files()

# Remove the ~-expanded one >>> del files[1] >>> files ['/etc/git-buildpackage/gbp.conf', '.gbp.conf', 'debian/gbp.conf', '.git/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=`[``]`)
(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, option_name, dest, help=None, **kwargs)

set a option for the command line parser, the default is read from the config file

Parameters:
  - `option_name` (string) - name of the option
  - `dest` (string) - where to store this option
  - `help` (string) - help text

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',
       'color': 'auto',
       'color-scheme': '',
       'commit-msg': 'Update changelog for %(version)s release',
       'compression': 'auto',
      ...

### 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 comi
      tter\'s date, default is \'%(author-date-is-committer-date)s\'',
       'author-is-committer': 'Use the authors\'s name also as the comitter\
      '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',
       '.gbp.conf',
       'debian/gbp.conf',
       '.git/gbp.conf']