Commits

Michał Górny committed 0d45aad

Support assigning a MakeConfVariable instance to a PackageFileSet.

This is a new API for global action support. One does assign
a MakeConfVariable instance to PackageFileSet.makeconfvar, and then
calling PackageFileSet[None] returns the MakeConfVariable instance.

  • Participants
  • Parent commits ef62275

Comments (0)

Files changed (2)

lib/flaggie/cli.py

 		main([argv[0], '--help'])
 		return 0
 
-	pfiles = PackageFiles(os.path.join( \
-		porttree.settings['PORTAGE_CONFIGROOT'], USER_CONFIG_PATH), porttree)
 	mkconf = MakeConf(os.path.join( \
 		porttree.settings['PORTAGE_CONFIGROOT'], MAKE_CONF_FILE), porttree)
+	pfiles = PackageFiles(os.path.join( \
+		porttree.settings['PORTAGE_CONFIGROOT'], USER_CONFIG_PATH), porttree,
+		mkconf)
 
 	for actset in act:
 		try:

lib/flaggie/packagefile.py

 	def __getitem__(self, pkg):
 		""" Get package entries for a package in order of effectiveness
 			(the last declarations in the file are effective, and those
-			will be returned first). """
+			will be returned first).
+			
+			If pkg is None and PackageFileSet has self.makeconfvar set,
+			calling self[None] will return the MakeConfVariable instance.
+		"""
+
+		if pkg is None:
+			if self.makeconfvar is not None:
+				yield self.makeconfvar
+			else:
+				raise KeyError('PackageFileSet[None] requested but no MakeConf assigned.')
+			return
+
 		for e in self:
 			if pkg == e.package:
 				yield e
 				f.remove(e)
 			f.modified = True
 
+	makeconfvar = None
+
 class PackageKeywordsFileSet(PackageFileSet):
 	def __init__(self, path, dbapi):
 		PackageFileSet.__init__(self, path)
 		PackageFileSet.write(*((self,) + args))
 
 class PackageFiles(object):
-	def __init__(self, basedir, dbapi):
+	def __init__(self, basedir, dbapi, mkconf = None):
 		p = lambda x: os.path.join(basedir, x)
 
 		pkw = [p('package.keywords')]
 			'env': PackageFileSet(p('package.env'))
 		}
 
+		if mkconf:
+			for k, f in self.files.items():
+				f.makeconfvar = mkconf[k]
+
 	def __getitem__(self, k):
 		return self.files[k]