Commits

Michał Górny  committed 683ede1

--drop-unmatched-flags should not touch unmatched packages.

In order to avoid mistakes (and implicit actions), make
--drop-unmatched-flags no longer remove flags for packages which
do not have a match in portdb.

  • Participants
  • Parent commits bc56ff6

Comments (0)

Files changed (3)

 - `--drop-unmatched-flags` to remove all flags, keywords and licenses
 	which do not match the package metadata (`IUSE`, `KEYWORDS`
 	and `LICENSE` keys respectively). In other words, this should remove
-	outdated flags.
+	outdated flags. Please note that, in order to avoid mistakes, this
+	action won't remove flags for packages which do not have a match
+	in portdb (`--drop-unmatched-pkgs` is useful for that).
 
 In addition to the actual cleanup actions, a set of shorthand options is
 available too:

File lib/flaggie/cleanup.py

 		if pkgs:
 			raise AssertionError('pkgs not empty in cleanup action')
 		
+		dbcache = {}
+
 		for k, f in pfiles.files.items():
 			cache = self._cache[k]
 			for pe in f:
-				flags = cache[pe.package]
-				for flag in set([x.name for x in pe]):
-					if k == 'kw' and flag == '**':
-						pass
-					elif flag not in flags:
-						del pe[flag]
+				if pe.package not in dbcache:
+					try:
+						dbcache[pe.package] = bool(self._dbapi.xmatch('match-all', pe.package))
+					except (InvalidAtom, AmbiguousPackageName):
+						dbcache[pe.package] = False
+
+				if dbcache[pe.package]:
+					flags = cache[pe.package]
+					for flag in set([x.name for x in pe]):
+						if k == 'kw' and flag == '**':
+							pass
+						elif flag not in flags:
+							del pe[flag]
 
 class DropUnmatchedPkgs(BaseCleanupAction):
 	def _perform(self, f):

File lib/flaggie/cli.py

 				cleanup_actions.add(DropIneffective)
 				cleanup_actions.add(SortEntries)
 				cleanup_actions.add(SortFlags)
-				# DropUnmatchedPkgs is implicit here
+				cleanup_actions.add(DropUnmatchedPkgs)
 				cleanup_actions.add(DropUnmatchedFlags)
 			elif a == '--':
 				argv.remove(a)