Re: How to delete old yumdb entries?

James Antill <[email protected]>
Newsgroups gmane.linux.rpm.yum
Message-ID <[email protected]>
Mike Fleetwood <[email protected]> writes:

> Hi,
>
> I always upgrade my Fedora OS and this seems to have lead to a lot of
> old entries in my yumdb for old packages from previous versions of
> Fedora, which take quite a bit of space.  Is there anything special I
> need to do to delete them or do I just use rm?
>
> Commands below suggest at about 3/4 of the entries are for old
> packages from previous versions of Fedora.

 That's a lot, as this should only happen when transactions are
aborted before yum runs the cleanup on delete ... try this:

diff --git a/yumdb.py b/yumdb.py
index 8a4888e..ac683bf 100755
--- a/yumdb.py
+++ b/yumdb.py
@@ -7,8 +7,24 @@ import fnmatch
 import yum
 import shlex
 
+import os
+import glob
+
 parser = None
 
+# FIXME: Internal knowledge
+def _load_all_package_paths(db_path):
+    # glob the path and get a dict of pkgs to their subdir
+    glb = '%s/*/*/' % db_path
+    pkgdirs = glob.glob(glb)
+    _packages = {}
+    for d in pkgdirs:
+        if d[-1] == '/':
+            d = d[:-1]
+        pkgid = os.path.basename(d).split('-')[0]
+        _packages[pkgid] = d
+    return _packages
+
 def setup_opts():
     version = "0.0.1"
     vers_txt = "Manage yum groups metadata version %s" % version
@@ -183,6 +199,14 @@ def run_cmd(yb, args, inshell=False):
                 if ykey not in ndata:
                     continue
                 print " " * 4, ykey, '=', getattr(pkg.yumdb_info, ykey)
+    elif args[0] == 'extra':
+        yumdb_packages = _load_all_package_paths(yb.rpmdb.yumdb.conf.db_path)
+        for pkg in sorted(yb.rpmdb.returnPackages()):
+            if pkg.pkgid in yumdb_packages:
+                del yumdb_packages[pkg.pkgid]
+        for pkgid in yumdb_packages:
+            print "%s: %s" % (pkgid, yumdb_packages[pkgid])
+
     elif args[0] == 'shell' and not inshell:
         args.pop(0)
         if args:

...those dirs. should be safe to just delete (rm -rf), we can look at
doing something to make it a bit easier.

-- 
James Antill -- [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.