[yum-cvs] yum/yum sqlitesack.py,1.78,1.79 sqlutils.py,1.1,1.2
Seth Vidal
skvidal at linux.duke.edu
Sun Mar 4 15:36:26 UTC 2007
Update of /home/groups/yum/cvs/yum/yum
In directory login1.linux.duke.edu:/tmp/cvs-serv20002
Modified Files:
sqlitesack.py sqlutils.py
Log Message:
- implement not-quite-complete searchFiles() method to the sqlitesack
- add a couple of commented-out debug statements so I don't have to constantly
add and delete them to sqlutils
Index: sqlitesack.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/sqlitesack.py,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -r1.78 -r1.79
--- sqlitesack.py 4 Mar 2007 14:34:18 -0000 1.78
+++ sqlitesack.py 4 Mar 2007 15:36:24 -0000 1.79
@@ -22,6 +22,7 @@
import os
import os.path
import re
+import fnmatch
import yumRepo
from packages import PackageObject, RpmBase, YumAvailablePackage
@@ -40,10 +41,7 @@
'conflicts': [],
'requires': [],
'provides': [] }
- self.files = {'file':[],
- 'dir':[],
- 'ghost': [] }
-
+ self._files = {}
self.sack = repo.sack
self.repoid = repo.id
self.repo = repo
@@ -53,10 +51,11 @@
self.id = self.pkgId
self.ver = self.version
self.rel = self.release
-
+
self._changelog = None
-
+ files = property(fget=lambda self: self._loadFiles())
+
def _read_db_obj(self, db_obj, item=None):
"""read the db obj. If asked for a specific item, return it.
otherwise populate out into the object what exists"""
@@ -109,9 +108,9 @@
def _loadFiles(self):
if self._loadedfiles:
- return
+ return self._files
+
result = {}
- self.files = result
#FIXME - this should be try, excepting
self.sack.populate(self.repo, mdtype='filelists')
@@ -134,7 +133,9 @@
filetype = filetypes.pop()
result.setdefault(filetype,[]).append(filename)
self._loadedfiles = True
- self.files = result
+ self._files = result
+
+ return self._files
def _loadChangelog(self):
result = []
@@ -309,8 +310,67 @@
pkg = self.getPackageDetails(ob['pkgId'])
result.append((self.pc(rep,pkg)))
- return result
+ return result
+ def searchFiles(self, name):
+ """search primary if file will be in there, if not, search filelists, use globs, if possible"""
+
+ glob = True
+ if not re.match('.*[\*\?\[\]].*', name):
+ glob = False
+
+ pkgs = {}
+ for (rep,cache) in self.filelistsdb.items():
+ cur = cache.cursor()
+
+ # grab the entries that are a single file in the
+ # filenames section, use sqlites globbing if it is a glob
+ if glob:
+ executeSQL(cur, "select packages.pkgId as pkgId from filelist, \
+ packages where packages.pkgKey = filelist.pkgKey and \
+ length(filelist.filetypes) = 1 and \
+ filelist.dirname || ? || filelist.filenames \
+ glob ?", ('/', name))
+ else:
+ executeSQL(cur, "select packages.pkgId as pkgId from filelist, \
+ packages where packages.pkgKey = filelist.pkgKey and \
+ length(filelist.filetypes) = 1 and \
+ filelist.dirname || ? || filelist.filenames \
+ = ?", ('/', name))
+
+ for ob in cur.fetchall():
+ if self._excluded(rep, ob['pkgId']):
+ continue
+ pkg = self.getPackageDetails(ob['pkgId'])
+ po = self.pc(rep, pkg)
+ pkgs[po.pkgId] = po
+
+ # for all the ones where filenames is multiple files,
+ # make the files up whole and use python's globbing method
+ executeSQL(cur, "select packages.pkgID as pkgID, \
+ filelist.dirname as dirname, \
+ filelist.filenames as filenames \
+ from filelist,packages where \
+ packages.pkgKey = filelist.pkgKey \
+ and length(filelist.filetypes) > 1")
+
+ for (pkgId,d,fs) in cur.fetchall():
+ files = fs.split('/')
+ fns = map(lambda f: '%s/%s' % (d, f), files)
+ if glob:
+ matches = fnmatch.filter(fns, name)
+ else:
+ matches = filter(lambda x: name==x, fns)
+
+ if len(matches) > 0:
+ if self._excluded(rep, pkgId):
+ continue
+ pkg = self.getPackageDetails(pkgId)
+ po = self.pc(rep, pkg)
+ pkgs[po.pkgId] = po
+
+ return pkgs.values()
+
def searchPrimaryFields(self, fields, searchstring):
"""search arbitrary fields from the primarydb for a string"""
result = []
Index: sqlutils.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/sqlutils.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- sqlutils.py 5 Dec 2006 20:51:29 -0000 1.1
+++ sqlutils.py 4 Mar 2007 15:36:24 -0000 1.2
@@ -133,6 +133,7 @@
def executeSQLPyFormat(cursor, query, params=None):
+ #print query
if params is None:
return cursor.execute(query)
@@ -140,6 +141,7 @@
return cursor.execute(q, p)
def executeSQLQmark(cursor, query, params=None):
+ #print query
if params is None:
return cursor.execute(query)
More information about the Yum-cvs-commits
mailing list