import os
import sys
-import types
def dodir(path):
os.spawnlp(os.P_WAIT, "install", "install", "-d", path)
(options, args) = parse_args()
- if type(options.allowed_exts) == types.StringType:
- options.allowed_exts = options.allowed_exts.split(",")
-
if options.verbose:
print "Allowed extensions:", options.allowed_exts
print "Document prefix : '" + options.doc_prefix + "'"
fi
[[ ! -s ${srcdir}${x} ]] && die "${x} does not exist"
+ _unpack_tar() {
+ if [ "${y}" == "tar" ]; then
+ $1 -dc "${srcdir}${x}" | tar xof - ${tar_opts}
+ assert "$myfail"
+ else
+ $1 -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
+ fi
+ }
+
myfail="failure unpacking ${x}"
case "${x##*.}" in
tar)
unzip -qo "${srcdir}${x}" || die "$myfail"
;;
gz|Z|z)
- if [ "${y}" == "tar" ]; then
- tar zoxf "${srcdir}${x}" ${tar_opts} || die "$myfail"
- else
- gzip -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
- fi
+ _unpack_tar gzip
;;
bz2|bz)
- if [ "${y}" == "tar" ]; then
- bzip2 -dc "${srcdir}${x}" | tar xof - ${tar_opts}
- assert "$myfail"
- else
- bzip2 -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
- fi
+ _unpack_tar bzip2
;;
7Z|7z)
local my_output
fi
;;
lzma)
- if [ "${y}" == "tar" ]; then
- lzma -dc "${srcdir}${x}" | tar xof - ${tar_opts}
- assert "$myfail"
- else
- lzma -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
- fi
+ _unpack_tar lzma
;;
xz)
if hasq $eapi 0 1 2 ; then
vecho "unpack ${x}: file format not recognized. Ignoring."
else
- if [ "${y}" == "tar" ]; then
- xz -dc "${srcdir}${x}" | tar xof - ${tar_opts}
- assert "$myfail"
- else
- xz -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
- fi
+ _unpack_tar xz
fi
;;
*)
unset x y
export SANDBOX_ON=${PORTAGE_SANDBOX_ON}
unset PORTAGE_SANDBOX_ON
-
- # After loading the environment, make sure the color variables
- # are in sync with the current NOCOLOR setting.
- case "${NOCOLOR:-false}" in
- yes|true)
- unset_colors
- ;;
- no|false)
- set_colors
- ;;
- esac
-
fi
if ! hasq "$EBUILD_PHASE" clean cleanrm && \
ECLASSDIR ECLASS_DEPTH ENDCOL FAKEROOTKEY \
GOOD HILITE HOME IMAGE \
LAST_E_CMD LAST_E_LEN LD_PRELOAD MISC_FUNCTIONS_ARGS MOPREFIX \
- NORMAL PKGDIR PKGUSE PKG_LOGDIR PKG_TMPDIR \
+ NOCOLOR NORMAL PKGDIR PKGUSE PKG_LOGDIR PKG_TMPDIR \
PORTAGE_ACTUAL_DISTDIR PORTAGE_ARCHLIST \
PORTAGE_BASHRC PORTAGE_BASHRCS_SOURCED \
PORTAGE_BINPKG_TAR_OPTS PORTAGE_BINPKG_TMPFILE PORTAGE_BUILDDIR \
from portage.const import NEWS_LIB_PATH
import _emerge.help
-import portage.xpak, commands, errno, re, socket, time, types
+import portage.xpak, commands, errno, re, socket, time
from portage.output import blue, bold, colorize, darkblue, darkgreen, darkred, green, \
nc_len, red, teal, turquoise, xtermTitle, \
xtermTitleReset, yellow
from portage.sets.base import InternalPackageSet
from itertools import chain, izip
-from UserDict import DictMixin
try:
import cPickle as pickle
# formats a size given in bytes nicely
def format_size(mysize):
- if type(mysize) not in [types.IntType,types.LongType]:
- return str(mysize)
+ if isinstance(mysize, basestring):
+ return mysize
if 0 != mysize % 1024:
# Always round up to the next kB so that it doesn't show 0 kB when
# some small file still needs to be fetched.
# the config instance in the subproccess.
fetch_env = os.environ.copy()
+ nocolor = settings.get("NOCOLOR")
+ if nocolor is not None:
+ fetch_env["NOCOLOR"] = nocolor
+
fetch_env["PORTAGE_NICENESS"] = "0"
if self.prefetch:
fetch_env["PORTAGE_PARALLEL_FETCHONLY"] = "1"
if self.depth is None:
self.depth = 0
-class BlockerCache(DictMixin):
+class BlockerCache(portage.cache.mappings.MutableMapping):
"""This caches blockers of installed packages so that dep_check does not
have to be done for every single installed package on every invocation of
emerge. The cache is invalidated whenever it is detected that something
"""
return self.BlockerData(*self._cache_data["blockers"][cpv])
- def keys(self):
- """This needs to be implemented so that self.__repr__() doesn't raise
- an AttributeError."""
- return list(self)
-
class BlockerDB(object):
def __init__(self, root_config):
# dependencies so that things like --fetchonly can still
# function despite collisions.
pass
- else:
+ elif not previously_added:
self._slot_pkg_map[pkg.root][pkg.slot_atom] = pkg
self.mydbapi[pkg.root].cpv_inject(pkg)
+ self._filtered_trees[pkg.root]["porttree"].dbapi._clear_cache()
if not pkg.installed:
# Allow this package to satisfy old-style virtuals in case it
return False
except portage.exception.InvalidDependString:
pass
+ in_graph = self._depgraph._slot_pkg_map[
+ self._root].get(pkg.slot_atom)
+ if in_graph is None:
+ # Mask choices for packages which are not the highest visible
+ # version within their slot (since they usually trigger slot
+ # conflicts).
+ highest_visible, in_graph = self._depgraph._select_package(
+ self._root, pkg.slot_atom)
+ if pkg != highest_visible:
+ return False
+ elif in_graph != pkg:
+ # Mask choices for packages that would trigger a slot
+ # conflict with a previously selected package.
+ return False
return True
def _dep_expand(self, atom):
# $Id$
-VERSION="$Rev: 9373 $"[6:-2] + "-svn"
+VERSION="$Rev: 12601 $"[6:-2] + "-svn"
# ===========================================================================
# START OF IMPORTS -- START OF IMPORTS -- START OF IMPORTS -- START OF IMPORT
import commands
from time import sleep
from random import shuffle
- import UserDict
from itertools import chain, izip
import platform
import warnings
from portage.dbapi.vartree import vardbapi, vartree, dblink
from portage.dbapi.porttree import close_portdbapi_caches, portdbapi, portagetree
-class FetchlistDict(UserDict.DictMixin):
+class FetchlistDict(portage.cache.mappings.Mapping):
"""This provide a mapping interface to retrieve fetch lists. It's used
to allow portage.manifest.Manifest to access fetch lists via a standard
mapping interface rather than use the dbapi directly."""
def has_key(self, pkg_key):
"""Returns true if the given package exists within pkgdir."""
return pkg_key in self
+
+ def __iter__(self):
+ return iter(self.portdb.cp_list(self.cp, mytree=self.mytree))
+
def keys(self):
"""Returns keys for all packages within pkgdir"""
return self.portdb.cp_list(self.cp, mytree=self.mytree)
+ if sys.hexversion >= 0x3000000:
+ keys = __iter__
+
def pkgmerge(mytbz2, myroot, mysettings, mydbapi=None,
vartree=None, prev_mtimes=None, blockers=None):
"""will merge a .tbz2 file, returning a list of runtime dependencies
-# Copyright: 2005 Gentoo Foundation
+# Copyright: 2005-2009 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
# Author(s): Brian Harring (ferringb@gentoo.org)
-# License: GPL2
# $Id$
+__all__ = ["Mapping", "MutableMapping", "UserDict", "ProtectedDict",
+ "LazyLoad", "slot_dict_class"]
+
import sys
-import UserDict
import warnings
import weakref
-class ProtectedDict(UserDict.DictMixin):
+class Mapping(object):
+ """
+ In python-3.0, the UserDict.DictMixin class has been replaced by
+ Mapping and MutableMapping from the collections module, but 2to3
+ doesn't currently account for this change:
+
+ http://bugs.python.org/issue2876
+
+ As a workaround for the above issue, use this class as a substitute
+ for UserDict.DictMixin so that code converted via 2to3 will run.
+ """
+
+ def __iter__(self):
+ return self.iterkeys()
+
+ def keys(self):
+ return list(self.__iter__())
+
+ def has_key(self, key):
+ warnings.warn("portage.cache.mappings.Mapping.has_key() " + \
+ "is deprecated, use the in operator instead", DeprecationWarning)
+ return key in self
+
+ def __contains__(self, key):
+ try:
+ value = self[key]
+ except KeyError:
+ return False
+ return True
+
+ def iteritems(self):
+ for k in self:
+ yield (k, self[k])
+
+ def iterkeys(self):
+ return self.__iter__()
+
+ def itervalues(self):
+ for _, v in self.iteritems():
+ yield v
+
+ def values(self):
+ return [v for _, v in self.iteritems()]
+
+ def items(self):
+ return list(self.iteritems())
+
+ def get(self, key, default=None):
+ try:
+ return self[key]
+ except KeyError:
+ return default
+
+ def __repr__(self):
+ return repr(dict(self.iteritems()))
+
+ def __len__(self):
+ return len(self.keys())
+
+ if sys.hexversion >= 0x3000000:
+ items = iteritems
+ keys = __iter__
+ values = itervalues
+
+class MutableMapping(Mapping):
+ """
+ A mutable vesion of the Mapping class.
+ """
+
+ def clear(self):
+ for key in self.keys():
+ del self[key]
+
+ def setdefault(self, key, default=None):
+ try:
+ return self[key]
+ except KeyError:
+ self[key] = default
+ return default
+
+ def pop(self, key, *args):
+ if len(args) > 1:
+ raise TypeError("pop expected at most 2 arguments, got " + \
+ repr(1 + len(args)))
+ try:
+ value = self[key]
+ except KeyError:
+ if args:
+ return args[0]
+ raise
+ del self[key]
+ return value
+
+ def popitem(self):
+ try:
+ k, v = self.iteritems().next()
+ except StopIteration:
+ raise KeyError('container is empty')
+ del self[k]
+ return (k, v)
+
+ def update(self, other=None, **kwargs):
+ if other is None:
+ pass
+ elif hasattr(other, 'iteritems'):
+ for k, v in other.iteritems():
+ self[k] = v
+ elif hasattr(other, 'keys'):
+ for k in other.keys():
+ self[k] = other[k]
+ else:
+ for k, v in other:
+ self[k] = v
+ if kwargs:
+ self.update(kwargs)
+
+class UserDict(MutableMapping):
+ """
+ Use this class as a substitute for UserDict.UserDict so that
+ code converted via 2to3 will run:
+
+ http://bugs.python.org/issue2876
+ """
+
+ def __init__(self, dict=None, **kwargs):
+ self.data = {}
+ if dict is not None:
+ self.update(dict)
+ if kwargs:
+ self.update(kwargs)
+
+ def __repr__(self):
+ return repr(self.data)
+
+ def __contains__(self, key):
+ return key in self.data
+
+ def __iter__(self):
+ return iter(self.data)
+
+ def __len__(self):
+ return len(self.data)
+
+ def __getitem__(self, key):
+ return self.data[key]
+
+ def __setitem__(self, key, item):
+ self.data[key] = item
+
+ def __delitem__(self, key):
+ del self.data[key]
+
+ def clear(self):
+ self.data.clear()
+
+ if sys.hexversion >= 0x3000000:
+ keys = __iter__
+
+class ProtectedDict(MutableMapping):
"""
given an initial dict, this wraps that dict storing changes in a secondary dict, protecting
the underlying dict from changes
if k not in self.blacklist and k not in self.new:
yield k
-
- def keys(self):
- return list(self.__iter__())
-
-
def __contains__(self, key):
return key in self.new or (key not in self.blacklist and key in self.orig)
if sys.hexversion >= 0x3000000:
keys = __iter__
- items = iteritems
-class LazyLoad(UserDict.DictMixin):
+class LazyLoad(Mapping):
"""
Lazy loading of values for a dict
"""
self.pull = None
return self.d[key]
-
def __iter__(self):
- return iter(self.keys())
-
- def keys(self):
- if self.pull != None:
+ if self.pull is not None:
self.d.update(self.pull())
self.pull = None
- return self.d.keys()
-
+ return iter(self.d)
def has_key(self, key):
warnings.warn("portage.cache.mappings.LazyLoad.has_key() is "
if sys.hexversion >= 0x3000000:
keys = __iter__
- items = iteritems
_slot_dict_classes = weakref.WeakValueDictionary()
return hasattr(self, self._prefix + k)
def has_key(self, k):
+ warnings.warn("portage.cache.mappings.SlotDict.has_key()" + \
+ " is deprecated, use the in operator instead",
+ DeprecationWarning)
return k in self
def pop(self, key, *args):
if sys.hexversion >= 0x3000000:
items = iteritems
+ keys = __iter__
# "a? ( b? ( z ) ) -- Valid
#
-import re, sys, types
+import re, sys
import weakref
from itertools import chain
import portage.exception
while mydeparray:
head = mydeparray.pop(0)
- if type(head) == types.ListType:
+ if not isinstance(head, basestring):
additions = use_reduce(head, uselist, masklist, matchall, excludeall)
if additions:
rlist.append(additions)
# config.py -- Portage Config
-# Copyright 2007 Gentoo Foundation
+# Copyright 2007-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$
-from UserDict import UserDict
+__all__ = ["ConfigLoaderKlass", "GenericFile", "PackageKeywordsFile",
+ "PackageUseFile", "PackageMaskFile", "PortageModulesFile"]
+
+from portage.cache.mappings import UserDict
from portage.env.loaders import KeyListFileLoader, KeyValuePairFileLoader, ItemFileLoader
-class ConfigLoaderKlass(UserDict, object):
+class ConfigLoaderKlass(UserDict):
"""
A base class stub for things to inherit from.
Users may want a non-file backend.
self.data, self.errors = self._loader.load()
- def __iter__(self):
- return iter(self.data)
-
class GenericFile(UserDict):
"""
Inherits from ConfigLoaderKlass, attempts to use all known loaders
"hardlock_name", "hardlink_is_mine", "hardlink_lockfile", \
"unhardlink_lockfile", "hardlock_cleanup"]
-import errno, os, stat, time, types
+import errno, os, stat, time
from portage.exception import DirectoryNotFound, FileNotFound, \
InvalidData, TryAgain, OperationNotPermitted, PermissionDenied
from portage.data import portage_gid
if not mypath:
raise InvalidData("Empty path given")
- if type(mypath) == types.StringType and mypath[-1] == '/':
+ if isinstance(mypath, basestring) and mypath[-1] == '/':
mypath = mypath[:-1]
- if type(mypath) == types.FileType:
+ if hasattr(mypath, 'fileno'):
mypath = mypath.fileno()
- if type(mypath) == types.IntType:
+ if isinstance(mypath, int):
lockfilename = mypath
wantnewlockfile = 0
unlinkfile = 0
unlinkfile = 1
else:
lockfilename = mypath
-
- if type(mypath) == types.StringType:
+
+ if isinstance(mypath, basestring):
if not os.path.exists(os.path.dirname(mypath)):
raise DirectoryNotFound(os.path.dirname(mypath))
preexisting = os.path.exists(lockfilename)
finally:
os.umask(old_mask)
- elif type(mypath) == types.IntType:
+ elif isinstance(mypath, int):
myfd = mypath
else:
raise
- if type(lockfilename) == types.StringType and \
+ if isinstance(lockfilename, basestring) and \
myfd != HARDLINK_FD and _fstat_nlink(myfd) == 0:
# The file was deleted on us... Keep trying to make one...
os.close(myfd)
return True
# myfd may be None here due to myfd = mypath in lockfile()
- if type(lockfilename) == types.StringType and not os.path.exists(lockfilename):
+ if isinstance(lockfilename, basestring) and \
+ not os.path.exists(lockfilename):
writemsg("lockfile does not exist '%s'\n" % lockfilename,1)
if myfd is not None:
os.close(myfd)
unlinkfile = 1
locking_method(myfd,fcntl.LOCK_UN)
except OSError:
- if type(lockfilename) == types.StringType:
+ if isinstance(lockfilename, basestring):
os.close(myfd)
raise IOError("Failed to unlock file '%s'\n" % lockfilename)
# why test lockfilename? because we may have been handed an
# fd originally, and the caller might not like having their
# open fd closed automatically on them.
- if type(lockfilename) == types.StringType:
+ if isinstance(lockfilename, basestring):
os.close(myfd)
return True
# setup_env.py -- Make sure bin subdir has sane env for testing
# Copyright 2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: test_dep_getcpv.py 6182 2007-03-06 07:35:22Z antarus $
+# $Id$
import os, shutil, sys
from os.path import dirname, abspath, join
# test_dobin.py -- Portage Unit Testing Functionality
# Copyright 2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: test_dep_getcpv.py 6182 2007-03-06 07:35:22Z antarus $
+# $Id$
from setup_env import *
# test_dodir.py -- Portage Unit Testing Functionality
# Copyright 2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: test_dodir.py 6182 2007-03-06 07:35:22Z antarus $
+# $Id$
from setup_env import *
# test_dep_getusedeps.py -- Portage Unit Testing Functionality
# Copyright 2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: test_dep_getslot.py 5794 2007-01-27 18:16:08Z antarus $
+# $Id$
from portage.tests import TestCase
from portage.dep import dep_getusedeps
# test_PackageKeywordsFile.py -- Portage Unit Testing Functionality
# Copyright 2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: test_PackageKeywordsFile.py 6182 2007-03-06 07:35:22Z antarus $
+# $Id$
from portage.tests import TestCase
from portage.env.config import PackageKeywordsFile
# test_PackageMaskFile.py -- Portage Unit Testing Functionality
# Copyright 2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: test_PackageMaskFile.py 6182 2007-03-06 07:35:22Z antarus $
+# $Id$
import os
# test_PackageUseFile.py -- Portage Unit Testing Functionality
# Copyright 2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: test_PackageUseFile.py 6182 2007-03-06 07:35:22Z antarus $
+# $Id$
import os
from portage.tests import TestCase
# test_NewsItem.py -- Portage Unit Testing Functionality
# Copyright 2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: test_varExpand.py 5596 2007-01-12 08:08:53Z antarus $
+# $Id$
import os
from portage.tests import TestCase
# Copyright 1998-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: __init__.py 6870 2007-06-19 07:22:18Z zmedico $
+# $Id$
# Copyright 1998-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: test_spawn.py 8474 2007-11-09 03:35:38Z zmedico $
+# $Id$
import errno, os, sys
import fcntl
# testConfigFileSet.py -- Portage Unit Testing Functionality
# Copyright 2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: testShell.py 7363 2007-07-22 23:21:14Z zmedico $
+# $Id$
import tempfile, os
# testStaticFileSet.py -- Portage Unit Testing Functionality
# Copyright 2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: testShell.py 7363 2007-07-22 23:21:14Z zmedico $
+# $Id$
import tempfile, os
pkgs=grabfile(myfilename, compatlevel, recursive=recursive)
for x in range(len(pkgs)-1, -1, -1):
pkg = pkgs[x]
- if pkg[0] in '-*': # -atom *pkg for packages file
+ # for packages and package.mask files
+ if pkg[:1] == "-":
+ pkg = pkg[1:]
+ if pkg[:1] == "*":
pkg = pkg[1:]
if not isvalidatom(pkg):
writemsg("--- Invalid atom in %s: %s\n" % (myfilename, pkgs[x]),