Hi all,
The attached patch adds as properties most of the big yum base
attributes.
This should allow us to clean up all the random:
self.doRepoSetup()
self.doRpmDBSetup()
self.doSackSetup()
calls that are all over the code.
essentially now, if you just want the default configuration you can do:
import yum
my = yum.YumBase()
my.pkgSack.returnNevra(name='yum')
my.rpmdb.returnNevra(name='yum')
and it will work
calls to rpmdb will create the ts object and the conf object.
calls to pkgSack will create the repos and conf objects immediately
using the defaults of doRepoSetup() and doConfigSetup()
it's still possible for you to create these individually with special
options you just have to run them first.
Things not done:
- I've not made properties of: comps or up, yet. That's only b/c it is
late and I am sleepy.
anyway - let me know what you think and if we like it, I'll commit it.
-sv
? yum-3.1.2.tar.gz
Index: cli.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/cli.py,v
retrieving revision 1.256
diff -u -r1.256 cli.py
--- cli.py 16 Feb 2007 07:58:29 -0000 1.256
+++ cli.py 21 Feb 2007 07:26:07 -0000
@@ -91,10 +91,11 @@
"""grabs the repomd.xml for each enabled repository
and sets up the basics of the repository"""
- if self.pkgSack and thisrepo is None:
+ if self._repos and thisrepo is None:
self.verbose_logger.log(yum.logginglevels.DEBUG_4,
'skipping reposetup, pkgsack exists')
- return
+ return self._repos
+
self.verbose_logger.log(yum.logginglevels.INFO_2,
'Setting up repositories')
@@ -107,7 +108,8 @@
self.verbose_logger.log(yum.logginglevels.INFO_2,
'Reading repository metadata in from local files')
self.doSackSetup(thisrepo=thisrepo)
-
+
+ return self._repos
def getOptionsConfig(self, args):
"""parses command line arguments, takes cli args:
Index: yum/__init__.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/__init__.py,v
retrieving revision 1.281
diff -u -r1.281 __init__.py
--- yum/__init__.py 14 Feb 2007 21:35:09 -0000 1.281
+++ yum/__init__.py 21 Feb 2007 07:26:09 -0000
@@ -34,7 +34,7 @@
import rpmUtils.transaction
import comps
import config
-import repos
+from repos import RepoStorage
import misc
from parser import ConfigPreProcessor
import transactioninfo
@@ -62,14 +62,16 @@
def __init__(self):
depsolve.YumDepsolver.__init__(self)
- self.tsInfo = None
- self.rpmdb = None
+ self._conf = None
+ self._tsInfo = None
+ self._ts = None
+ self._rpmdb = None
self.up = None
self.comps = None
- self.pkgSack = None
+ self._pkgSack = None
self.logger = logging.getLogger("yum.YumBase")
self.verbose_logger = logging.getLogger("yum.verbose.YumBase")
- self.repos = repos.RepoStorage() # class of repositories
+ self._repos = None
# Start with plugins disabled
self.disablePlugins()
@@ -77,6 +79,7 @@
self.localPackages = [] # for local package handling
self.mediagrabber = None
+
def _transactionDataFactory(self):
"""Factory method returning TransactionData object"""
@@ -113,6 +116,9 @@
level will be read from the configuration file.
'''
+ if self._conf:
+ return self._conf
+
# TODO: Remove this block when we no longer support configs outside
# of /etc/yum/
if fn == '/etc/yum/yum.conf' and not os.path.exists(fn):
@@ -132,16 +138,20 @@
self.doPluginSetup(optparser, plugin_types, startupconf.pluginpath,
startupconf.pluginconfpath)
- self.conf = config.readMainConfig(startupconf)
+ self._conf = config.readMainConfig(startupconf)
self.yumvar = self.conf.yumvar
self.getReposFromConfig()
# who are we:
self.conf.uid = os.geteuid()
-
+ if self.conf.uid != 0:
+ self.conf.cache = 1
+
self.doFileLogSetup(self.conf.uid, self.conf.logfile)
self.plugins.run('init')
+ return self._conf
+
def doLoggingSetup(self, debuglevel, errorlevel):
'''
@@ -160,7 +170,7 @@
#FIXME this method could be a simpler
- reposlist = []
+ self.conf._reposlist = []
# Check yum.conf for repositories
for section in self.conf.cfg.sections():
@@ -173,7 +183,7 @@
except (Errors.RepoError, Errors.ConfigError), e:
self.logger.warning(e)
else:
- reposlist.append(thisrepo)
+ self.conf._reposlist.append(thisrepo)
# Read .repo files from directories specified by the reposdir option
# (typically /etc/yum/repos.d)
@@ -198,15 +208,8 @@
except (Errors.RepoError, Errors.ConfigError), e:
self.logger.warning(e)
else:
- reposlist.append(thisrepo)
+ self.conf._reposlist.append(thisrepo)
- # Got our list of repo objects, add them to the repos collection
- for thisrepo in reposlist:
- try:
- self.repos.add(thisrepo)
- except Errors.RepoError, e:
- self.logger.warning(e)
- continue
def readRepoConfig(self, parser, section):
'''Parse an INI file section for a repository.
@@ -266,40 +269,71 @@
This can't happen in __init__ b/c we don't know our installroot
yet"""
- if self.tsInfo != None and self.ts != None:
+ if self._tsInfo != None and self._ts != None:
return
if not self.conf.installroot:
raise Errors.YumBaseError, 'Setting up TransactionSets before config class is up'
- self.tsInfo = self._transactionDataFactory()
+ self._tsInfo = self._transactionDataFactory()
self.initActionTs()
+
+ def doTsInfoSetup(self):
+ if not self._tsInfo:
+ self._tsInfo = self._transactionDataFactory()
+
+ return self._tsInfo
+
+ def doActionTsSetup(self):
+ if not self._ts:
+ self.initActionTs()
+ return self._ts
def doRpmDBSetup(self):
"""sets up a holder object for important information from the rpmdb"""
- if self.rpmdb is None:
+ if self._rpmdb is None:
self.verbose_logger.debug('Reading Local RPMDB')
- self.rpmdb = rpmsack.RPMDBPackageSack(root=self.conf.installroot)
+ self._rpmdb = rpmsack.RPMDBPackageSack(root=self.conf.installroot)
+
+ return self._rpmdb
def closeRpmDB(self):
"""closes down the instances of the rpmdb we have wangling around"""
- self.rpmdb = None
- self.ts = None
+ self._rpmdb = None
+ self._ts = None
+ self._tsInfo = None
self.up = None
if self.comps != None:
self.comps.compiled = False
-
+
+ def _deleteTs(self):
+ del self._ts
+ self._ts = None
+
def doRepoSetup(self, thisrepo=None):
"""grabs the repomd.xml for each enabled repository and sets up
the basics of the repository"""
+
+ if not self._repos:
+ self._repos = RepoStorage()
+ else:
+ return self._repos
+
+ # Get our list of repo objects from conf, add them to the repos collection
+ for r in self.conf._reposlist:
+ try:
+ self.repos.add(r)
+ except Errors.RepoError, e:
+ self.logger.warning(e)
+ continue
self.plugins.run('prereposetup')
if thisrepo is None:
- repos = self.repos.listEnabled()
+ repos = self._repos.listEnabled()
else:
- repos = self.repos.findRepos(thisrepo)
+ repos = self._repos.findRepos(thisrepo)
if len(repos) < 1:
self.logger.critical('No Repositories Available to Set Up')
@@ -310,16 +344,20 @@
num += 1
- if self.repos.callback and len(repos) > 0:
- self.repos.callback.progressbar(num, len(repos), repo.id)
+ if self._repos.callback and len(repos) > 0:
+ self._repos.callback.progressbar(num, len(repos), repo.id)
self.plugins.run('postreposetup')
+ return self._repos
def doSackSetup(self, archlist=None, thisrepo=None):
"""populates the package sacks for information from our repositories,
takes optional archlist for archs to include"""
-
- if self.pkgSack and thisrepo is None:
+
+ if self._pkgSack:
+ return self._pkgSack
+
+ if self._pkgSack and thisrepo is None:
self.verbose_logger.log(logginglevels.DEBUG_4,
'skipping reposetup, pkgsack exists')
return
@@ -339,7 +377,8 @@
self.repos.getPackageSack().setCompatArchs(archdict)
self.repos.populateSack(which=repos)
- self.pkgSack = self.repos.getPackageSack()
+ self._pkgSack = self.repos.getPackageSack()
+
self.excludePackages()
self.pkgSack.excludeArchs(archlist)
@@ -348,6 +387,8 @@
self.includePackages(repo)
self.plugins.run('exclude')
self.pkgSack.buildIndexes()
+
+
def doUpdateSetup(self):
"""setups up the update object in the base class and fills out the
@@ -427,7 +468,16 @@
self.doRpmDBSetup()
pkglist = self.rpmdb.simplePkgList()
self.comps.compile(pkglist)
-
+
+
+ # properties so they auto-create themselves with defaults
+ repos = property(fget=lambda self: self.doRepoSetup())
+ pkgSack = property(fget=lambda self: self.doSackSetup())
+ conf = property(fget=lambda self: self.doConfigSetup())
+ rpmdb = property(fget=lambda self: self.doRpmDBSetup())
+ tsInfo = property(fget=lambda self: self.doTsInfoSetup())
+ ts = property(fget=lambda self: self.doActionTsSetup(), fdel=lambda self: self._deleteTs())
+
def doSackFilelistPopulate(self):
"""convenience function to populate the repos with the filelist metadata
it also is simply to only emit a log if anything actually gets populated"""
Index: yum/depsolve.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/depsolve.py,v
retrieving revision 1.130
diff -u -r1.130 depsolve.py
--- yum/depsolve.py 20 Feb 2007 17:04:52 -0000 1.130
+++ yum/depsolve.py 21 Feb 2007 07:26:10 -0000
@@ -33,7 +33,6 @@
class Depsolve(object):
def __init__(self):
- self.ts = None
packages.base = self
self.dsCallback = None
self.logger = logging.getLogger("yum.Depsolve")
@@ -43,25 +42,25 @@
def initActionTs(self):
"""sets up the ts we'll use for all the work"""
- self.ts = rpmUtils.transaction.TransactionWrapper(self.conf.installroot)
+ self._ts = rpmUtils.transaction.TransactionWrapper(self.conf.installroot)
ts_flags_to_rpm = { 'noscripts': rpm.RPMTRANS_FLAG_NOSCRIPTS,
'notriggers': rpm.RPMTRANS_FLAG_NOTRIGGERS,
'nodocs': rpm.RPMTRANS_FLAG_NODOCS,
'test': rpm.RPMTRANS_FLAG_TEST,
'repackage': rpm.RPMTRANS_FLAG_REPACKAGE}
- self.ts.setFlags(0) # reset everything.
+ self._ts.setFlags(0) # reset everything.
for flag in self.conf.tsflags:
if ts_flags_to_rpm.has_key(flag):
- self.ts.addTsFlag(ts_flags_to_rpm[flag])
+ self._ts.addTsFlag(ts_flags_to_rpm[flag])
else:
self.logger.critical('Invalid tsflag in config file: %s', flag)
probfilter = 0
for flag in self.tsInfo.probFilterFlags:
probfilter |= flag
- self.ts.setProbFilter(probfilter)
+ self._ts.setProbFilter(probfilter)
def whatProvides(self, name, flags, version):
"""searches the packageSacks for what provides the arguments
Index: yum/transactioninfo.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/transactioninfo.py,v
retrieving revision 1.36
diff -u -r1.36 transactioninfo.py
--- yum/transactioninfo.py 19 Feb 2007 22:40:04 -0000 1.36
+++ yum/transactioninfo.py 21 Feb 2007 07:26:10 -0000
@@ -37,6 +37,17 @@
self.conditionals = {} # key = pkgname, val = list of pos to add
+ # lists of txmbrs in their states - just placeholders
+ self.instgroups = []
+ self.removedgroups = []
+ self.removed = []
+ self.installed = []
+ self.updated = []
+ self.obsoleted = []
+ self.depremoved = []
+ self.depinstalled = []
+ self.depupdated = []
+
def __len__(self):
return len(self.pkgdict.values())
? rpmUtils/updates.py.crack
_______________________________________________
Yum-devel mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/yum-devel