summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'deprecated/dep-clean/dep-clean')
-rw-r--r--deprecated/dep-clean/dep-clean164
1 files changed, 164 insertions, 0 deletions
diff --git a/deprecated/dep-clean/dep-clean b/deprecated/dep-clean/dep-clean
new file mode 100644
index 0000000..2f2bde0
--- /dev/null
+++ b/deprecated/dep-clean/dep-clean
@@ -0,0 +1,164 @@
+#!/usr/bin/python
+#
+# Terminology:
+#
+# portdir = /usr/portage + /usr/local/portage
+# vardir = /var/db/pkg
+
+import sys
+import gentoolkit
+try:
+ from portage.output import *
+except ImportError:
+ from output import *
+
+__author__ = "Karl Trygve Kalleberg, Brandon Low, Jerry Haltom"
+__email__ = "karltk@gentoo.org, lostlogic@gentoo.org, ssrit@larvalstage"
+__version__ = "0.2.0"
+__productname__ = "dep-clean"
+__description__ = "Portage auxiliary dependency checker"
+
+class Config:
+ pass
+
+def defaultConfig():
+ Config.displayUnneeded = 1
+ Config.displayNeeded = 1
+ Config.displayRemoved = 1
+ Config.color = -1
+ Config.verbosity = 2
+ Config.prefixes = { "R" : "",
+ "U" : "",
+ "N" : "" }
+def asCPVs(pkgs):
+ return map(lambda x: x.get_cpv(), pkgs)
+
+def asCPs(pkgs):
+ return map(lambda x: x.get_cp(), pkgs)
+
+def toCP(cpvs):
+ def _(x):
+ (c,p,v,r) = gentoolkit.split_package_name(x)
+ return c + "/" + p
+ return map(_, cpvs)
+
+def checkDeps():
+ if Config.verbosity > 1:
+ print "Scanning packages, please be patient..."
+
+ unmerged = asCPVs(gentoolkit.find_all_uninstalled_packages())
+ unmerged_cp = toCP(unmerged)
+
+ merged = asCPVs(gentoolkit.find_all_installed_packages())
+ merged_cp = toCP(merged)
+
+ (system, unres_system) = gentoolkit.find_system_packages()
+ system = asCPVs(system)
+
+ (world, unres_world) = gentoolkit.find_world_packages()
+ world = asCPVs(world)
+
+ desired = system + world
+
+ unneeded = filter(lambda x: x not in desired, merged)
+ needed = filter(lambda x: x not in merged, desired)
+ old = filter(lambda x: x not in unmerged_cp, merged_cp)
+
+ if len(needed):
+ print "Packages required, but not by world and system:"
+ for x in needed: print " " + x
+ raise "Internal error, please report."
+
+ if len(unres_system) and Config.displayNeeded:
+ if Config.verbosity > 0:
+ print white("Packages in system but not installed:")
+ for x in unres_system:
+ print " " + Config.prefixes["N"] + red(x)
+
+ if len(unres_world) and Config.displayNeeded:
+ if Config.verbosity > 0:
+ print white("Packages in world but not installed:")
+ for x in unres_world:
+ print " " + Config.prefixes["N"] + red(x)
+
+ if len(old) and Config.displayRemoved:
+ if Config.verbosity > 0:
+ print white("Packages installed, but no longer available:")
+ for x in old:
+ print " " + Config.prefixes["R"] + yellow(x)
+
+ if len(unneeded) and Config.displayUnneeded:
+ if Config.verbosity > 0:
+ print white("Packages installed, but not required by system or world:")
+ for x in unneeded:
+ print " " + Config.prefixes["U"] + green(x)
+
+def main():
+
+ defaultConfig()
+
+ for x in sys.argv:
+ if 0:
+ pass
+ elif x in ["-h","--help"]:
+ printUsage()
+ sys.exit(0)
+ elif x in ["-V","--version"]:
+ printVersion()
+ sys.exit(0)
+
+ elif x in ["-n","--needed","--needed=yes"]:
+ Config.displayNeeded = 1
+ elif x in ["-N","--needed=no"]:
+ Config.displayNeeded = 0
+
+ elif x in ["-u","--unneeded","--unneeded=yes"]:
+ Config.displayUnneeded = 1
+ elif x in ["-U","--unneeded=no"]:
+ Config.displayUnneeded = 0
+
+ elif x in ["-r","--removed","--removed=yes"]:
+ Config.displayRemoved = 1
+ elif x in ["-R","--removed","--removed=no"]:
+ Config.displayRemoved = 0
+ elif x in ["-c","--color=yes"]:
+ Config.color = 1
+ elif x in ["-C","--color=no"]:
+ Config.color = 0
+
+ elif x in ["-v", "--verbose"]:
+ Config.verbosity += 1
+ elif x in ["-q", "--quiet"]:
+ Config.verbosity = 0
+
+ # Set up colour output correctly
+ if (Config.color == -1 and \
+ ((not sys.stdout.isatty()) or \
+ (gentoolkit.settings["NOCOLOR"] in ["yes","true"]))) \
+ or \
+ Config.color == 0:
+ nocolor()
+ Config.prefixes = { "R": "R ", "N": "N ", "U": "U " }
+
+ checkDeps()
+
+def printVersion():
+ print __productname__ + "(" + __version__ + ") - " + \
+ __description__
+ print "Authors: " + __author__
+
+def printUsage():
+ print white("Usage: ") + turquoise(__productname__) + \
+ " [" + turquoise("options") + "]"
+ print "Where " + turquoise("options") + " is one of:"
+ print white("Display:")
+ print " -N,--needed needed packages that are not installed."
+ print " -R,--removed installed packages not in portage."
+ print " -U,--unneeded potentially unneeded packages that are installed."
+ print white("Other:")
+ print " -C,--nocolor output without color. Categories will be denoted by P,N,U."
+ print " -h,--help print this help"
+ print " -v,--version print version information"
+
+if __name__ == "__main__":
+ main()