Commits

Michał Górny committed c58ae3c

Make cleanup actions reuse action API.

  • Participants
  • Parent commits 64e7273

Comments (0)

Files changed (2)

lib/flaggie/cleanup.py

 
 from portage.exception import AmbiguousPackageName, InvalidAtom
 
-class BaseCleanupAction(object):
-	def __init__(self, *args):
-		if args:
-			self(*args)
+from flaggie.action import Action
 
-	def __call__(self, pfiles, dbapi):
+class BaseCleanupAction(Action.BaseAction):
+	def __init__(self, dbapi):
 		self._dbapi = dbapi
+
+	def clarify(self, pkgs, cache):
+		if pkgs:
+			raise AssertionError('pkgs not empty in cleanup action')
+		self._cache = cache
+
+	def __call__(self, pkgs, pfiles):
+		if pkgs:
+			raise AssertionError('pkgs not empty in cleanup action')
 		for f in pfiles:
 			self._perform(f)
 

lib/flaggie/cli.py

 		SortEntries, SortFlags
 from flaggie.packagefile import PackageFiles
 
-def parse_actions(args, dbapi, settings, quiet = False, strict = False):
+def parse_actions(args, dbapi, settings, quiet = False, strict = False, \
+		cleanupact = []):
 	out = []
 	cache = Caches(dbapi)
 	actset = ActionSet(cache = cache)
 
 	if actset and (actset.pkgs or not had_pkgs):
 		out.append(actset)
+
+	if cleanupact:
+		actset = ActionSet(cache = cache)
+		for a in cleanupact:
+			actset.append(a(dbapi))
+		out.append(actset)
+
 	return out
 
 def main(argv):
 	porttree = trees[max(trees)]['porttree']
 
 	act = parse_actions(argv[1:], porttree.dbapi, porttree.settings, \
-			quiet = quiet, strict = strict)
+			quiet = quiet, strict = strict, cleanupact = cleanup_actions)
 	if act is None:
 		return 1
-	if not act and not cleanup_actions:
+	if not act:
 		main([argv[0], '--help'])
 		return 0
 
 	pfiles = PackageFiles(os.path.join( \
 		porttree.settings['PORTAGE_CONFIGROOT'], USER_CONFIG_PATH))
+
 	for actset in act:
 		try:
 			actset(pfiles)
 		except NotImplementedError as e:
 			print('Warning: %s' % e)
 
-	for a in cleanup_actions:
-		a(pfiles, porttree.dbapi)
-
 	pfiles.write()
 
 	return 0