Git commit b18f208f316e72dba9951ba8dc3575a5edfe80f4 by Patrick Spendrin. Committed on 31/08/2015 at 22:24. Pushed by sengels into branch 'master'. provide dynamic package options options to enable or disable certain packages from commandline have been added, so that you can now use options.packages.git=3DFalse from kdesettings.ini, environment and commandline. These options can also be queried by calling options.isActive(). Dashes ('-') in package names, will be automagically replaced to an underscore. M +1 -1 bin/EmergeBase.py M +0 -1 bin/EmergeConfig.py M +1 -0 bin/emerge.py M +2 -3 bin/info.py M +61 -43 bin/options.py M +16 -0 bin/portage.py http://commits.kde.org/emerge/b18f208f316e72dba9951ba8dc3575a5edfe80f4 diff --git a/bin/EmergeBase.py b/bin/EmergeBase.py index f972090..81ded87 100644 --- a/bin/EmergeBase.py +++ b/bin/EmergeBase.py @@ -34,7 +34,7 @@ class EmergeBase(object): self.filename, self.category, self.subpackage, self.package, mod = =3D portage.PortageInstance._CURRENT_MODULE#ugly workaround we need to repl= ace the constructor = if not hasattr(self, 'subinfo'): - self.subinfo =3D mod.subinfo(self) + self.subinfo =3D mod.subinfo(self, portage.PortageInstance.opt= ions) = = if not hasattr(self, 'buildSystemType'): diff --git a/bin/EmergeConfig.py b/bin/EmergeConfig.py index 7b631b8..43586fc 100644 --- a/bin/EmergeConfig.py +++ b/bin/EmergeConfig.py @@ -156,7 +156,6 @@ class EmergeConfig( object ): self._readSettings( ) = self.setDefault( "General", "DUMP_SETTINGS", "False" ) - self.setDefault( "General", "EMERGE_OPTIONS", "") self.addAlias( "EmergeDebug", "Verbose", "General", "EMERGE_VERBOS= E" ) self.addAlias( "EmergeDebug", "MeasureTime", "General", "EMERGE_ME= ASURE_TIME" ) self.addAlias( "General", "UseHardlinks", "General", "EMERGE_USE_S= YMLINKS" ) diff --git a/bin/emerge.py b/bin/emerge.py index f748ed9..a38d343 100755 --- a/bin/emerge.py +++ b/bin/emerge.py @@ -377,6 +377,7 @@ def main( ): emergeSettings.set( "General", "EMERGE_TRACE", args.trace ) emergeSettings.set( "General", "EMERGE_PKGPATCHLVL", args.patchlevel ) = + portage.PortageInstance.options =3D args.options if args.search: for package in args.packageNames: category =3D "" diff --git a/bin/info.py b/bin/info.py index 0cdd60c..ce20a4b 100644 --- a/bin/info.py +++ b/bin/info.py @@ -18,12 +18,11 @@ import VersionInfo = class infoclass(object): """this module contains the information class""" - def __init__( self, parent): + def __init__( self, parent, option_string=3DNone): ### package options self.parent =3D parent - self.options =3D Options() + self.options =3D Options(option_string) self.versionInfo =3D VersionInfo.VersionInfo(self) - self.options.readFromEnv() self.targets =3D OrderedDict() self.archiveNames =3D OrderedDict() # Specifiy that the fetched source should be placed into a diff --git a/bin/options.py b/bin/options.py index 6f478a0..92d55b2 100644 --- a/bin/options.py +++ b/bin/options.py @@ -43,6 +43,39 @@ class OptionsBase(object): def __init__(self): pass = +class OptionsPortage(OptionsBase): + def __init__(self): + self._packages =3D dict() + + def __setattr__(self, name, value): + if name =3D=3D "_packages": + object.__setattr__(self, name, value) + else: + self._packages[name] =3D value + + def __getattr__(self, name): + if name in self._packages: + return self._packages[name] + else: + return True + + def getPackageIgnores(self): + """this results in a list, suitable for updating the portage.ignor= es""" + ret =3D [] + for p in self._packages: + _c =3D portage.PortageInstance.getCategory(p) + if not _c: + _c =3D portage.PortageInstance.getCategory(p + "-pkg") + if not _c: + _c =3D portage.PortageInstance.getCategory(p.replace("= _", "-")) + if _c: p =3D p.replace("_", "-") + else: + p +=3D "-pkg" + if not _c: + continue + ret.append("/".join(portage.getFullPackage(p))) + return ret + ## options for enabling or disabling features of KDE ## in the future, a certain set of features make up a 'profile' together class OptionsFeatures(OptionsBase): @@ -207,9 +240,11 @@ class OptionsGit(OptionsBase): = ## main option class class Options(object): - def __init__(self): + def __init__(self, optionslist=3DNone): ## options for the dependency generation self.features =3D OptionsFeatures() + ## options for package exclusion + self.packages =3D OptionsPortage() ## options of the fetch action self.fetch =3D OptionsFetch() ## options of the unpack action @@ -263,60 +298,43 @@ class Options(object): self.buildStatic =3D False = #### end of user configurable part - self.__instances =3D dict() self.__verbose =3D False self.__errors =3D False + self.__readFromList(emergeSettings.get( "General", "EMERGE_OPTIONS= ", "")) + self.readFromEnv() + self.__readFromList(optionslist) + portage.PortageInstance.ignores.update(self.packages.getPackageIgn= ores()) = def readFromEnv( self ): """ read emerge related variables from environment and map them to= public attributes in the option class and sub classes """ - self.__collectAttributes() - self.__readFromList(emergeSettings.get( "General", "EMERGE_OPTIONS= ").split(";")) - = + _o =3D os.getenv("EMERGE_OPTIONS") + if _o: + _o =3D _o.split(" ") + else: + _o =3D [] + self.__readFromList(_o) + def isActive(self, package): return not package in portage.PortageInstance.ignores = - def __collectAttributes( self, instance=3DNone, container=3DNone ): - """ collect all public attributes this class and subclasses - """ - if instance =3D=3D None: instance =3D self - if container =3D=3D None: container =3D self.__instances - # first save instance object - container['.'] =3D [instance, dict()] - - # now check all children - for key, value in inspect.getmembers(instance): - if key.startswith('__') or type(value).__name__.startswith('in= stance'): - continue - if inspect.ismethod(value): - continue - # we have found a child that in itself could have children aga= in - if isinstance(value, OptionsBase): - container[key.lower()] =3D dict() - self.__collectAttributes(value, container[key.lower()]) - else: - # simply append properties here - container['.'][1][key.lower()] =3D [key, value] - - if self.__verbose: - for key in container: - print(container[key]) - def __setInstanceAttribute( self, key, value ): """set attribute in an instance""" - currentObject =3D None + currentObject =3D self currentKey =3D None - currentDict =3D self.__instances - for keyparticle in key.split('.'): - if keyparticle.lower() in currentDict: - #print("found keyparticle as branch", keyparticle) - currentDict =3D currentDict[keyparticle.lower()] - elif keyparticle.lower() in currentDict['.'][1]: - #print("found keyparticle as node", keyparticle) - currentObject =3D currentDict['.'][0] - currentKey =3D currentDict['.'][1][keyparticle.lower()][0] - if not currentObject or not currentKey: - return False + for currentKey in key.split('.'): + if currentKey =3D=3D "options": continue + + if hasattr(currentObject, currentKey): + o =3D getattr(currentObject, currentKey) + if not isinstance(o, OptionsBase): + continue + else: + currentObject =3D o + else: + if isinstance(currentObject, OptionsPortage): + break + return False = # if the type is already bool, we'll keep it that way and interpre= t the string accordingly if type(getattr(currentObject, currentKey)) is bool: diff --git a/bin/portage.py b/bin/portage.py index b3c0189..71ec6e2 100644 --- a/bin/portage.py +++ b/bin/portage.py @@ -156,6 +156,21 @@ def rootDirForPackage( category, package ): PortageCache._rootDirCache[name] =3D os.path.join( EmergeStandardD= irs.emergeRoot(), "emerge", "portage" ) return PortageCache._rootDirCache[name] = +def getFullPackage( package ): + """tries to find a package and returns either category / subpackage / = package or category / package + +returns an empty list if not found +""" + category =3D PortageInstance.getCategory( package ) + if not category: return [] + if package in PortageInstance.subpackages: + _cat, subpackage =3D PortageInstance.subpackages[ package ][0].spl= it('/') + if not _cat =3D=3D category: return [] + return [category, subpackage, package] + else: + return [category, package] + + def getDirname( category, package ): """ return absolute pathname for a given category and package """ subpackage, package =3D getSubPackage( category, package ) @@ -177,6 +192,7 @@ def VCSDirs(): class Portage(object): #cache for pacages _packageDict =3D OrderedDict() + options =3D "" = def __init__( self ): """ """