Allow specifying a mask when removing package files

This commit is contained in:
Martin Gracik 2010-08-12 15:17:44 +02:00
parent f602a2eb7b
commit 15988fd5b2
3 changed files with 31 additions and 12 deletions

View File

@ -150,9 +150,9 @@ class Lorax(BaseLoraxClass):
if not os.path.isdir("/tmp/pkglists"): if not os.path.isdir("/tmp/pkglists"):
os.makedirs("/tmp/pkglists") os.makedirs("/tmp/pkglists")
for pkg in self.installtree.yum.installed_packages: for pkgobj in self.installtree.yum.installed_packages.values():
with open("/tmp/pkglists/%s" % pkg.name, "w") as f: with open("/tmp/pkglists/%s" % pkgobj.name, "w") as f:
for filename in self.installtree.yum.get_file_list(pkg): for filename in pkgobj.filelist:
f.write("%s\n" % filename) f.write("%s\n" % filename)
self.installtree.run_ldconfig() self.installtree.run_ldconfig()
@ -623,7 +623,12 @@ class YumHelper(object):
@property @property
def installed_packages(self): def installed_packages(self):
pl = self.yb.doPackageLists() pl = self.yb.doPackageLists()
return pl.installed
d = {}
for pkgobj in pl.installed:
d[pkgobj.name] = pkgobj
return d
def get_file_list(self, package): def get_file_list(self, package):
return package.returnFileEntries() return package.returnFileEntries()

View File

@ -103,8 +103,14 @@ class BaseImageClass(BaseLoraxClass):
fname = os.path.join(self.dsttree, fname) fname = os.path.join(self.dsttree, fname)
remove_(fname) remove_(fname)
def removepkg(self, pkgname): def removepkg(self, *args):
self.pkgs_to_remove.add(pkgname) pkgname = args[0]
try:
mask = args[1]
except IndexError:
mask = "*"
self.pkgs_to_remove.add((pkgname, mask))
def symlink(self, link_target, link_name): def symlink(self, link_target, link_name):
link_name = os.path.join(self.dsttree, link_name) link_name = os.path.join(self.dsttree, link_name)

View File

@ -640,12 +640,20 @@ class Install(BaseImageClass):
"libdir": self.conf.libdir} "libdir": self.conf.libdir}
self.parse_template(self.template_file, variables) self.parse_template(self.template_file, variables)
# XXX remove whole packages # XXX remove packages
for pkg in self.installtree.yum.installed_packages: installed_packages = self.installtree.yum.installed_packages
if pkg.name in self.pkgs_to_remove: for pkgname, mask in self.pkgs_to_remove:
self.pinfo("removing not needed package %s" % pkg.name) if pkgname not in installed_packages:
for fname in pkg.filelist: continue
self.pdebug("removing file %s%s" % (self.srctree, fname))
self.pinfo("removing files from package %s matching mask %s" \
% (pkgname, mask))
pkgobj = installed_packages.get(pkgname)
for fname in pkgobj.filelist:
if fnmatch.fnmatch(fname, mask):
self.pdebug("removing file %s%s" \
% (self.srctree, fname))
remove_("%s%s" % (self.srctree, fname)) remove_("%s%s" % (self.srctree, fname))
self.copy_stubs() self.copy_stubs()