[yum-commits] Branch 'yum-3_2_X' - 3 commits - yum/__init__.py yum/config.py
James Antill
james at osuosl.org
Wed Mar 11 21:06:01 UTC 2009
yum/__init__.py | 6 ++----
yum/config.py | 40 ++++++++++++++++++++++++++++------------
2 files changed, 30 insertions(+), 16 deletions(-)
New commits:
commit d8c8e83194330a1595fa1c6d7e30c8f7fd797373
Author: James Antill <james at and.org>
Date: Wed Mar 11 16:34:43 2009 -0400
Speedup RepoConf.iterkeys() as we call it "a lot" - 20% speedup
diff --git a/yum/config.py b/yum/config.py
index bebccc6..d3ace8f 100644
--- a/yum/config.py
+++ b/yum/config.py
@@ -513,8 +513,9 @@ class BaseConfig(object):
def iterkeys(self):
'''Yield the names of all defined options in the instance.
'''
- for name, item in self.iteritems():
- yield name
+ for name in dir(self):
+ if self.isoption(name):
+ yield name
def iteritems(self):
'''Yield (name, value) pairs for every option in the instance.
@@ -522,9 +523,8 @@ class BaseConfig(object):
The value returned is the parsed, validated option value.
'''
# Use dir() so that we see inherited options too
- for name in dir(self):
- if self.isoption(name):
- yield (name, getattr(self, name))
+ 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
@@ -693,6 +693,20 @@ class RepoConf(BaseConfig):
'''
Option definitions for repository INI file sections.
'''
+
+ __cached_keys = set()
+ def iterkeys(self):
+ '''Yield the names of all defined options in the instance.
+ '''
+ ck = self.__cached_keys
+ if not isinstance(self, RepoConf):
+ ck = set()
+ if not ck:
+ ck.update(list(BaseConfig.iterkeys(self)))
+
+ for name in self.__cached_keys:
+ yield name
+
name = Option()
enabled = Inherit(YumConf.enabled)
baseurl = UrlListOption()
commit c0c64db26fed2634fd02b3e51c2537bce4f75a7f
Author: James Antill <james at and.org>
Date: Wed Mar 11 16:17:34 2009 -0400
Convert to RawConfigParser from iniparse, as we don't use %blah 5-10%
noop speedup.
Also don't double test repodirs, minor speedup.
diff --git a/yum/__init__.py b/yum/__init__.py
index a7ea490..eed78c2 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -37,7 +37,7 @@ _ = yum.i18n._
P_ = yum.i18n.P_
try:
- from iniparse.compat import ParsingError, ConfigParser
+ from iniparse.compat import ParsingError, RawConfigParser as ConfigParser
except ImportError:
from ConfigParser import ParsingError, ConfigParser
import Errors
@@ -338,9 +338,7 @@ class YumBase(depsolve.Depsolve):
self.getReposFromConfigFile(self.conf.config_file_path, repo_config_age)
for reposdir in self.conf.reposdir:
- if os.path.exists(self.conf.installroot+'/'+reposdir):
- reposdir = self.conf.installroot + '/' + reposdir
-
+ reposdir = self.conf.installroot + '/' + reposdir
if os.path.isdir(reposdir):
for repofn in sorted(glob.glob('%s/*.repo' % reposdir)):
thisrepo_age = os.stat(repofn)[8]
commit 700d8640ab0f497a0d210dff75b8b0b78ca56bc6
Author: James Antill <james at and.org>
Date: Wed Mar 11 16:16:01 2009 -0400
Remove exceptions from options processing, saves 5-10% noop
diff --git a/yum/config.py b/yum/config.py
index cedfaab..bebccc6 100644
--- a/yum/config.py
+++ b/yum/config.py
@@ -492,24 +492,22 @@ class BaseConfig(object):
if value is not None:
setattr(self, name, value)
- def optionobj(cls, name):
+ def optionobj(cls, name, exceptions=True):
'''Return the Option instance for the given name
'''
obj = getattr(cls, name, None)
if isinstance(obj, Option):
return obj
- else:
+ elif exceptions:
raise KeyError
+ else:
+ return None
optionobj = classmethod(optionobj)
def isoption(cls, name):
'''Return True if the given name refers to a defined option
'''
- try:
- cls.optionobj(name)
- return True
- except KeyError:
- return False
+ return cls.optionobj(name, exceptions=False) is not None
isoption = classmethod(isoption)
def iterkeys(self):
@@ -742,6 +740,8 @@ def readStartupConfig(configfile, root):
May raise Errors.ConfigError if a problem is detected with while parsing.
'''
+ # ' xemacs syntax hack
+
StartupConf.installroot.default = root
startupconf = StartupConf()
startupconf.config_file_path = configfile
@@ -771,6 +771,8 @@ def readMainConfig(startupconf):
@return: Populated YumConf instance.
'''
+ # ' xemacs syntax hack
+
# Set up substitution vars
yumvars = _getEnvVar()
yumvars['basearch'] = rpmUtils.arch.getBaseArch() # FIXME make this configurable??
More information about the Yum-commits
mailing list