Commits

Michał Górny committed fa80d6b

Support '--drop-unmatched-pkgs' cleanup action.

Comments (0)

Files changed (2)

lib/flaggie/cleanup.py

 # (C) 2010 Michał Górny <gentoo@mgorny.alt.pl>
 # Released under the terms of the 3-clause BSD license.
 
+from portage.exception import AmbiguousPackageName, InvalidAtom
+
 class BaseCleanupAction(object):
 	def __init__(self, *args):
 		if args:
 				else:
 					pe.remove(flag)
 
+class DropUnmatchedPkgs(BaseCleanupAction):
+	def _perform(self, f):
+		cache = {}
+
+		class AllMatcher(object):
+			def __eq__(self, other):
+				return True
+
+		am = AllMatcher()
+
+		for pe in f:
+			if pe.package not in cache:
+				try:
+					cache[pe.package] = bool(self._dbapi.xmatch('match-all', pe.package))
+				except (InvalidAtom, AmbiguousPackageName):
+					cache[pe.package] = False
+
+			# implicitly remove the package through removing all of its flags
+			if not cache[pe.package]:
+				del pe[am]
+
 class SortEntries(BaseCleanupAction):
 	def _perform(self, f):
 		f.sort()

lib/flaggie/cli.py

 from flaggie import PV
 from flaggie.action import Action, ActionSet, ParserError, ParserWarning
 from flaggie.cache import Caches
-from flaggie.cleanup import DropIneffective, SortEntries, SortFlags
+from flaggie.cleanup import DropIneffective, DropUnmatchedPkgs, \
+		SortEntries, SortFlags
 from flaggie.packagefile import PackageFiles
 
 def parse_actions(args, dbapi, settings, quiet = False, strict = False):
 	--sort-flags		Sort package.* flags by name
 	--sort			Shorthand for --sort-entries and --sort-flags
 	--cleanup		Shorthand for --drop-ineffective and --sort
+
+	--drop-unmatched-pkgs	Drop packages which no longer are available
+				in portdb
 		
 Global actions are applied to the make.conf file. Actions are applied to
 the package.* files, for the packages preceding them.
 				cleanup_actions.add(DropIneffective)
 				cleanup_actions.add(SortEntries)
 				cleanup_actions.add(SortFlags)
+			elif a == '--drop-unmatched-pkgs':
+				cleanup_actions.add(DropUnmatchedPkgs)
 			elif a == '--':
 				argv.remove(a)
 				break
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.