[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#582791: New "showmanual" option for apt-cache



Package: apt
Version: 0.7.26~exp4
Severity: wishlist
Tags: experimental patch

0.7.26~exp4 introduced the apt-cache option "showauto" to replace
apt-mark showauto. It shows packages that were automatically
installed.

I'm proposing a new apt-cache option "showmanual" (or maybe
"showexplicit"?) which displays the packages that were manually
(explicitly) installed. This is useful as a replacement for
deborphan/orphaner and similar scripts which try to find orphaned
packages parsing the dependencies themselves (which is less reliable).

The patch seems to work fine (it's a rather trivial change), but there
might be a better way of testing whether or not a package is installed
instead of testing InstallVer != NULL. The unified diff applies to
0.7.26~exp4. Please let me know if the patch needs to be submitted in
a different format and I'll make the necessary changes.
--- apt-cache.cc.orig	2010-05-23 13:29:02.000000000 -0300
+++ apt-cache.cc	2010-05-23 13:54:08.000000000 -0300
@@ -1431,6 +1431,29 @@
 
    return true;
 }
+
+/* show manually installed packages (sorted) */
+bool ShowManual(CommandLine &CmdL)
+{
+   OpProgress op;
+   pkgDepCache DepCache(GCache);
+   DepCache.Init(&op);
+
+   std::vector<string> packages;
+   packages.reserve(GCache->HeaderP->PackageCount / 3);
+   
+   for (pkgCache::PkgIterator P = GCache->PkgBegin(); P.end() == false; P++)
+      if (DepCache[P].InstallVer && !(DepCache[P].Flags & pkgCache::Flag::Auto))
+         packages.push_back(P.Name());
+
+    std::sort(packages.begin(), packages.end());
+    
+    for (vector<string>::iterator I = packages.begin(); I != packages.end(); I++)
+            cout << *I << "\n";
+
+   return true;
+}
+
 									/*}}}*/
 // ShowPackage - Dump the package record to the screen			/*{{{*/
 // ---------------------------------------------------------------------
@@ -1803,6 +1826,7 @@
       "   search - Search the package list for a regex pattern\n"
       "   show - Show a readable record for the package\n"
       "   showauto - Display a list of automatically installed packages\n"
+      "   showmanual - Display a list of manually installed packages\n"
       "   depends - Show raw dependency information for a package\n"
       "   rdepends - Show reverse dependency information for a package\n"
       "   pkgnames - List the names of all packages in the system\n"
@@ -1868,6 +1892,7 @@
                                     {"show",&ShowPackage},
                                     {"pkgnames",&ShowPkgNames},
                                     {"showauto",&ShowAuto},
+                                    {"showmanual",&ShowManual},
                                     {"policy",&Policy},
                                     {"madison",&Madison},
                                     {0,0}};

Reply to: