Hi all: The attached patch makes urls, grab, and grabfunc lazily initialized properties on YumRepository. The benefit is that if your repos are using mirrorlists, then you only have to fetch the mirrorlists from the server if you are doing any operations that will need the network. Previously yum would always grab the mirrorlists, in many cases resulting in unneeded http connections.
Anyone see any cases where this will break stuff? -James
diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index c99fb20..0f0a723 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -202,7 +202,7 @@ class YumRepository(Repository, config.RepoConf):
config.RepoConf.__init__(self)
Repository.__init__(self, repoid)
- self.urls = []
+ self._urls = []
self.enablegroups = 0
self.groupsfilename = 'yumgroups.xml' # something some freaks might
# eventually want
@@ -237,6 +237,9 @@ class YumRepository(Repository, config.RepoConf):
self.storage = storagefactory.GetStorage()
self.sack = self.storage.GetPackageSack()
+ self._grabfunc = None
+ self._grab = None
+
def __getProxyDict(self):
self.doProxyDict()
if self._proxy_dict:
@@ -301,7 +304,6 @@ class YumRepository(Repository, config.RepoConf):
return output
def enable(self):
- self.baseurlSetup()
Repository.enable(self)
def check(self):
@@ -348,6 +350,11 @@ class YumRepository(Repository, config.RepoConf):
return headers
def setupGrab(self):
+ warnings.warn('setupGrab() will go away in a future version of Yum.\n',
+ Errors.YumFutureDeprecationWarning, stacklevel=2)
+ self._setupGrab()
+
+ def _setupGrab(self):
"""sets up the grabber functions with the already stocked in urls for
the mirror groups"""
@@ -371,9 +378,22 @@ class YumRepository(Repository, config.RepoConf):
reget='simple')
- self.grab = mgclass(self.grabfunc, self.urls,
+ self._grab = mgclass(self.grabfunc, self.urls,
failure_callback=self.mirror_failure_obj)
+ def _getgrabfunc(self):
+ if not self._grabfunc:
+ self._setupGrab()
+ return self._grabfunc
+
+ def _getgrab(self):
+ if not self._grab:
+ self._setupGrab()
+ return self._grab
+
+ grabfunc = property(lambda self: self._getgrabfunc())
+ grab = property(lambda self: self._getgrab())
+
def dirSetup(self):
"""make the necessary dirs, if possible, raise on failure"""
@@ -403,9 +423,13 @@ class YumRepository(Repository, config.RepoConf):
"Cannot access repository dir %s" % dir
def baseurlSetup(self):
+ warnings.warn('baseurlSetup() will go away in a future version of Yum.\n',
+ Errors.YumFutureDeprecationWarning, stacklevel=2)
+ self._baseurlSetup()
+
+ def _baseurlSetup(self):
"""go through the baseurls and mirrorlists and populate self.urls
with valid ones, run self.check() at the end to make sure it worked"""
-
goodurls = []
if self.mirrorlist and not self.mirrorlistparsed:
mirrorurls = getMirrorList(self.mirrorlist, self.proxy_dict)
@@ -423,9 +447,15 @@ class YumRepository(Repository, config.RepoConf):
else:
goodurls.append(url)
- self.setAttribute('urls', goodurls)
+ self._urls = goodurls
self.check()
- self.setupGrab() # update the grabber for the urls
+
+ def _geturls(self):
+ if not self._urls:
+ self._baseurlSetup()
+ return self._urls
+
+ urls = property(lambda self: self._geturls())
def _getFile(self, url=None, relative=None, local=None, start=None, end=None,
copy_local=0, checkfunc=None, text=None, reget='simple', cache=True):
@@ -582,7 +612,6 @@ class YumRepository(Repository, config.RepoConf):
try:
self.cache = cache
self.mediafunc = mediafunc
- self.baseurlSetup()
self.dirSetup()
except Errors.RepoError, e:
raise
@@ -747,19 +776,15 @@ class YumRepository(Repository, config.RepoConf):
def setCallback(self, callback):
self.callback = callback
- self.setupGrab()
def setFailureObj(self, failure_obj):
self.failure_obj = failure_obj
- self.setupGrab()
def setMirrorFailureObj(self, failure_obj):
self.mirror_failure_obj = failure_obj
- self.setupGrab()
def setInterruptCallback(self, callback):
self.interrupt_callback = callback
- self.setupGrab()
def getMirrorList(mirrorlist, pdict = None):
"""retrieve an up2date-style mirrorlist file from a url,
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Yum-devel mailing list [EMAIL PROTECTED] https://lists.dulug.duke.edu/mailman/listinfo/yum-devel
