Sync with genscripts rev 422, includes fixes to eclean and python additions for prefix
authorfuzzyray <fuzzyray@gentoo.org>
Thu, 8 Apr 2010 21:13:07 +0000 (21:13 -0000)
committerfuzzyray <fuzzyray@gentoo.org>
Thu, 8 Apr 2010 21:13:07 +0000 (21:13 -0000)
svn path=/trunk/gentoolkit/; revision=768

12 files changed:
pym/gentoolkit/analyse/analyse.py
pym/gentoolkit/analyse/lib.py
pym/gentoolkit/dependencies.py
pym/gentoolkit/eclean/cli.py
pym/gentoolkit/eclean/exclude.py
pym/gentoolkit/eprefix.py [new file with mode: 0644]
pym/gentoolkit/equery/uses.py
pym/gentoolkit/flag.py [new file with mode: 0644]
pym/gentoolkit/keyword.py
pym/gentoolkit/package.py
pym/gentoolkit/test/eclean/distfiles.exclude [new file with mode: 0644]
setup.py

index 21623242cb55135811656756f41126796ac58069..f14aff5daf98ec51c44c94b58dc8bb096fc5dfd5 100644 (file)
@@ -16,8 +16,8 @@ import gentoolkit
 from gentoolkit.dbapi import PORTDB, VARDB
 from gentoolkit.analyse.base import ModuleBase
 from gentoolkit import pprinter as pp
-from gentoolkit.analyse.lib import (get_installed_use,  get_iuse, abs_flag,
-       abs_list, get_all_cpv_use, get_flags, FlagAnalyzer, KeywordAnalyser)
+from gentoolkit.flag import get_installed_use, get_flags
+from gentoolkit.analyse.lib import FlagAnalyzer, KeywordAnalyser
 from gentoolkit.analyse.output import nl, AnalysisPrinter
 from gentoolkit.package import Package
 from gentoolkit.helpers import get_installed_cpvs
index a32d13b867ad38625714967570c7e3aa99c8fa1d..3f383a80cbb549624e3c07d78af12fed4068d1eb 100644 (file)
@@ -12,148 +12,14 @@ import sys
 
 from gentoolkit.dbapi import PORTDB, VARDB
 from gentoolkit import errors
-from gentoolkit.keyword import abs_keywords
+from gentoolkit.keyword import reduce_keywords
+from gentoolkit.flag import (reduce_flags, get_flags, get_all_cpv_use,
+    filter_flags, get_installed_use, get_iuse)
 #from gentoolkit.package import Package
 
 import portage
 
 
-def get_installed_use(cpv, use="USE"):
-       """Gets the installed USE flags from the VARDB
-
-       @type: cpv: string
-       @param cpv: cat/pkg-ver
-       @type use: string
-       @param use: 1 of ["USE", "PKGUSE"]
-       @rtype list
-       @returns [] or the list of IUSE flags
-       """
-       return VARDB.aux_get(cpv,[use])[0].split()
-
-
-def get_iuse(cpv):
-       """Gets the current IUSE flags from the tree
-
-       @type: cpv: string
-       @param cpv: cat/pkg-ver
-       @rtype list
-       @returns [] or the list of IUSE flags
-       """
-       try:
-               return PORTDB.aux_get(cpv, ["IUSE"])[0].split()
-       except:
-               return []
-
-
-def abs_flag(flag):
-       """Absolute value function for a USE flag
-
-       @type flag: string
-       @param flag: the use flag to absolute.
-       @rtype: string
-       @return absolute USE flag
-       """
-       if flag[0] in ["+","-"]:
-               return flag[1:]
-       else:
-               return flag
-
-
-def abs_list(the_list):
-       """Absolute value function for a USE flag list
-
-       @type the_list: list
-       @param the_list: the use flags to absolute.
-       @rtype: list
-       @return absolute USE flags
-       """
-       r=[]
-       for member in the_list:
-               r.append(abs_flag(member))
-       return r
-
-
-def filter_flags(use, use_expand_hidden, usemasked, useforced):
-       """Filter function to remove hidden or otherwise not normally
-       visible USE flags from a list.
-
-       @type use: list
-       @param use: the USE flag list to be filtered.
-       @type use_expand_hidden: list
-       @param  use_expand_hidden: list of flags hidden.
-       @type usemasked: list
-       @param usemasked: list of masked USE flags.
-       @type useforced: list
-       @param useforced: the forced USE flags.
-       @rtype: list
-       @return the filtered USE flags.
-       """
-       # clean out some environment flags, since they will most probably
-       # be confusing for the user
-       for f in use_expand_hidden:
-               f=f.lower() + "_"
-               for x in use:
-                       if f in x:
-                               use.remove(x)
-       # clean out any arch's
-       archlist = portage.settings["PORTAGE_ARCHLIST"].split()
-       for a in use[:]:
-               if a in archlist:
-                       use.remove(a)
-       # dbl check if any from usemasked  or useforced are still there
-       masked = usemasked + useforced
-       for a in use[:]:
-               if a in masked:
-                       use.remove(a)
-       return use
-
-
-def get_all_cpv_use(cpv):
-       """Uses portage to determine final USE flags and settings for an emerge
-
-       @type cpv: string
-       @param cpv: eg cat/pkg-ver
-       @rtype: lists
-       @return  use, use_expand_hidden, usemask, useforce
-       """
-       use = None
-       PORTDB.settings.unlock()
-       try:
-               PORTDB.settings.setcpv(cpv, use_cache=True, mydb=portage.portdb)
-               use = portage.settings['PORTAGE_USE'].split()
-               use_expand_hidden = portage.settings["USE_EXPAND_HIDDEN"].split()
-               usemask = list(PORTDB.settings.usemask)
-               useforce =  list(PORTDB.settings.useforce)
-       except KeyError:
-               PORTDB.settings.reset()
-               PORTDB.settings.lock()
-               return [], [], [], []
-       # reset cpv filter
-       PORTDB.settings.reset()
-       PORTDB.settings.lock()
-       return use, use_expand_hidden, usemask, useforce
-
-
-def get_flags(cpv, final_setting=False):
-       """Retrieves all information needed to filter out hidded, masked, etc.
-       USE flags for a given package.
-
-       @type cpv: string
-       @param cpv: eg. cat/pkg-ver
-       @type final_setting: boolean
-       @param final_setting: used to also determine the final
-               enviroment USE flag settings and return them as well.
-       @rtype: list or list, list
-       @return IUSE or IUSE, final_flags
-       """
-       final_use, use_expand_hidden, usemasked, useforced = get_all_cpv_use(cpv)
-       iuse_flags = filter_flags(get_iuse(cpv), use_expand_hidden, usemasked, useforced)
-       #flags = filter_flags(use_flags, use_expand_hidden, usemasked, useforced)
-       if final_setting:
-               final_flags = filter_flags(final_use,  use_expand_hidden, usemasked, useforced)
-               return iuse_flags, final_flags
-       return iuse_flags
-
 class FlagAnalyzer(object):
        """Specialty functions for analysing an installed package's
        USE flags.  Can be used for single or mulitple use without
@@ -199,7 +65,7 @@ class FlagAnalyzer(object):
                @return (plus, minus, unset) sets of USE flags
                """
                installed = set(self.get_used(cpv, self.target))
-               iuse =  set(abs_list(self.get_flags(cpv)))
+               iuse =  set(reduce_flags(self.get_flags(cpv)))
                return self._analyse(installed, iuse)
 
        def _analyse(self, installed, iuse):
@@ -232,7 +98,7 @@ class FlagAnalyzer(object):
                @return (plus, minus, unset) sets of USE flags
                """
                installed = set(self.pkg_used(pkg))
-               iuse =  set(abs_list(self.pkg_flags(pkg)))
+               iuse =  set(reduce_flags(self.pkg_flags(pkg)))
                return self._analyse(installed, iuse)
 
        def pkg_used(self, pkg):
@@ -323,13 +189,13 @@ class KeywordAnalyser(object):
                kwd = None
                result = ''
                if keywords:
-                       absolute_kwds = abs_keywords(keywords)
+                       absolute_kwds = reduce_keywords(keywords)
                        kwd = list(used.intersection(absolute_kwds))
                        #if keywords == ['~ppc64']:
                                #print "Checked keywords for kwd", keywords, used, "kwd =", kwd
                if not kwd:
                        #print "Checking for kwd against portage.archlist"
-                       absolute_kwds = abs_keywords(keywords)
+                       absolute_kwds = reduce_keywords(keywords)
                        # check for one against archlist then re-check
                        kwd = list(absolute_kwds.intersection(portage.archlist))
                        #print "determined keyword =", kwd
index fda28f7593dda51011327fb1d9a1bafe0584674f..f12500622e0c3e4f7b3e90d7b588bf8950d5a8f1 100644 (file)
@@ -77,7 +77,10 @@ class Dependencies(CPV):
                try:
                        result = PORTDB.aux_get(self.cpv, envvars)
                except KeyError:
-                       result = VARDB.aux_get(self.cpv, envvars)
+                       try:
+                               result = VARDB.aux_get(self.cpv, envvars)
+                       except KeyError:
+                               return []
                return result
 
        def get_depend(self):
index 90eff68ad761ec6708302d824cd45276b623c1a1..ddfaaba621c79ac6e88fb6f129379bbd12a2ed81 100644 (file)
@@ -33,6 +33,7 @@ from gentoolkit.eclean.exclude import (parseExcludeFile,
 from gentoolkit.eclean.clean import CleanUp
 from gentoolkit.eclean.output import OutputControl
 #from gentoolkit.eclean.dbapi import Dbapi
+from gentoolkit.eprefix import EPREFIX
 
 def printVersion():
        """Output the version info."""
@@ -253,6 +254,7 @@ def parseArgs(options={}):
                        elif o in ("-t", "--time-limit"):
                                options['time-limit'] = parseTime(a)
                        elif o in ("-e", "--exclude-file"):
+                               print("cli --exclude option")
                                options['exclude-file'] = a
                        elif o in ("-n", "--package-names"):
                                options['package-names'] = True
@@ -463,6 +465,14 @@ def main():
                if options['verbose']:
                        options['verbose-output'] = output.einfo
        # parse the exclusion file
+       #print("MAIN(), CHecking exclude-file")
+       if not 'exclude-file' in options:
+               # set it to the default exclude file if it exists
+               exclude_file = "%s/etc/%s/%s.exclude" % (EPREFIX,__productname__ , action)
+               #print("MAIN(), EXCLUDE FILE name=", exclude_file)
+               if os.path.isfile(exclude_file):
+                       #print("MAIN(), setting default exclude-file")
+                       options['exclude-file'] = exclude_file
        if 'exclude-file' in options:
                try:
                        exclude = parseExcludeFile(options['exclude-file'],
@@ -475,10 +485,7 @@ def main():
                                "See format of this file in `man %s`" % __productname__), file=sys.stderr)
                        sys.exit(1)
        else:
-               exclude_file = "/etc/%s/%s.exclude" % (__productname__ , action)
-               if os.path.isfile(exclude_file):
-                       options['exclude-file'] = exclude_file
-               exclude={}
+                       exclude = {}
        # security check for non-pretend mode
        if not options['pretend'] and portage.secpass == 0:
                print( pp.error(
index 6ffa0c6b347d68c8f98484e459170cb0b96cb0a1..62bfed1edcd8c058465ada91693ce53d66693e88 100644 (file)
@@ -223,6 +223,7 @@ def exclDictExpandPkgname(exclude):
                        pkgname = cp.split('/')[1]
                        p.add(pkgname)
        if 'packages' in exclude:
+               for cp in exclude['packages']:
                        pkgname = cp.split('/')[1]
                        p.add(pkgname)
        if 'anti-packages' in exclude:
diff --git a/pym/gentoolkit/eprefix.py b/pym/gentoolkit/eprefix.py
new file mode 100644 (file)
index 0000000..9a04e4b
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/python
+
+# Copyright 2003-2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+
+#from __future__ import print_function
+
+"""Eprefix support module to set the EPREFIX variable
+used in all gentoolkit modules
+
+Example useage:  from gentoolkit.eprefix import EPREFIX
+then in code add it to the filepath eg.:  
+       exclude_file = "%s/etc/%s/%s.exclude" % (EPREFIX,__productname__ , action)
+
+"""
+
+import os
+
+
+EPREFIX = ''
+
+# the following code is used to set it when
+# non-installed code is being run
+if 'EPREFIX' in os.environ:
+       EPREFIX = os.environ['EPREFIX']
+else:
+       try:
+               import portage.const
+               EPREFIX = portage.BPREFIX
+       except AttributeError:
+               EPREFIX = ''
+
+#print("EPREFIX set to:", EPREFIX)
index 4eba5009c4986aafcea9583fcb64c195c0cad861..08ff585c3c8385a234048b82f0241ba214377a30 100644 (file)
@@ -28,6 +28,7 @@ from gentoolkit.equery import format_options, mod_usage, CONFIG
 from gentoolkit.helpers import uniqify
 from gentoolkit.textwrap_ import TextWrapper
 from gentoolkit.query import Query
+from gentoolkit.flag import get_flags, reduce_flags
 
 # =======
 # Globals
@@ -172,13 +173,11 @@ def get_output_descriptions(pkg, global_usedesc):
                local_usedesc = []
        else:
                local_usedesc = pkg.metadata.use()
-       iuse = pkg.environment("IUSE")
 
-       if iuse:
-               usevar = uniqify([x.lstrip('+-') for x in iuse.split()])
-               usevar.sort()
-       else:
-               usevar = []
+       iuse, final_use = get_flags(pkg.cpv, final_setting=True)
+       usevar = reduce_flags(iuse)
+       usevar.sort()
+       
 
        if pkg.is_installed():
                used_flags = pkg.use().split()
@@ -211,7 +210,7 @@ def get_output_descriptions(pkg, global_usedesc):
                except AttributeError:
                        restrict = ""
 
-               if flag in pkg.settings("USE").split():
+               if flag in final_use:
                        inuse = True
                if flag in used_flags:
                        inused = True
@@ -236,9 +235,9 @@ def parse_module_options(module_opts):
 def print_legend():
        """Print a legend to explain the output format."""
 
-       print("[ Legend : %s - flag is set in make.conf       ]" % pp.emph("U"))
-       print("[        : %s - package is installed with flag ]" % pp.emph("I"))
-       print("[ Colors : %s, %s                         ]" % (
+       print("[ Legend : %s - final flag setting for installation]" % pp.emph("U"))
+       print("[        : %s - package is installed with flag     ]" % pp.emph("I"))
+       print("[ Colors : %s, %s                             ]" % (
                pp.useflag("set", enabled=True), pp.useflag("unset", enabled=False)))
 
 
diff --git a/pym/gentoolkit/flag.py b/pym/gentoolkit/flag.py
new file mode 100644 (file)
index 0000000..8a16110
--- /dev/null
@@ -0,0 +1,165 @@
+#!/usr/bin/python
+#
+# Copyright(c) 2010, Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+#
+
+
+"""Provides support functions for USE flag settings and analysis"""
+
+
+__all__ = (
+       'get)iuse',
+       'get_installed_use',
+       'reduce_flag',
+       'reduce_flags',
+       'filter_flags',
+       'get_all_cpv_use',
+       'get_flags'
+)
+
+
+import sys
+
+from gentoolkit.dbapi import PORTDB, VARDB
+
+import portage
+
+
+def get_iuse(cpv):
+       """Gets the current IUSE flags from the tree
+
+       To be used when a gentoolkit package object is not needed
+       @type: cpv: string
+       @param cpv: cat/pkg-ver
+       @rtype list
+       @returns [] or the list of IUSE flags
+       """
+       try:
+               return PORTDB.aux_get(cpv, ["IUSE"])[0].split()
+       except:
+               return []
+
+
+def get_installed_use(cpv, use="USE"):
+       """Gets the installed USE flags from the VARDB
+
+       To be used when a gentoolkit package object is not needed
+       @type: cpv: string
+       @param cpv: cat/pkg-ver
+       @type use: string
+       @param use: 1 of ["USE", "PKGUSE"]
+       @rtype list
+       @returns [] or the list of IUSE flags
+       """
+       return VARDB.aux_get(cpv,[use])[0].split()
+
+
+def reduce_flag(flag):
+       """Absolute value function for a USE flag
+
+       @type flag: string
+       @param flag: the use flag to absolute.
+       @rtype: string
+       @return absolute USE flag
+       """
+       if flag[0] in ["+","-"]:
+               return flag[1:]
+       else:
+               return flag
+
+
+def reduce_flags(the_list):
+       """Absolute value function for a USE flag list
+
+       @type the_list: list
+       @param the_list: the use flags to absolute.
+       @rtype: list
+       @return absolute USE flags
+       """
+       r=[]
+       for member in the_list:
+               r.append(reduce_flag(member))
+       return r
+
+
+def filter_flags(use, use_expand_hidden, usemasked, useforced):
+       """Filter function to remove hidden or otherwise not normally
+       visible USE flags from a list.
+
+       @type use: list
+       @param use: the USE flag list to be filtered.
+       @type use_expand_hidden: list
+       @param  use_expand_hidden: list of flags hidden.
+       @type usemasked: list
+       @param usemasked: list of masked USE flags.
+       @type useforced: list
+       @param useforced: the forced USE flags.
+       @rtype: list
+       @return the filtered USE flags.
+       """
+       # clean out some environment flags, since they will most probably
+       # be confusing for the user
+       for f in use_expand_hidden:
+               f=f.lower() + "_"
+               for x in use:
+                       if f in x:
+                               use.remove(x)
+       # clean out any arch's
+       archlist = portage.settings["PORTAGE_ARCHLIST"].split()
+       for a in use[:]:
+               if a in archlist:
+                       use.remove(a)
+       # dbl check if any from usemasked  or useforced are still there
+       masked = usemasked + useforced
+       for a in use[:]:
+               if a in masked:
+                       use.remove(a)
+       return use
+
+
+def get_all_cpv_use(cpv):
+       """Uses portage to determine final USE flags and settings for an emerge
+
+       @type cpv: string
+       @param cpv: eg cat/pkg-ver
+       @rtype: lists
+       @return  use, use_expand_hidden, usemask, useforce
+       """
+       use = None
+       PORTDB.settings.unlock()
+       try:
+               PORTDB.settings.setcpv(cpv, use_cache=True, mydb=portage.portdb)
+               use = portage.settings['PORTAGE_USE'].split()
+               use_expand_hidden = portage.settings["USE_EXPAND_HIDDEN"].split()
+               usemask = list(PORTDB.settings.usemask)
+               useforce =  list(PORTDB.settings.useforce)
+       except KeyError:
+               PORTDB.settings.reset()
+               PORTDB.settings.lock()
+               return [], [], [], []
+       # reset cpv filter
+       PORTDB.settings.reset()
+       PORTDB.settings.lock()
+       return use, use_expand_hidden, usemask, useforce
+
+
+def get_flags(cpv, final_setting=False):
+       """Retrieves all information needed to filter out hidded, masked, etc.
+       USE flags for a given package.
+
+       @type cpv: string
+       @param cpv: eg. cat/pkg-ver
+       @type final_setting: boolean
+       @param final_setting: used to also determine the final
+               enviroment USE flag settings and return them as well.
+       @rtype: list or list, list
+       @return IUSE or IUSE, final_flags
+       """
+       final_use, use_expand_hidden, usemasked, useforced = get_all_cpv_use(cpv)
+       iuse_flags = filter_flags(get_iuse(cpv), use_expand_hidden, usemasked, useforced)
+       #flags = filter_flags(use_flags, use_expand_hidden, usemasked, useforced)
+       if final_setting:
+               final_flags = filter_flags(final_use,  use_expand_hidden, usemasked, useforced)
+               return iuse_flags, final_flags
+       return iuse_flags
index 3260bf060063e2d73ca3cf093f7bc3573e8f5e2f..217a3961901476d8ba7ab8a8eb78b88bb3c63293 100644 (file)
@@ -13,7 +13,9 @@ http://www.gentoo.org/proj/en/glep/glep-0053.html
 
 __all__ = (
        'Keyword',
-       'compare_strs'
+       'compare_strs',
+       'reduce_keywords',
+       'determine_keywords'
 )
 
 # =======
index 169097f59182d41a3e1728cd81bc7415e72a2503..e88160f62c26428e83300749df36d4fd0dfaa7ef 100644 (file)
@@ -55,6 +55,7 @@ from gentoolkit import errors
 from gentoolkit.cpv import CPV
 from gentoolkit.dbapi import PORTDB, VARDB
 from gentoolkit.keyword import determine_keyword
+from gentoolkit.flag import get_flags
 
 # =======
 # Classes
@@ -315,6 +316,12 @@ class Package(CPV):
 
                return self.dblink.getstring("USE")
 
+       def use_status(self):
+               """Returns the USE flags active for installation."""
+
+               iuse, final_flags = get_flags(slef.cpv, final_setting=True)
+               return final_flags
+
        def parsed_contents(self):
                """Returns the parsed CONTENTS file.
 
diff --git a/pym/gentoolkit/test/eclean/distfiles.exclude b/pym/gentoolkit/test/eclean/distfiles.exclude
new file mode 100644 (file)
index 0000000..700c1bb
--- /dev/null
@@ -0,0 +1,11 @@
+# test exclude file
+
+app-portage
+
+media-libs/sdl-pango
+
+sys-auth/consolekit-0.4.1
+
+!app-emulation/emul-linux-x86-baselibs
+
+help2man-1.37.1.tar.gz
index dc840377b1c4f4a6d35b45424ddd65e6f5d7c62f..0bd2dd10062ea60a5a852daeb8a3d36e3ce67c5a 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -17,6 +17,13 @@ __version__ = os.getenv('VERSION', default='9999')
 
 cwd = os.getcwd()
 
+# Load EPREFIX from Portage, fall back to the empty string if it fails 
+       try: 
+               from portage.const import EPREFIX 
+       except AttributeError: 
+               EPREFIX='' 
+
+
 # Bash files that need `VERSION=""` subbed, relative to this dir:
 bash_scripts = [os.path.join(cwd, path) for path in (
        'bin/euse',
@@ -109,10 +116,10 @@ core.setup(
        packages=packages,
        scripts=(glob('bin/*')),
        data_files=(
-               ('/etc/env.d', ['data/99gentoolkit-env']),
-               ('/etc/revdep-rebuild', ['data/revdep-rebuild/99revdep-rebuild']),
-               ('/etc/eclean', glob('data/eclean/*')),
-               ('/usr/share/man/man1', glob('man/*'))
+               (EPREFIX + '/etc/env.d', ['data/99gentoolkit-env']),
+               (EPREFIX + '/etc/revdep-rebuild', ['data/revdep-rebuild/99revdep-rebuild']),
+               (EPREFIX + '/etc/eclean', glob('data/eclean/*')),
+               (EPREFIX + '/usr/share/man/man1', glob('man/*'))
        ),
        cmdclass={
                'test': load_test(),