[Yum-devel] [PATCH] Add primary_only arg. to returnFileTypes(), use it from transactioninfo sack so that we don't require filelists to be downloaded.
James Antill
james at and.org
Thu Apr 15 16:55:34 UTC 2010
---
yum/packages.py | 23 ++++++++++++++++++++---
yum/sqlitesack.py | 11 ++++++++++-
yum/transactioninfo.py | 2 +-
3 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/yum/packages.py b/yum/packages.py
index 731d217..c1a14d0 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -514,9 +514,26 @@ class RpmBase(object):
return self.files[ftype]
return []
- def returnFileTypes(self):
- """return list of types of files in the package"""
- # maybe should die - use direct access to attribute
+ def returnFileTypes(self, primary_only=False):
+ """return list of types of files in the package, you can pass
+ primary_only=True to limit to those files in the primary repodata"""
+ if primary_only:
+ ret = [] # We only return the types for the primary files.
+ for ftype in self.files.keys():
+ if ftype == 'dir':
+ match = misc.re_primary_dirname
+ else:
+ match = misc.re_primary_filename
+ # As soon as we find a primary file of this type, we can
+ # return it.
+ for fn in self.files[ftype]:
+ if match(fn):
+ break
+ else:
+ continue
+ ret.append(ftype)
+ return ret
+
return self.files.keys()
def returnPrcoNames(self, prcotype):
diff --git a/yum/sqlitesack.py b/yum/sqlitesack.py
index 1885d57..43f60cd 100644
--- a/yum/sqlitesack.py
+++ b/yum/sqlitesack.py
@@ -353,6 +353,8 @@ class YumAvailablePackageSqlite(YumAvailablePackage, PackageObject, RpmBase):
return self._changelog
def returnFileEntries(self, ftype='file', primary_only=False):
+ """return list of files based on type, you can pass primary_only=True
+ to limit to those files in the primary repodata"""
if primary_only and not self._loadedfiles:
sql = "SELECT name as fname FROM files WHERE pkgKey = ? and type = ?"
cur = self._sql_MD('primary', sql, (self.pkgKey, ftype))
@@ -361,7 +363,14 @@ class YumAvailablePackageSqlite(YumAvailablePackage, PackageObject, RpmBase):
self._loadFiles()
return RpmBase.returnFileEntries(self,ftype,primary_only)
- def returnFileTypes(self):
+ def returnFileTypes(self, primary_only=False):
+ """return list of types of files in the package, you can pass
+ primary_only=True to limit to those files in the primary repodata"""
+ if primary_only and not self._loadedfiles:
+ sql = "SELECT DISTINCT type as ftype FROM files WHERE pkgKey = ?"
+ cur = self._sql_MD('primary', sql, (self.pkgKey,))
+ return map(lambda x: x['ftype'], cur)
+
self._loadFiles()
return RpmBase.returnFileTypes(self)
diff --git a/yum/transactioninfo.py b/yum/transactioninfo.py
index d7d8859..dfa34b3 100644
--- a/yum/transactioninfo.py
+++ b/yum/transactioninfo.py
@@ -39,7 +39,7 @@ class GetProvReqOnlyPackageSack(PackageSack):
self._need_index_files = need_files
def __addPackageToIndex_primary_files(self, obj):
- for ftype in obj.returnFileTypes():
+ for ftype in obj.returnFileTypes(primary_only=True):
for file in obj.returnFileEntries(ftype, primary_only=True):
self._addToDictAsList(self.filenames, file, obj)
def __addPackageToIndex_files(self, obj):
--
1.6.6.1
More information about the Yum-devel
mailing list