[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [emerge] bin: provide dynamic package options
From:       Patrick Spendrin <ps_ml () gmx ! de>
Date:       2015-08-31 22:27:47
Message-ID: E1ZWXYJ-0001h1-Fn () scm ! kde ! org
[Download RAW message or body]

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=False 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 = \
portage.PortageInstance._CURRENT_MODULE#ugly workaround we need to replace the \
constructor  
         if not hasattr(self, 'subinfo'):
-            self.subinfo = mod.subinfo(self)
+            self.subinfo = mod.subinfo(self, portage.PortageInstance.options)
 
 
         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_VERBOSE" )
         self.addAlias( "EmergeDebug", "MeasureTime", "General", \
                "EMERGE_MEASURE_TIME" )
         self.addAlias( "General", "UseHardlinks", "General", "EMERGE_USE_SYMLINKS" )
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 = args.options
     if args.search:
         for package in args.packageNames:
             category = ""
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=None):
         ### package options
         self.parent = parent
-        self.options = Options()
+        self.options = Options(option_string)
         self.versionInfo = VersionInfo.VersionInfo(self)
-        self.options.readFromEnv()
         self.targets = OrderedDict()
         self.archiveNames = 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 = dict()
+
+    def __setattr__(self, name, value):
+        if name == "_packages":
+            object.__setattr__(self, name, value)
+        else:
+            self._packages[name] = 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.ignores"""
+        ret = []
+        for p in self._packages:
+            _c = portage.PortageInstance.getCategory(p)
+            if not _c:
+                _c = portage.PortageInstance.getCategory(p + "-pkg")
+                if not _c:
+                    _c = portage.PortageInstance.getCategory(p.replace("_", "-"))
+                    if _c: p = p.replace("_", "-")
+                else:
+                    p += "-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=None):
         ## options for the dependency generation
         self.features = OptionsFeatures()
+        ## options for package exclusion
+        self.packages = OptionsPortage()
         ## options of the fetch action
         self.fetch = OptionsFetch()
         ## options of the unpack action
@@ -263,60 +298,43 @@ class Options(object):
         self.buildStatic = False
 
         #### end of user configurable part
-        self.__instances = dict()
         self.__verbose = False
         self.__errors = False
+        self.__readFromList(emergeSettings.get( "General", "EMERGE_OPTIONS", ""))
+        self.readFromEnv()
+        self.__readFromList(optionslist)
+        portage.PortageInstance.ignores.update(self.packages.getPackageIgnores())
 
     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 = os.getenv("EMERGE_OPTIONS")
+        if _o:
+            _o = _o.split(" ")
+        else:
+            _o = []
+        self.__readFromList(_o)
+
     def isActive(self, package):
         return not package in portage.PortageInstance.ignores
 
-    def __collectAttributes( self, instance=None, container=None ):
-        """ collect all public attributes this class and subclasses
-        """
-        if instance == None: instance = self
-        if container == None: container = self.__instances
-        # first save instance object
-        container['.'] = [instance, dict()]
-
-        # now check all children
-        for key, value in inspect.getmembers(instance):
-            if key.startswith('__') or type(value).__name__.startswith('instance'):
-                continue
-            if inspect.ismethod(value):
-                continue
-            # we have found a child that in itself could have children again
-            if isinstance(value, OptionsBase):
-                container[key.lower()] = dict()
-                self.__collectAttributes(value, container[key.lower()])
-            else:
-                # simply append properties here
-                container['.'][1][key.lower()] = [key, value]
-
-        if self.__verbose:
-            for key in container:
-                print(container[key])
-
     def __setInstanceAttribute( self, key, value ):
         """set attribute in an instance"""
-        currentObject = None
+        currentObject = self
         currentKey = None
-        currentDict = self.__instances
-        for keyparticle in key.split('.'):
-            if keyparticle.lower() in currentDict:
-                #print("found keyparticle as branch", keyparticle)
-                currentDict = currentDict[keyparticle.lower()]
-            elif keyparticle.lower() in currentDict['.'][1]:
-                #print("found keyparticle as node", keyparticle)
-                currentObject = currentDict['.'][0]
-                currentKey = currentDict['.'][1][keyparticle.lower()][0]
-        if not currentObject or not currentKey:
-            return False
+        for currentKey in key.split('.'):
+            if currentKey == "options": continue
+
+            if hasattr(currentObject, currentKey):
+                o = getattr(currentObject, currentKey)
+                if not isinstance(o, OptionsBase):
+                    continue
+                else:
+                    currentObject = o
+            else:
+                if isinstance(currentObject, OptionsPortage):
+                    break
+                return False
 
         # if the type is already bool, we'll keep it that way and interpret 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] = os.path.join( \
EmergeStandardDirs.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 = PortageInstance.getCategory( package )
+    if not category: return []
+    if package in PortageInstance.subpackages:
+        _cat, subpackage = PortageInstance.subpackages[ package ][0].split('/')
+        if not _cat == 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 = getSubPackage( category, package )
@@ -177,6 +192,7 @@ def VCSDirs():
 class Portage(object):
     #cache for pacages
     _packageDict = OrderedDict()
+    options = ""
 
     def __init__( self ):
         """ """


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic