[yum-commits] Branch 'yum-3_2_X' - yum/config.py
James Antill
james at osuosl.org
Thu Jul 28 13:39:32 UTC 2011
yum/config.py | 481 ++++++++++++++++++++++++++++++++++------------------------
1 file changed, 288 insertions(+), 193 deletions(-)
New commits:
commit 4063a2e9fe1e4559691d39ac05e9097e9a6133a8
Author: Nick Jacek <njacek at redhat.com>
Date: Wed Jul 27 16:31:30 2011 -0400
Adds documentation for the yum.config module, and modifies the existing documentation to be consistant.
diff --git a/yum/config.py b/yum/config.py
index dbf1784..bbeca66 100644
--- a/yum/config.py
+++ b/yum/config.py
@@ -47,13 +47,12 @@ __pkgs_gpgcheck_default__ = False
__repo_gpgcheck_default__ = False
class Option(object):
- '''
+ """
This class handles a single Yum configuration file option. Create
subclasses for each type of supported configuration option.
-
Python descriptor foo (__get__ and __set__) is used to make option
- definition easy and consise.
- '''
+ definition easy and concise.
+ """
def __init__(self, default=None, parse_default=False):
self._setattrname()
@@ -63,19 +62,19 @@ class Option(object):
self.default = default
def _setattrname(self):
- '''Calculate the internal attribute name used to store option state in
+ """Calculate the internal attribute name used to store option state in
configuration instances.
- '''
+ """
self._attrname = '__opt%d' % id(self)
def __get__(self, obj, objtype):
- '''Called when the option is read (via the descriptor protocol).
+ """Called when the option is read (via the descriptor protocol).
- @param obj: The configuration instance to modify.
- @param objtype: The type of the config instance (not used).
- @return: The parsed option value or the default value if the value
- wasn't set in the configuration file.
- '''
+ :param obj: The configuration instance to modify.
+ :param objtype: The type of the config instance (not used).
+ :return: The parsed option value or the default value if the value
+ wasn't set in the configuration file.
+ """
# xemacs highlighting hack: '
if obj is None:
return self
@@ -83,12 +82,11 @@ class Option(object):
return getattr(obj, self._attrname, None)
def __set__(self, obj, value):
- '''Called when the option is set (via the descriptor protocol).
+ """Called when the option is set (via the descriptor protocol).
- @param obj: The configuration instance to modify.
- @param value: The value to set the option to.
- @return: Nothing.
- '''
+ :param obj: The configuration instance to modify.
+ :param value: The value to set the option to.
+ """
# Only try to parse if it's a string
if isinstance(value, basestring):
try:
@@ -100,62 +98,59 @@ class Option(object):
setattr(obj, self._attrname, value)
def setup(self, obj, name):
- '''Initialise the option for a config instance.
+ """Initialise the option for a config instance.
This must be called before the option can be set or retrieved.
- @param obj: BaseConfig (or subclass) instance.
- @param name: Name of the option.
- '''
+ :param obj: :class:`BaseConfig` (or subclass) instance.
+ :param name: Name of the option.
+ """
self._optname = name
setattr(obj, self._attrname, copy.copy(self.default))
def clone(self):
- '''Return a safe copy of this Option instance
- '''
+ """Return a safe copy of this :class:`Option` instance.
+
+ :return: a safe copy of this :class:`Option` instance
+ """
new = copy.copy(self)
new._setattrname()
return new
def parse(self, s):
- '''Parse the string value to the Option's native value.
+ """Parse the string value to the :class:`Option`'s native value.
- @param s: Raw string value to parse.
- @return: Validated native value.
-
- Will raise ValueError if there was a problem parsing the string.
- Subclasses should override this.
- '''
+ :param s: raw string value to parse
+ :return: validated native value
+ :raise: ValueError if there was a problem parsing the string.
+ Subclasses should override this
+ """
return s
def tostring(self, value):
- '''Convert the Option's native value to a string value.
-
- @param value: Native option value.
- @return: String representation of input.
-
- This does the opposite of the parse() method above.
+ """Convert the :class:`Option`'s native value to a string value. This
+ does the opposite of the :func:`parse` method above.
Subclasses should override this.
- '''
+
+ :param value: native option value
+ :return: string representation of input
+ """
return str(value)
def Inherit(option_obj):
- '''Clone an Option instance for the purposes of inheritance. The returned
- instance has all the same properties as the input Option and shares items
+ """Clone an :class:`Option` instance for the purposes of inheritance. The returned
+ instance has all the same properties as the input :class:`Option` and shares items
such as the default value. Use this to avoid redefinition of reused
options.
- @param option_obj: Option instance to inherit.
- @return: New Option instance inherited from the input.
- '''
+ :param option_obj: :class:`Option` instance to inherit
+ :return: New :class:`Option` instance inherited from the input
+ """
new_option = option_obj.clone()
new_option.inherit = True
return new_option
class ListOption(Option):
-
- """
- An option containing a list of strings.
- """
+ """An option containing a list of strings."""
def __init__(self, default=None, parse_default=False):
if default is None:
@@ -163,10 +158,12 @@ class ListOption(Option):
super(ListOption, self).__init__(default, parse_default)
def parse(self, s):
- """Converts a string from the config file to a workable list, parses
- globdir: paths as foo.d-style dirs
+ """Convert a string from the config file to a workable list, parses
+ globdir: paths as foo.d-style dirs.
- Commas and spaces are used as separators for the list
+ :param s: The string to be converted to a list. Commas and
+ whitespace are used as separators for the list
+ :return: *s* converted to a list
"""
# we need to allow for the '\n[whitespace]' continuation - easier
# to sub the \n with a space and then read the lines
@@ -183,12 +180,18 @@ class ListOption(Option):
return results
def tostring(self, value):
+ """Convert a list of to a string value. This does the
+ opposite of the :func:`parse` method above.
+
+ :param value: a list of values
+ :return: string representation of input
+ """
return '\n '.join(value)
class UrlOption(Option):
- '''
- This option handles lists of URLs with validation of the URL scheme.
- '''
+ """This option handles lists of URLs with validation of the URL
+ scheme.
+ """
def __init__(self, default=None, schemes=('http', 'ftp', 'file', 'https'),
allow_none=False):
@@ -197,6 +200,13 @@ class UrlOption(Option):
self.allow_none = allow_none
def parse(self, url):
+ """Parse a url to make sure that it is valid, and in a scheme
+ that can be used.
+
+ :param url: a string containing the url to parse
+ :return: *url* if it is valid
+ :raises: :class:`ValueError` if there is an error parsing the url
+ """
url = url.strip()
# Handle the "_none_" special case
@@ -224,10 +234,9 @@ class UrlOption(Option):
return '%s or %s' % (', '.join(self.schemes[:-1]), self.schemes[-1])
class UrlListOption(ListOption):
- '''
- Option for handling lists of URLs with validation of the URL scheme.
- '''
-
+ """Option for handling lists of URLs with validation of the URL
+ scheme.
+ """
def __init__(self, default=None, schemes=('http', 'ftp', 'file', 'https'),
parse_default=False):
super(UrlListOption, self).__init__(default, parse_default)
@@ -236,6 +245,13 @@ class UrlListOption(ListOption):
self._urloption = UrlOption(schemes=schemes)
def parse(self, s):
+ """Parse a string containing multiple urls into a list, and
+ ensure that they are in a scheme that can be used.
+
+ :param s: the string to parse
+ :return: a list of strings containing the urls in *s*
+ :raises: :class:`ValueError` if there is an error parsing the urls
+ """
out = []
s = s.replace('\n', ' ')
s = s.replace(',', ' ')
@@ -254,10 +270,7 @@ class UrlListOption(ListOption):
class IntOption(Option):
-
- """
- An option representing an integer value.
- """
+ """An option representing an integer value."""
def __init__(self, default=None, range_min=None, range_max=None):
super(IntOption, self).__init__(default)
@@ -265,6 +278,13 @@ class IntOption(Option):
self._range_max = range_max
def parse(self, s):
+ """Parse a string containing an integer.
+
+ :param s: the string to parse
+ :return: the integer in *s*
+ :raises: :class:`ValueError` if there is an error parsing the
+ integer
+ """
try:
val = int(s)
except (ValueError, TypeError), e:
@@ -276,39 +296,56 @@ class IntOption(Option):
return val
class PositiveIntOption(IntOption):
-
+ """An option representing a positive integer value, where 0 can
+ have a special representation.
"""
- An option representing a positive integer value, where 0 can have a special
- represention.
- """
-
def __init__(self, default=None, range_min=0, range_max=None,
names_of_0=None):
super(PositiveIntOption, self).__init__(default, range_min, range_max)
self._names0 = names_of_0
def parse(self, s):
+ """Parse a string containing a positive integer, where 0 can
+ have a special representation.
+
+ :param s: the string to parse
+ :return: the integer in *s*
+ :raises: :class:`ValueError` if there is an error parsing the
+ integer
+ """
if s in self._names0:
return 0
return super(PositiveIntOption, self).parse(s)
class SecondsOption(Option):
+ """An option representing an integer value of seconds, or a human
+ readable variation specifying days, hours, minutes or seconds
+ until something happens. Works like :class:`BytesOption`. Note
+ that due to historical president -1 means "never", so this accepts
+ that and allows the word never, too.
- """
- An option representing an integer value of seconds, or a human readable
- variation specifying days, hours, minutes or seconds until something
- happens. Works like BytesOption.
- Note that due to historical president -1 means "never", so this accepts
- that and allows the word never too.
-
- Valid inputs: 100, 1.5m, 90s, 1.2d, 1d, 0xF, 0.1, -1, never
- Invalid inputs: -10, -0.1, 45.6Z, 1d6h, 1day, 1y
+ Valid inputs: 100, 1.5m, 90s, 1.2d, 1d, 0xF, 0.1, -1, never.
+ Invalid inputs: -10, -0.1, 45.6Z, 1d6h, 1day, 1y.
Return value will always be an integer
"""
MULTS = {'d': 60 * 60 * 24, 'h' : 60 * 60, 'm' : 60, 's': 1}
def parse(self, s):
+ """Parse a string containing an integer value of seconds, or a human
+ readable variation specifying days, hours, minutes or seconds
+ until something happens. Works like :class:`BytesOption`. Note
+ that due to historical president -1 means "never", so this accepts
+ that and allows the word never, too.
+
+ Valid inputs: 100, 1.5m, 90s, 1.2d, 1d, 0xF, 0.1, -1, never.
+ Invalid inputs: -10, -0.1, 45.6Z, 1d6h, 1day, 1y.
+
+ :param s: the string to parse
+ :return: an integer representing the number of seconds
+ specified by *s*
+ :raises: :class:`ValueError` if there is an error parsing the string
+ """
if len(s) < 1:
raise ValueError("no value specified")
@@ -335,14 +372,20 @@ class SecondsOption(Option):
return int(n * mult)
class BoolOption(Option):
-
- """
- An option representing a boolean value.
-
- The value can be one of 0, 1, yes, no, true, or false.
+ """An option representing a boolean value. The value can be one
+ of 0, 1, yes, no, true, or false.
"""
def parse(self, s):
+ """Parse a string containing a boolean value. 1, yes, and
+ true will evaluate to True; and 0, no, and false will evaluate
+ to False. Case is ignored.
+
+ :param s: the string containing the boolean value
+ :return: the boolean value contained in *s*
+ :raises: :class:`ValueError` if there is an error in parsing
+ the boolean value
+ """
s = s.lower()
if s in ('0', 'no', 'false'):
return False
@@ -352,30 +395,49 @@ class BoolOption(Option):
raise ValueError('invalid boolean value')
def tostring(self, value):
+ """Convert a boolean value to a string value. This does the
+ opposite of the :func:`parse` method above.
+
+ :param value: the boolean value to convert
+ :return: a string representation of *value*
+ """
if value:
return "1"
else:
return "0"
class FloatOption(Option):
- """
- An option representing a numeric float value.
- """
+ """An option representing a numeric float value."""
+
def parse(self, s):
+ """Parse a string containing a numeric float value.
+
+ :param s: a string containing a numeric float value to parse
+ :return: the numeric float value contained in *s*
+ :raises: :class:`ValueError` if there is an error parsing
+ float value
+ """
try:
return float(s.strip())
except (ValueError, TypeError):
raise ValueError('invalid float value')
class SelectionOption(Option):
- '''Handles string values where only specific values are allowed
- '''
+ """Handles string values where only specific values are
+ allowed.
+ """
def __init__(self, default=None, allowed=(), mapper={}):
super(SelectionOption, self).__init__(default)
self._allowed = allowed
self._mapper = mapper
def parse(self, s):
+ """Parse a string for specific values.
+
+ :param s: the string to parse
+ :return: *s* if it contains a valid value
+ :raises: :class:`ValueError` if there is an error parsing the values
+ """
if s in self._mapper:
s = self._mapper[s]
if s not in self._allowed:
@@ -383,18 +445,21 @@ class SelectionOption(Option):
return s
class CaselessSelectionOption(SelectionOption):
- ''' Mainly for compat. with BoolOption, works like SelectionOption but
- lowers input case. '''
-
+ """Mainly for compatibility with :class:`BoolOption`, works like
+ :class:`SelectionOption` but lowers input case.
+ """
def parse(self, s):
+ """Parse a string for specific values.
+
+ :param s: the string to parse
+ :return: *s* if it contains a valid value
+ :raises: :class:`ValueError` if there is an error parsing the values
+ """
return super(CaselessSelectionOption, self).parse(s.lower())
class BytesOption(Option):
-
- """
- An option representing a value in bytes.
-
- The value may be given in bytes, kilobytes, megabytes, or gigabytes.
+ """An option representing a value in bytes. The value may be given
+ in bytes, kilobytes, megabytes, or gigabytes.
"""
# Multipliers for unit symbols
MULTS = {
@@ -404,20 +469,18 @@ class BytesOption(Option):
}
def parse(self, s):
- """Parse a friendly bandwidth option to bytes
-
- The input should be a string containing a (possibly floating point)
- number followed by an optional single character unit. Valid units are
- 'k', 'M', 'G'. Case is ignored.
+ """Parse a friendly bandwidth option to bytes. The input
+ should be a string containing a (possibly floating point)
+ number followed by an optional single character unit. Valid
+ units are 'k', 'M', 'G'. Case is ignored. The convention that
+ 1k = 1024 bytes is used.
- Valid inputs: 100, 123M, 45.6k, 12.4G, 100K, 786.3, 0
- Invalid inputs: -10, -0.1, 45.6L, 123Mb
-
- Return value will always be an integer
-
- 1k = 1024 bytes.
+ Valid inputs: 100, 123M, 45.6k, 12.4G, 100K, 786.3, 0.
+ Invalid inputs: -10, -0.1, 45.6L, 123Mb.
- ValueError will be raised if the option couldn't be parsed.
+ :param s: the string to parse
+ :return: the number of bytes represented by *s*
+ :raises: :class:`ValueError` if the option can't be parsed
"""
if len(s) < 1:
raise ValueError("no value specified")
@@ -443,25 +506,23 @@ class BytesOption(Option):
return int(n * mult)
class ThrottleOption(BytesOption):
-
- """
- An option representing a bandwidth throttle value. See
- ThrottleOption.parse for acceptable input values.
+ """An option representing a bandwidth throttle value. See
+ :func:`parse` for acceptable input values.
"""
def parse(self, s):
- """Get a throttle option.
-
- Input may either be a percentage or a "friendly bandwidth value" as
- accepted by the BytesOption.
-
- Valid inputs: 100, 50%, 80.5%, 123M, 45.6k, 12.4G, 100K, 786.0, 0
- Invalid inputs: 100.1%, -4%, -500
-
- Return value will be a int if a bandwidth value was specified or a
- float if a percentage was given.
-
- ValueError will be raised if input couldn't be parsed.
+ """Get a throttle option. Input may either be a percentage or
+ a "friendly bandwidth value" as accepted by the
+ :class:`BytesOption`.
+
+ Valid inputs: 100, 50%, 80.5%, 123M, 45.6k, 12.4G, 100K, 786.0, 0.
+ Invalid inputs: 100.1%, -4%, -500.
+
+ :param s: the string to parse
+ :return: the bandwidth represented by *s*. The return value
+ will be an int if a bandwidth value was specified, and a
+ float if a percentage was given
+ :raises: :class:`ValueError` if input can't be parsed
"""
if len(s) < 1:
raise ValueError("no value specified")
@@ -479,10 +540,9 @@ class ThrottleOption(BytesOption):
return BytesOption.parse(self, s)
class BaseConfig(object):
- '''
- Base class for storing configuration definitions. Subclass when creating
- your own definitons.
- '''
+ """Base class for storing configuration definitions. Subclass when
+ creating your own definitions.
+ """
def __init__(self):
self._section = None
@@ -499,13 +559,14 @@ class BaseConfig(object):
return '\n'.join(out)
def populate(self, parser, section, parent=None):
- '''Set option values from a INI file section.
+ """Set option values from an INI file section.
- @param parser: ConfParser instance (or subclass)
- @param section: INI file section to read use.
- @param parent: Optional parent BaseConfig (or subclass) instance to use
- when doing option value inheritance.
- '''
+ :param parser: :class:`ConfigParser` instance (or subclass)
+ :param section: INI file section to read use
+ :param parent: Optional parent :class:`BaseConfig` (or
+ subclass) instance to use when doing option value
+ inheritance
+ """
self.cfg = parser
self._section = section
@@ -527,8 +588,19 @@ class BaseConfig(object):
setattr(self, name, value)
def optionobj(cls, name, exceptions=True):
- '''Return the Option instance for the given name
- '''
+ """Return the :class:`Option` instance for the given name.
+
+ :param cls: the class to return the :class:`Option` instance from
+ :param name: the name of the :class:`Option` instance to return
+ :param exceptions: defines what action to take if the
+ specified :class:`Option` instance does not exist. If *exceptions* is
+ True, a :class:`KeyError` will be raised. If *exceptions*
+ is False, None will be returned
+ :return: the :class:`Option` instance specified by *name*, or None if
+ it does not exist and *exceptions* is False
+ :raises: :class:`KeyError` if the specified :class:`Option` does not
+ exist, and *exceptions* is True
+ """
obj = getattr(cls, name, None)
if isinstance(obj, Option):
return obj
@@ -539,37 +611,41 @@ class BaseConfig(object):
optionobj = classmethod(optionobj)
def isoption(cls, name):
- '''Return True if the given name refers to a defined option
- '''
+ """Return True if the given name refers to a defined option.
+
+ :param cls: the class to find the option in
+ :param name: the name of the option to search for
+ :return: whether *name* specifies a defined option
+ """
return cls.optionobj(name, exceptions=False) is not None
isoption = classmethod(isoption)
def iterkeys(self):
- '''Yield the names of all defined options in the instance.
- '''
+ """Yield the names of all defined options in the instance."""
+
for name in dir(self):
if self.isoption(name):
yield name
def iteritems(self):
- '''Yield (name, value) pairs for every option in the instance.
-
- The value returned is the parsed, validated option value.
- '''
+ """Yield (name, value) pairs for every option in the
+ instance. The value returned is the parsed, validated option
+ value.
+ """
# Use dir() so that we see inherited options too
for name in self.iterkeys():
yield (name, getattr(self, name))
def write(self, fileobj, section=None, always=()):
- '''Write out the configuration to a file-like object
+ """Write out the configuration to a file-like object.
- @param fileobj: File-like object to write to
- @param section: Section name to use. If not-specified the section name
- used during parsing will be used.
- @param always: A sequence of option names to always write out.
+ :param fileobj: File-like object to write to
+ :param section: Section name to use. If not specified, the section name
+ used during parsing will be used
+ :param always: A sequence of option names to always write out.
Options not listed here will only be written out if they are at
- non-default values. Set to None to dump out all options.
- '''
+ non-default values. Set to None to dump out all options
+ """
# Write section heading
if section is None:
if self._section is None:
@@ -586,6 +662,14 @@ class BaseConfig(object):
self.cfg.write(fileobj)
def getConfigOption(self, option, default=None):
+ """Return the current value of the given option.
+
+ :param option: string specifying the option to return the
+ value of
+ :param default: the value to return if the option does not exist
+ :return: the value of the option specified by *option*, or
+ *default* if it does not exist
+ """
warnings.warn('getConfigOption() will go away in a future version of Yum.\n'
'Please access option values as attributes or using getattr().',
DeprecationWarning)
@@ -594,6 +678,12 @@ class BaseConfig(object):
return default
def setConfigOption(self, option, value):
+ """Set the value of the given option to the given value.
+
+ :param option: string specifying the option to set the value
+ of
+ :param value: the value to set the option to
+ """
warnings.warn('setConfigOption() will go away in a future version of Yum.\n'
'Please set option values as attributes or using setattr().',
DeprecationWarning)
@@ -603,11 +693,10 @@ class BaseConfig(object):
raise Errors.ConfigError, 'No such option %s' % option
class StartupConf(BaseConfig):
- '''
- Configuration option definitions for yum.conf's [main] section that are
- required early in the initialisation process or before the other [main]
- options can be parsed.
- '''
+ """Configuration option definitions for yum.conf's [main] section
+ that are required early in the initialisation process or before
+ the other [main] options can be parsed.
+ """
# xemacs highlighting hack: '
debuglevel = IntOption(2, 0, 10)
errorlevel = IntOption(2, 0, 10)
@@ -625,11 +714,10 @@ class StartupConf(BaseConfig):
persistdir = Option('/var/lib/yum')
class YumConf(StartupConf):
- '''
- Configuration option definitions for yum.conf\'s [main] section.
+ """Configuration option definitions for yum.conf's [main] section.
- Note: see also options inherited from StartupConf
- '''
+ Note: see also options inherited from :class:`StartupConf`
+ """
retries = PositiveIntOption(10, names_of_0=["<forever>"])
recent = IntOption(7, range_min=0)
@@ -757,6 +845,12 @@ class YumConf(StartupConf):
_reposlist = []
def dump(self):
+ """Return a string representing the values of all the
+ configuration options.
+
+ :return: a string representing the values of all the
+ configuration options
+ """
output = '[main]\n'
# we exclude all vars which start with _ or are in this list:
excluded_vars = ('cfg', 'uid', 'yumvar', 'progress_obj', 'failure_obj',
@@ -779,14 +873,12 @@ class YumConf(StartupConf):
return output
class RepoConf(BaseConfig):
- '''
- Option definitions for repository INI file sections.
- '''
+ """Option definitions for repository INI file sections."""
__cached_keys = set()
def iterkeys(self):
- '''Yield the names of all defined options in the instance.
- '''
+ """Yield the names of all defined options in the instance."""
+
ck = self.__cached_keys
if not isinstance(self, RepoConf):
ck = set()
@@ -840,23 +932,23 @@ class RepoConf(BaseConfig):
skip_if_unavailable = BoolOption(False)
class VersionGroupConf(BaseConfig):
+ """Option definitions for version groups."""
+
pkglist = ListOption()
run_with_packages = BoolOption(False)
def readStartupConfig(configfile, root):
- '''
- Parse Yum's main configuration file and return a StartupConf instance.
-
- This is required in order to access configuration settings required as Yum
- starts up.
+ """Parse Yum's main configuration file and return a
+ :class:`StartupConf` instance. This is required in order to
+ access configuration settings required as Yum starts up.
- @param configfile: The path to yum.conf.
- @param root: The base path to use for installation (typically '/')
- @return: A StartupConf instance.
+ :param configfile: the path to yum.conf
+ :param root: the base path to use for installation (typically '/')
+ :return: A :class:`StartupConf` instance
- May raise Errors.ConfigError if a problem is detected with while parsing.
- '''
+ :raises: :class:`Errors.ConfigError` if a problem is detected with while parsing.
+ """
# ' xemacs syntax hack
@@ -885,12 +977,11 @@ def readStartupConfig(configfile, root):
return startupconf
def readMainConfig(startupconf):
- '''
- Parse Yum's main configuration file
+ """Parse Yum's main configuration file
- @param startupconf: StartupConf instance as returned by readStartupConfig()
- @return: Populated YumConf instance.
- '''
+ :param startupconf: :class:`StartupConf` instance as returned by readStartupConfig()
+ :return: Populated :class:`YumConf` instance
+ """
# ' xemacs syntax hack
@@ -957,6 +1048,12 @@ def readMainConfig(startupconf):
return yumconf
def readVersionGroupsConfig(configfile="/etc/yum/version-groups.conf"):
+ """Parse the configuration file for version groups.
+
+ :param configfile: the configuration file to read
+ :return: a dictionary containing the parsed options
+ """
+
parser = ConfigParser()
confpp_obj = ConfigPreProcessor(configfile)
try:
@@ -971,17 +1068,16 @@ def readVersionGroupsConfig(configfile="/etc/yum/version-groups.conf"):
def getOption(conf, section, name, option):
- '''Convenience function to retrieve a parsed and converted value from a
- ConfigParser.
-
- @param conf: ConfigParser instance or similar
- @param section: Section name
- @param name: Option name
- @param option: Option instance to use for conversion.
- @return: The parsed value or default if value was not present.
-
- Will raise ValueError if the option could not be parsed.
- '''
+ """Convenience function to retrieve a parsed and converted value from a
+ :class:`ConfigParser`.
+
+ :param conf: ConfigParser instance or similar
+ :param section: Section name
+ :param name: :class:`Option` name
+ :param option: :class:`Option` instance to use for conversion
+ :return: The parsed value or default if value was not present
+ :raises: :class:`ValueError` if the option could not be parsed
+ """
try:
val = conf.get(section, name)
except (NoSectionError, NoOptionError):
@@ -1040,13 +1136,12 @@ def _getsysver(installroot, distroverpkg):
return releasever
def writeRawRepoFile(repo,only=None):
- """
- Writes changes in a repo object back to a .repo file.
- @param repo: Repo Object
- @param only: List of attributes to work on (None = All)
- It work by reading the repo file, changes the values there shall be changed and write it back to disk.
- """
+ """Write changes in a repo object back to a .repo file.
+ :param repo: the Repo Object to write back out
+ :param only: list of attributes to work on. If *only* is None, all
+ options will be written out
+ """
if not _use_iniparse:
return
More information about the Yum-commits
mailing list