[yum-cvs] yum/yum config.py,1.46,1.47 repos.py,1.71,1.72
Seth Vidal
skvidal at login.linux.duke.edu
Wed Mar 9 08:14:22 UTC 2005
Update of /home/groups/yum/cvs/yum/yum
In directory login:/tmp/cvs-serv4950
Modified Files:
config.py repos.py
Log Message:
made the replacement variables in the config file ($releasever, $basearch,
$arch, $YUM0-$YUM9) apply to almost all of the options equally. Cleaned up a
fair bit of code and muddied some other code
Index: config.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/config.py,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- config.py 9 Mar 2005 06:36:48 -0000 1.46
+++ config.py 9 Mar 2005 08:14:20 -0000 1.47
@@ -24,6 +24,7 @@
import glob
import rpm
import re
+import types
import rpmUtils.transaction
import rpmUtils.arch
@@ -54,7 +55,7 @@
"""
try:
return self.getboolean(section, option)
- except (ConfigParser.NoSectionError, ConfigParser.NoOptionError), e:
+ except (ConfigParser.NoSectionError, ConfigParser.NoOptionError), e:
return default
def _getint(self, section, option, default=None):
@@ -216,15 +217,17 @@
'kernel-BOOT']),
('tsflags', [])]
- optionbools = [('assumeyes', 0),
- ('exactarch', 1),
- ('tolerant', 1),
- ('diskspacecheck', 1),
- ('overwrite_groups', 0),
- ('keepalive', 1),
- ('gpgcheck', 0),
- ('obsoletes', 0),
- ('showdupesfromrepos', 0)]
+ optionbools = [('assumeyes', 'False'),
+ ('exactarch', 'True'),
+ ('tolerant', 'True'),
+ ('diskspacecheck', 'True'),
+ ('overwrite_groups', 'False'),
+ ('keepalive', 'True'),
+ ('gpgcheck', 'False'),
+ ('obsoletes', 'False'),
+ ('showdupesfromrepos', 'False'),
+ ('enabled', 'True'),
+ ('enablegroups', 'True')]
# not being set from the config file
# or things that can't be handled like all the rest
@@ -236,21 +239,60 @@
optionfloats = [('timeout', 30.0)]
+ # do these two early so we can do the rest using variableReplace()
+ for (option, default) in [('distroverpkg' , 'fedora-release'),
+ ('installroot', root)]:
+ value = self.cfg._getoption('main', option, default)
+ self.configdata[option] = value
+ setattr(self, option, value)
+
+ # get our variables parsed
+ self.yumvar = self._getEnvVar()
+ self.yumvar['basearch'] = rpmUtils.arch.getBaseArch() # FIXME make this configurable??
+ self.yumvar['arch'] = rpmUtils.arch.getCanonArch() # FIXME make this configurable??
+ # figure out what the releasever really is from the distroverpkg
+ self.yumvar['releasever'] = self._getsysver()
+
# do the ints
for (option, default) in optionints:
- value = self.cfg._getint('main', option, default)
+ try:
+ value = self.cfg._getoption('main', option, default)
+ value = variableReplace(self.yumvar, value)
+ value = int(value)
+ except ValueError, e:
+ raise Errors.ConfigError, 'Invalid value in config for main::%s' % option
self.configdata[option] = value
setattr(self, option, value)
- # do the strings
+ # do the floats
+ for (option, value) in optionfloats:
+ try:
+ value = self.cfg._getoption('main', option, default)
+ value = variableReplace(self.yumvar, value)
+ value = float(value)
+ except ValueError, e:
+ raise Errors.ConfigError, 'Invalid value in config for main::%s' % option
+
+ self.configdata[option] = value
+ setattr(self, option, value)
+
+ # do the strings
for (option, default) in optionstrings:
value = self.cfg._getoption('main', option, default)
+ value = variableReplace(self.yumvar, value)
self.configdata[option] = value
setattr(self, option, value)
# do the bools
+ self._boolean_states = {'1': True, 'yes': True, 'true': True, 'on': True,
+ '0': False, 'no': False, 'false': False, 'off': False}
+
for (option, default) in optionbools:
- value = self.cfg._getboolean('main', option, default)
+ value = self.cfg._getoption('main', option, default)
+ value = variableReplace(self.yumvar, value)
+ if value.lower() not in self._boolean_states:
+ raise Errors.ConfigError, 'Invalid value in config for main::%s' % option
+ value = self._boolean_states[value.lower()]
self.configdata[option] = value
setattr(self, option, value)
@@ -259,13 +301,6 @@
self.configdata[option] = value
setattr(self, option, value)
- # do the floats
- for (option, value) in optionfloats:
- value = self.cfg._getfloat('main', option, default)
- self.configdata[option] = value
- setattr(self, option, value)
-
-
# do the dirs - set the root if there is one (grumble)
for option in ['cachedir', 'logfile']:
path = self.configdata[option]
@@ -278,18 +313,11 @@
for option, getfunc in (('bandwidth', self.cfg.getbytes),
('throttle', self.cfg.getthrottle)):
value = getfunc('main', option, 0)
+ value = variableReplace(self.yumvar, value)
self.configdata[option] = value
setattr(self, option, value)
-
- # get our variables parsed
- self.yumvar = self._getEnvVar()
- self.yumvar['basearch'] = rpmUtils.arch.getBaseArch() # FIXME make this configurable??
- self.yumvar['arch'] = rpmUtils.arch.getCanonArch() # FIXME make this configurable??
- # figure out what the releasever really is from the distroverpkg
- self.yumvar['releasever'] = self._getsysver()
-
# weird ones
for option in ['commands', 'installonlypkgs', 'kernelpkgnames', 'exclude']:
self.configdata[option] = variableReplace(self.yumvar, self.configdata[option])
@@ -385,20 +413,36 @@
thisrepo = Repository(section)
thisrepo.set('yumvar', yumconfig.yumvar)
-
- enabled = cfgparser._getboolean(section, 'enabled', 1)
- name = cfgparser._getoption(section, 'name', section)
- name = variableReplace(yumconfig.yumvar, name)
- thisrepo.set('name', name)
- thisrepo.set('enabled', enabled)
-
+
+ for keyword in ['proxy_username', 'proxy', 'proxy_password',
+ 'retries', 'failovermethod', 'name']:
+ val = cfgparser._getoption(section, keyword, yumconfig.getConfigOption(keyword))
+ val = variableReplace(yumconfig.yumvar, val)
+ thisrepo.set(keyword, val)
+
+ for keyword in ['gpgcheck', 'keepalive', 'enablegroups', 'enabled']:
+ val = cfgparser._getoption(section, keyword, yumconfig.getConfigOption(keyword))
+ val = variableReplace(yumconfig.yumvar, val)
+ if type(val) is not types.BooleanType:
+ if val.lower() not in yumconfig._boolean_states:
+ raise Errors.RepoError, 'Invalid value in repo config for %s::%s' % (section, keyword)
+ val = yumconfig._boolean_states[val.lower()]
+ thisrepo.set(keyword, val)
+
+ for (keyword, getfunc) in [('bandwidth', cfgparser.getbytes),
+ ('throttle', cfgparser.getthrottle),
+ ('timeout', cfgparser._getfloat)]:
+ val = getfunc(section, keyword, yumconfig.getConfigOption(keyword))
+ thisrepo.set(keyword, val)
+
+
+ # lists and weird items
baseurl = cfgparser._getoption(section, 'baseurl', [])
baseurls = parseList(baseurl)
mirrorlistfn = cfgparser._getoption(section, 'mirrorlist', None)
mirrorlistfn = variableReplace(yumconfig.yumvar, mirrorlistfn)
thisrepo.set('mirrorlistfn', mirrorlistfn)
thisrepo.set('baseurls', baseurls)
-
gpgkey = cfgparser._getoption(section, 'gpgkey', '')
if gpgkey:
@@ -409,26 +453,6 @@
gpgkey = variableReplace(yumconfig.yumvar, gpgkey)
thisrepo.set('gpgkey', gpgkey)
-
- for keyword in ['proxy_username', 'proxy', 'proxy_password',
- 'retries', 'failovermethod']:
-
- thisrepo.set(keyword, cfgparser._getoption(section, keyword, \
- yumconfig.getConfigOption(keyword)))
-
- for keyword, getfunc in (('bandwidth', cfgparser.getbytes),
- ('throttle', cfgparser.getthrottle)):
- thisrepo.set(keyword, getfunc(section, keyword,
- yumconfig.getConfigOption(keyword)))
-
- for keyword in ['gpgcheck', 'keepalive']:
- thisrepo.set(keyword, cfgparser._getboolean(section, \
- keyword, yumconfig.getConfigOption(keyword)))
-
- for keyword in ['timeout']:
- thisrepo.set(keyword, cfgparser._getfloat(section, \
- keyword, yumconfig.getConfigOption(keyword)))
-
excludelist = cfgparser._getoption(section, 'exclude', [])
excludelist = variableReplace(yumconfig.yumvar, excludelist)
excludelist = parseList(excludelist)
@@ -439,8 +463,6 @@
includelist = parseList(includelist)
thisrepo.set('includepkgs', includelist)
- thisrepo.set('enablegroups', cfgparser._getboolean(section, 'enablegroups', 1))
-
cachedir = os.path.join(yumconfig.getConfigOption('cachedir'), section)
pkgdir = os.path.join(cachedir, 'packages')
hdrdir = os.path.join(cachedir, 'headers')
Index: repos.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/repos.py,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -r1.71 -r1.72
--- repos.py 8 Mar 2005 10:41:36 -0000 1.71
+++ repos.py 9 Mar 2005 08:14:20 -0000 1.72
@@ -766,12 +766,16 @@
if thing is None:
return thing
- if type(thing) is types.StringType:
+ elif type(thing) is types.ListType:
+ shortlist = thing
+
+ elif type(thing) is types.StringType:
shortlist = []
shortlist.append(thing)
- if type(thing) is types.ListType:
- shortlist = thing
+ else:
+ # not a list or string, screw it
+ return thing
basearch_reg = re.compile('\$basearch', re.I)
arch_reg = re.compile('\$arch', re.I)
More information about the Yum-cvs-commits
mailing list