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
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
@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):
@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):
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
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):
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."""
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
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'],
"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(
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:
--- /dev/null
+#!/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)
from gentoolkit.helpers import uniqify
from gentoolkit.textwrap_ import TextWrapper
from gentoolkit.query import Query
+from gentoolkit.flag import get_flags, reduce_flags
# =======
# Globals
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()
except AttributeError:
restrict = ""
- if flag in pkg.settings("USE").split():
+ if flag in final_use:
inuse = True
if flag in used_flags:
inused = True
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)))
--- /dev/null
+#!/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
__all__ = (
'Keyword',
- 'compare_strs'
+ 'compare_strs',
+ 'reduce_keywords',
+ 'determine_keywords'
)
# =======
from gentoolkit.cpv import CPV
from gentoolkit.dbapi import PORTDB, VARDB
from gentoolkit.keyword import determine_keyword
+from gentoolkit.flag import get_flags
# =======
# Classes
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.
--- /dev/null
+# 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
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',
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(),