From: fuzzyray Date: Thu, 8 Apr 2010 21:13:07 +0000 (-0000) Subject: Sync with genscripts rev 422, includes fixes to eclean and python additions for prefix X-Git-Tag: gentoolkit-0.3.0_rc11~45 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f146d54860527cf1cfe8010d09730fd0a20fc690;p=gentoolkit.git Sync with genscripts rev 422, includes fixes to eclean and python additions for prefix svn path=/trunk/gentoolkit/; revision=768 --- diff --git a/pym/gentoolkit/analyse/analyse.py b/pym/gentoolkit/analyse/analyse.py index 2162324..f14aff5 100644 --- a/pym/gentoolkit/analyse/analyse.py +++ b/pym/gentoolkit/analyse/analyse.py @@ -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 diff --git a/pym/gentoolkit/analyse/lib.py b/pym/gentoolkit/analyse/lib.py index a32d13b..3f383a8 100644 --- a/pym/gentoolkit/analyse/lib.py +++ b/pym/gentoolkit/analyse/lib.py @@ -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 diff --git a/pym/gentoolkit/dependencies.py b/pym/gentoolkit/dependencies.py index fda28f7..f125006 100644 --- a/pym/gentoolkit/dependencies.py +++ b/pym/gentoolkit/dependencies.py @@ -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): diff --git a/pym/gentoolkit/eclean/cli.py b/pym/gentoolkit/eclean/cli.py index 90eff68..ddfaaba 100644 --- a/pym/gentoolkit/eclean/cli.py +++ b/pym/gentoolkit/eclean/cli.py @@ -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( diff --git a/pym/gentoolkit/eclean/exclude.py b/pym/gentoolkit/eclean/exclude.py index 6ffa0c6..62bfed1 100644 --- a/pym/gentoolkit/eclean/exclude.py +++ b/pym/gentoolkit/eclean/exclude.py @@ -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 index 0000000..9a04e4b --- /dev/null +++ b/pym/gentoolkit/eprefix.py @@ -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) diff --git a/pym/gentoolkit/equery/uses.py b/pym/gentoolkit/equery/uses.py index 4eba500..08ff585 100644 --- a/pym/gentoolkit/equery/uses.py +++ b/pym/gentoolkit/equery/uses.py @@ -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 index 0000000..8a16110 --- /dev/null +++ b/pym/gentoolkit/flag.py @@ -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 diff --git a/pym/gentoolkit/keyword.py b/pym/gentoolkit/keyword.py index 3260bf0..217a396 100644 --- a/pym/gentoolkit/keyword.py +++ b/pym/gentoolkit/keyword.py @@ -13,7 +13,9 @@ http://www.gentoo.org/proj/en/glep/glep-0053.html __all__ = ( 'Keyword', - 'compare_strs' + 'compare_strs', + 'reduce_keywords', + 'determine_keywords' ) # ======= diff --git a/pym/gentoolkit/package.py b/pym/gentoolkit/package.py index 169097f..e88160f 100644 --- a/pym/gentoolkit/package.py +++ b/pym/gentoolkit/package.py @@ -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 index 0000000..700c1bb --- /dev/null +++ b/pym/gentoolkit/test/eclean/distfiles.exclude @@ -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 diff --git a/setup.py b/setup.py index dc84037..0bd2dd1 100755 --- 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(),