export PATH="${DEFAULT_PATH}:${PORTAGE_BIN_PATH}:${ROOTPATH}"
[ ! -z "$PREROOTPATH" ] && export PATH="${PREROOTPATH%%:}:$PATH"
-source "@PORTAGE_BASE@"/bin/isolated-functions.sh &>/dev/null
+source "${PORTAGE_BIN_PATH}/isolated-functions.sh" &>/dev/null
OCC="$CC"
OCXX="$CXX"
fi
# return shell-true/shell-false if exists.
# Takes single depend-type atoms.
- if "@PORTAGE_BASE@"/bin/portageq 'has_version' "${ROOT}" "$1"; then
- return 0
- else
- return 1
- fi
+ "${PORTAGE_BIN_PATH}"/portageq has_version "${ROOT}" "$1"
+ local retval=$?
+ case "${retval}" in
+ 0)
+ return 0
+ ;;
+ 1)
+ return 1
+ ;;
+ *)
+ die "unexpected portageq exit code: ${retval}"
+ ;;
+ esac
}
portageq() {
if [ "${EBUILD_PHASE}" == "depend" ]; then
die "portageq calls are not allowed in the global scope"
fi
- "@PORTAGE_BASE@"/bin/portageq "$@"
+ "${PORTAGE_BIN_PATH}/portageq" "$@"
}
fi
# returns the best/most-current match.
# Takes single depend-type atoms.
- "@PORTAGE_BASE@"/bin/portageq 'best_version' "${ROOT}" "$1"
+ "${PORTAGE_BIN_PATH}/portageq" 'best_version' "${ROOT}" "$1"
}
use_with() {
if ! ${CONFCACHE} ${CONFCACHE_ARG} ${TMP_CONFCACHE_DIR} "${ECONF_SOURCE}/configure" \
--prefix="${EPREFIX}"/usr \
- --host="${CHOST}" \
+ --host=${CHOST} \
--mandir="${EPREFIX}"/usr/share/man \
--infodir="${EPREFIX}"/usr/share/info \
--datadir="${EPREFIX}"/usr/share \
unset myarg
# Save current environment and touch a success file. (echo for success)
umask 002
- set | @EGREP@ -v "^SANDBOX_" > "${T}/environment" 2>/dev/null
- export | @EGREP@ -v "^declare -x SANDBOX_" | \
- @SED@ 's:^declare -rx:declare -x:' >> "${T}/environment" 2>/dev/null
+ set | egrep -v "^SANDBOX_" > "${T}/environment" 2>/dev/null
+ export | egrep -v "^declare -x SANDBOX_" | \
+ sed 's:^declare -rx:declare -x:' >> "${T}/environment" 2>/dev/null
chown ${PORTAGE_USER:-portage}:${PORTAGE_GROUP:-portage} "${T}/environment" &>/dev/null
chmod g+w "${T}/environment" &>/dev/null
fi
if __name__ == "__main__":
import sys
- sys.exit(emerge_main())
+ from portage.exception import PermissionDenied
+ try:
+ retval = emerge_main()
+ except PermissionDenied, e:
+ sys.stderr.write("Permission denied: '%s'\n" % str(e))
+ sys.exit(e.errno)
+ sys.exit(retval)
except KeyError:
usage(sys.argv)
sys.exit(os.EX_USAGE)
+ except portage.exception.PermissionDenied, e:
+ sys.stderr.write("Permission denied: '%s'\n" % str(e))
+ sys.exit(e.errno)
main()
usage = "Usage: quickpkg [options] <list of package atoms>"
from optparse import OptionParser
parser = OptionParser(usage=usage)
- options, args = parser.parse_args(sys.argv[1:])
+ parser.add_option("--umask",
+ default="0077",
+ help="umask used during package creation (default is 0077)")
+ from portage import settings
+ default_opts = settings.get("QUICKPKG_DEFAULT_OPTS","").split()
+ options, args = parser.parse_args(default_opts + sys.argv[1:])
if not args:
parser.error("no packages atoms given")
+ try:
+ umask = int(options.umask, 8)
+ except ValueError:
+ parser.error("invalid umask: %s" % options.umask)
# We need to ensure a sane umask for the packages that will be created.
- old_umask = os.umask(022)
+ old_umask = os.umask(umask)
from portage.output import get_term_size, EOutput
eout = EOutput()
def sigwinch_handler(signum, frame):
return myparams
# search functionality
-class search:
+class search(object):
#
# class constants
f.add_flowing_data(x)
f.end_paragraph(1)
-class depgraph:
+class depgraph(object):
pkg_tree_map = {
"ebuild":"porttree",
for x in worlddict.keys():
if not portage.isvalidatom(x):
world_problems = True
- elif not self.trees[self.target_root]["vartree"].dbapi.match(x):
+ continue
+ elif not vardb.match(x):
world_problems = True
- else:
- mylist.append(x)
+ available = False
+ if "--usepkgonly" not in self.myopts and \
+ portdb.match(x):
+ available = True
+ elif "--usepkg" in self.myopts:
+ mymatches = bindb.match(x)
+ if "--usepkgonly" not in self.myopts:
+ mymatches = visible(mymatches)
+ if mymatches:
+ available = True
+ if not available:
+ continue
+ mylist.append(x)
newlist = []
for atom in mylist:
mtime = pathstat[stat.ST_MTIME]
else:
raise portage.exception.DirectoryNotFound(mypath)
- except (IOError,OSError,portage.exception.PortageException):
+ except EnvironmentError, e:
+ if e.errno == portage.exception.PermissionDenied.errno:
+ raise portage.exception.PermissionDenied(mypath)
+ del e
+ if EmptyOnError:
+ return [], []
+ return None, None
+ except portage.exception.PortageException:
if EmptyOnError:
return [], []
return None, None
if mtime != cached_mtime or time.time() - mtime < 4:
if dircache.has_key(mypath):
cacheStale += 1
- list = os.listdir(mypath)
+ try:
+ list = os.listdir(mypath)
+ except EnvironmentError, e:
+ if e.errno != errno.EACCES:
+ raise
+ del e
+ raise portage.exception.PermissionDenied(mypath)
ftype = []
for x in list:
try:
#beautiful directed graph object
-class digraph:
+class digraph(object):
def __init__(self):
"""Create an empty digraph"""
return myusevars
def check_config_instance(test):
- if not test or (str(test.__class__) != 'portage.config'):
- raise TypeError, "Invalid type for config object: %s" % test.__class__
+ if not isinstance(test, config):
+ raise TypeError("Invalid type for config object: %s" % test.__class__)
-class config:
+class config(object):
"""
This class encompasses the main portage configuration. Data is pulled from
ROOT/PORTDIR/profiles/, from ROOT/etc/make.profile incrementally through all
aux_cache[k] = d[k]
self.dbapi._aux_cache[mycpv] = aux_cache
continue
+ if not os.access(full_path, os.R_OK):
+ writemsg("!!! Permission denied to read " + \
+ "binary package: '%s'\n" % full_path,
+ noiselevel=-1)
+ self.invalids.append(myfile[:-5])
+ continue
mytbz2 = portage.xpak.tbz2(full_path)
# For invalid packages, mycat could be None.
mycat = mytbz2.getfile("CATEGORY")
import os, sys
from portage.data import portage_gid
-class cache:
+class cache(object):
"""
Maintains the cache information about eclasses used in ebuild.
"""
"""An operation was not permitted operating system"""
class PermissionDenied(PortageException):
+ from errno import EACCES as errno
"""Permission denied"""
class ReadOnlyFileSystem(PortageException):
return mya
-class FileChecker:
+class FileChecker(object):
def __init__(self,keydir=None,keyring=None,requireSignedRing=False,minimumTrust=EXISTS):
self.minimumTrust = TRUSTED # Default we require trust. For rings.
self.keydir = None
occurs. The curses module is used if available, otherwise the output of
`stty size` is parsed.
"""
+ if not sys.stdout.isatty():
+ return -1, -1
try:
import curses
- curses.setupterm()
- return curses.tigetnum('lines'), curses.tigetnum('cols')
+ try:
+ curses.setupterm()
+ return curses.tigetnum('lines'), curses.tigetnum('cols')
+ except curses.error:
+ pass
except ImportError:
pass
st, out = commands.getstatusoutput('stty size')
cmd = ["stty", "rows", str(lines), "columns", str(columns)]
spawn(cmd, env=os.environ, fd_pipes={0:fd})
-class EOutput:
+class EOutput(object):
"""
Performs fancy terminal formatting for status and informational messages.
curval = self._curval
maxval = self._maxval
position = self._position
- if cols < 3:
+ percentage_str_width = 4
+ square_brackets_width = 2
+ if cols < percentage_str_width:
return ""
- bar_space = cols - 6
+ bar_space = cols - percentage_str_width - square_brackets_width
if maxval == 0:
max_bar_width = bar_space-3
image = " "
"<=>" + ((max_bar_width - bar_width) * " ") + "]"
return image
else:
- max_bar_width = bar_space-1
percentage = int(100 * float(curval) / maxval)
if percentage == 100:
- percentage = 99
- image = ("%d%% " % percentage).rjust(4)
+ percentage_str_width += 1
+ bar_space -= 1
+ max_bar_width = bar_space - 1
+ image = ("%d%% " % percentage).rjust(percentage_str_width)
if cols < min_columns:
return image
offset = float(curval) / maxval
import portage.tests
def main():
- testDirs = ["bin", "util","versions", "dep", "xpak", "env/config"]
+ testDirs = ["bin", "dep", "ebuild",
+ "env/config", "util", "versions", "xpak"]
suite = unittest.TestSuite()
basedir = os.path.dirname(__file__)
for mydir in testDirs:
from os.path import dirname, abspath, join
from portage.tests import TestCase
from portage.process import spawn
+from portage.const import PORTAGE_BIN_PATH
bindir = join(dirname(dirname(abspath(__file__))), "..", "..", "..", "bin")
basedir = join(dirname(dirname(abspath(__file__))), "bin", "root")
os.environ["S"] = os.path.join(basedir, "workdir")
os.environ["PF"] = "portage-tests-0.09-r1"
os.environ["PATH"] = bindir + ":" + os.environ["PATH"]
+os.environ["PORTAGE_BIN_PATH"] = PORTAGE_BIN_PATH
def binTestsCleanup():
if os.access(basedir, os.W_OK):
--- /dev/null
+# Copyright 1998-2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
--- /dev/null
+# Copyright 1998-2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+import errno, os, sys
+from portage.tests import TestCase
+
+class SpawnTestCase(TestCase):
+
+ def testLogfile(self):
+ from portage import settings, spawn
+ from tempfile import mkstemp
+ logfile = None
+ try:
+ fd, logfile = mkstemp()
+ os.close(fd)
+ null_fd = os.open('/dev/null', os.O_RDWR)
+ test_string = 2 * "blah blah blah\n"
+ spawn("echo -n '%s'" % test_string, settings, logfile=logfile,
+ fd_pipes={0:sys.stdin.fileno(), 1:null_fd, 2:null_fd})
+ os.close(null_fd)
+ f = open(logfile, 'r')
+ log_content = f.read()
+ f.close()
+ # When logging passes through a pty, it's lines will be separated
+ # by '\r\n', so use splitlines before comparing results.
+ self.assertEqual(test_string.splitlines(),
+ log_content.splitlines())
+ finally:
+ if logfile:
+ try:
+ os.unlink(logfile)
+ except EnvironmentError, e:
+ if e.errno != errno.ENOENT:
+ raise
+ del e
startpos=startpos+namelen+12
os.chdir(origdir)
-class tbz2:
+class tbz2(object):
def __init__(self,myfile):
self.file=myfile
self.filestat=None