[yum-cvs] yum/repomd packageSack.py,1.24,1.25
Seth Vidal
skvidal at linux.duke.edu
Sun May 28 04:41:52 UTC 2006
Update of /home/groups/yum/cvs/yum/repomd
In directory login1.linux.duke.edu:/tmp/cvs-serv4475
Modified Files:
packageSack.py
Log Message:
remove XMLPackageSack class b/c:
1. it removes our libxml2 dep
2. nothing uses this class b/c it is slow
Index: packageSack.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/repomd/packageSack.py,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- packageSack.py 11 Apr 2006 21:33:14 -0000 1.24
+++ packageSack.py 28 May 2006 04:41:50 -0000 1.25
@@ -12,9 +12,8 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-# Copyright 2003 Duke University
+# Copyright 2006 Duke University
-import libxml2
from mdErrors import PackageSackError
import mdUtils
@@ -547,215 +546,6 @@
return matches
-
-# packageSack should be a base class
-# two derived classes could be DBPackageSack and XMLPackageSack
-# one for importing this data from the localdb
-# another from XML metadata files
-
-class XMLPackageSack(PackageSack):
- """Derived class from PackageSack to build list from XML metadata file.
- Needs the Package Object Class passed to it for the Sack"""
- def __init__(self, pkgObjectClass):
- PackageSack.__init__(self)
- self.repoStatus = {} #[repoid]= [primary, filelist, other] (so you can tell
- #what things have been loaded or not - b/c w/o primary,
- #filelist and other really can't be loaded
- self.pkgObjectClass = pkgObjectClass
-
-
- def addFile(self, repoid, file, callback=None):
- """takes a repository id and an xml file. It populates whatever it can,
- if you try to populate with a filelist or other metadata file
- before the primary metadata you'll not like the results"""
- try:
- reader = libxml2.newTextReaderFilename(file)
- except libxml2.treeError:
- raise PackageSackError, "Invalid or non-existent file: %s" % (file)
-
- else:
- reader.Read()
- xmlfiletype=reader.Name() # - first node should be the type
- if xmlfiletype == 'metadata':
- if not self._checkRepoStatus(repoid, itemcheck='primary'):
- self.loadPrimaryMD(reader, repoid, callback)
-
- elif xmlfiletype == 'filelists':
- if not self._checkRepoStatus(repoid, itemcheck='filelists'):
- self.loadFileMD(reader, repoid, callback)
-
- elif xmlfiletype == 'otherdata':
- if not self._checkRepoStatus(repoid, itemcheck='other'):
- self.loadOtherMD(reader, repoid, callback)
-
- else:
- print 'Error: other unknown root element %s' % xmlfiletype
-
-
- def _checkRepoStatus(self, repoid, itemcheck='primary'):
- """return 1 if itemcheck is in repo"""
- if self.repoStatus.has_key(repoid):
- if itemcheck in self.repoStatus[repoid]:
- return 1
- return 0
-
- def __searchID(self, pkgid):
- """return list of packages based on pkgid"""
- self._checkIndexes(failure='build')
- if self.pkgsByID.has_key(pkgid):
- return self.pkgsByID[pkgid]
- else:
- return []
-
- def loadPrimaryMD(self, reader, repoid, callback=None):
- """load all the data from the primary metadata xml file"""
-
- pkgcount = 9999 # big number
- current = 1
- if reader.HasAttributes():
- pkgcount = int(reader.GetAttribute('packages'))
-
-
-
- ret = reader.Read()
- while ret:
- if reader.NodeType() == 14:
- ret = reader.Read()
- continue
-
- if reader.NodeType() == 1 and reader.Name() == 'package':
- if reader.HasAttributes():
- if reader.GetAttribute('type') == 'rpm':
- current+=1
- po = self.pkgObjectClass(reader, repoid)
- self.addPackage(po)
- if callback: callback(current, pkgcount, name=repoid)
- ret = reader.Read()
- continue
-
- # update the repoStatus
- if not self.repoStatus.has_key(repoid):
- self.repoStatus[repoid] = []
- if not 'primary' in self.repoStatus[repoid]:
- self.repoStatus[repoid].append('primary')
-
-
- def loadFileMD(self, reader, repoid, callback=None):
- """load all the filelist metadata from the file"""
-
- pkgcount = 9999 # big number
- current = 1
- if reader.HasAttributes():
- pkgcount = int(reader.GetAttribute('packages'))
-
- ret = reader.Read()
- while ret:
- if reader.NodeType() == 14:
- ret = reader.Read()
- continue
-
- if reader.NodeType() == 1 and reader.Name() == 'package':
- if reader.HasAttributes():
- pkgid = reader.GetAttribute('pkgid')
- pkgs = self.__searchID(pkgid)
- pkgmatch = 0
- mydepth = reader.Depth()
- current+=1
-
- for pkg in pkgs:
- if pkg.returnSimple('repoid') == repoid: # check for matching repo
- reader.Read()
- pkgmatch+=1
-
- while 1:
- if reader.NodeType() == 15 and reader.Depth() == mydepth:
- break
-
- elif reader.NodeType() == 14:
- ret = reader.Read()
- continue
-
- elif reader.NodeType() == 1:
- if reader.LocalName() == 'file':
- (ftype, file) = pkg.loadFileEntry(reader)
- #self._addToDictAsList(self.filenames, file, pkg)
-
- ret = reader.Read()
- continue
-
- if pkgmatch < 1:
- # FIXME - raise a warning? Emit error? bitch? moan?
- pass
-
-
- ret = reader.Read()
- if callback: callback(current, pkgcount, name=repoid) # give us some pretty output
- continue
-
- # update the repostatus
- if not 'filelist' in self.repoStatus[repoid]:
- self.repoStatus[repoid].append('filelist')
- # we've just added file items - build up the indexes again
- self.buildIndexes()
-
-
- def loadOtherMD(self, reader, repoid, callback=None):
- """load the changelog, etc data from the other.xml file"""
-
- pkgcount = 9999 # big number
- current = 1
- if reader.HasAttributes():
- pkgcount = int(reader.GetAttribute('packages'))
-
- ret = reader.Read()
- while ret:
- if reader.NodeType() == 14:
- ret = reader.Read()
- continue
-
- if reader.NodeType() == 1 and reader.Name() == 'package':
- current+=1
- if reader.HasAttributes():
- pkgid = reader.GetAttribute('pkgid')
- pkgs = self.__searchID(pkgid)
- pkgmatch = 0
- mydepth = reader.Depth()
- #current+=1
-
-
- for pkg in pkgs:
- if pkg.returnSimple('repoid') == repoid: # check for matching repo
- reader.Read()
- pkgmatch+=1
-
- while 1:
- if reader.NodeType() == 15 and reader.Depth() == mydepth:
- break
-
- elif reader.NodeType() == 14:
- ret = reader.Read()
- continue
-
- elif reader.NodeType() == 1:
- if reader.LocalName() == 'changelog':
- pkg.loadChangeLogEntry(reader)
-
- ret = reader.Read()
- continue
-
- if pkgmatch < 1:
- # FIXME - raise a warning? Emit error? bitch? moan?
- pass
- if callback: callback(current, pkgcount, name=repoid)
- ret = reader.Read()
- continue
-
- if not 'other' in self.repoStatus[repoid]:
- self.repoStatus[repoid].append('other')
- # we've just added file items - build up the indexes again
- self.buildIndexes()
-
-
class ListPackageSack(PackageSack):
"""Derived class from PackageSack to build new Sack from list of
pkgObjects - like one returned from self.returnNewestByNameArch()
More information about the Yum-cvs-commits
mailing list