Commits

Michał Górny committed 8cf678c

Support migrating package.keywords through --migrate-files.

If a particular PackageFileSet is passed multiple paths, --migrate-files
can be used to move all entries to the first file belonging to the final
path. In other words, it migrates entries from package.keywords to
package.accept_keywords.

Comments (0)

Files changed (3)

lib/flaggie/cleanup.py

 		for pe in f:
 			pe.sort()
 
-cleanupact_order = (DropUnmatchedPkgs, DropUnmatchedFlags, DropIneffective, \
-		SortEntries, SortFlags)
+class MigrateFiles(BaseCleanupAction):
+	def _perform(self, f):
+		f.migrate()
+
+cleanupact_order = (MigrateFiles, DropUnmatchedPkgs, DropUnmatchedFlags, \
+		DropIneffective, SortEntries, SortFlags)
 from flaggie.action import Action, ActionSet, ParserError, ParserWarning
 from flaggie.cache import Caches
 from flaggie.cleanup import DropIneffective, DropUnmatchedPkgs, \
-		DropUnmatchedFlags, SortEntries, SortFlags
+		DropUnmatchedFlags, SortEntries, SortFlags, MigrateFiles
 from flaggie.packagefile import PackageFiles
 
 def parse_actions(args, dbapi, settings, quiet = False, strict = False, \
 	--drop-unmatched-flags	Drop flags which are not found in package's
 				IUSE, KEYWORDS and/or LICENSE variables
 	--destructive-cleanup	Shorthand for all of the above
+
+	--migrate-files		Migrate the outdated files to newer variants
+				(package.keywords -> package.accept_keywords)
 		
 Global actions are applied to the make.conf file. Actions are applied to
 the package.* files, for the packages preceding them.
 				cleanup_actions.add(SortFlags)
 				cleanup_actions.add(DropUnmatchedPkgs)
 				cleanup_actions.add(DropUnmatchedFlags)
+			elif a == '--migrate-files':
+				cleanup_actions.add(MigrateFiles)
 			elif a == '--':
 				argv.remove(a)
 				break

lib/flaggie/packagefile.py

 			self.read()
 		return self._files
 
+	def migrate(self):
+		paths = self._paths
+		if len(paths) <= 1:
+			return
+
+		lp = paths[-1]
+		for f in self.files:
+			if f.path == lp or os.path.dirname(f.path) == lp:
+				lf = f
+				break
+		else:
+			raise AssertionError('Final file not found while trying to migrate.')
+
+		for p in paths[:-1]:
+			for f in self.files:
+				if f.path == p or os.path.dirname(f.path) == p:
+					lf[0:0] = f
+					del f[:]
+					f.modified = True
+
+		lf.modified = True
+
 	def read(self):
 		if self._files:
 			return