import cvstree
import xpak
import getbinpkg
- import portage_dep
- from portage_dep import dep_getcpv, dep_getkey, get_operator, \
+ import portage.dep
+ from portage.dep import dep_getcpv, dep_getkey, get_operator, \
isjustname, isspecific, isvalidatom, \
match_from_list, match_to_list, best_match_to_list
import output
from output import bold, colorize, green, red, yellow
- import portage_const
- from portage_const import VDB_PATH, PRIVATE_PATH, CACHE_PATH, DEPCACHE_PATH, \
+ import portage.const
+ from portage.const import VDB_PATH, PRIVATE_PATH, CACHE_PATH, DEPCACHE_PATH, \
USER_CONFIG_PATH, MODULES_FILE_PATH, CUSTOM_PROFILE_PATH, PORTAGE_BASE_PATH, \
PORTAGE_BIN_PATH, PORTAGE_PYM_PATH, PROFILE_PATH, LOCALE_DATA_PATH, \
EBUILD_SH_BINARY, SANDBOX_BINARY, BASH_BINARY, \
INCREMENTALS, EAPI, MISC_SH_BINARY, REPO_NAME_LOC, REPO_NAME_FILE, \
EPREFIX
- from portage_data import ostype, lchown, userland, secpass, uid, wheelgid, \
+ from portage.data import ostype, lchown, userland, secpass, uid, wheelgid, \
portage_uid, portage_gid, userpriv_groups
- from portage_manifest import Manifest
+ from portage.manifest import Manifest
- import portage_util
- from portage_util import atomic_ofstream, apply_secpass_permissions, apply_recursive_permissions, \
+ import portage.util
+ from portage.util import atomic_ofstream, apply_secpass_permissions, apply_recursive_permissions, \
dump_traceback, getconfig, grabdict, grabdict_package, grabfile, grabfile_package, \
map_dictlist_vals, new_protect_filename, normalize_path, \
pickle_read, pickle_write, stack_dictlist, stack_dicts, stack_lists, \
unique_array, varexpand, writedict, writemsg, writemsg_stdout, write_atomic
- import portage_exception
- import portage_gpg
- import portage_locks
- import portage_exec
- from portage_exec import atexit_register, run_exitfuncs
- from portage_locks import unlockfile,unlockdir,lockfile,lockdir
- import portage_checksum
- from portage_checksum import perform_md5,perform_checksum,prelink_capable
+ import portage.exception
+ import portage.gpg
+ import portage.locks
+ import portage.process
+ from portage.process import atexit_register, run_exitfuncs
+ from portage.locks import unlockfile,unlockdir,lockfile,lockdir
+ import portage.checksum
+ from portage.checksum import perform_md5,perform_checksum,prelink_capable
import eclass_cache
- from portage_localization import _
- from portage_update import dep_transform, fixdbentries, grab_updates, \
+ from portage.localization import _
+ from portage.update import dep_transform, fixdbentries, grab_updates, \
parse_updates, update_config_files, update_dbentries
# Need these functions directly in portage namespace to not break every external tool in existence
- from portage_versions import best, catpkgsplit, catsplit, pkgcmp, \
+ from portage.versions import best, catpkgsplit, catsplit, pkgcmp, \
pkgsplit, vercmp, ververify
# endversion and endversion_keys are for backward compatibility only.
- from portage_versions import endversion_keys
- from portage_versions import suffix_value as endversion
+ from portage.versions import endversion_keys
+ from portage.versions import suffix_value as endversion
except ImportError, e:
sys.stderr.write("\n\n")
try:
- import portage_selinux as selinux
+ import portage.selinux as selinux
except OSError, e:
writemsg("!!! SELinux not loaded: %s\n" % str(e), noiselevel=-1)
del e
if stat.S_ISDIR(pathstat[stat.ST_MODE]):
mtime = pathstat[stat.ST_MTIME]
else:
- raise portage_exception.DirectoryNotFound(mypath)
- except (IOError,OSError,portage_exception.PortageException):
+ raise portage.exception.DirectoryNotFound(mypath)
+ except (IOError,OSError,portage.exception.PortageException):
if EmptyOnError:
return [], []
return None, None
all_logentries = {}
for f in mylogfiles:
msgfunction, msgtype = f.split(".")
- if msgfunction not in portage_const.EBUILD_PHASES:
+ if msgfunction not in portage.const.EBUILD_PHASES:
writemsg("!!! can't process invalid log file: %s\n" % f,
noiselevel=-1)
continue
def combine_logentries(logentries):
# generate a single string with all log messages
rValue = ""
- for phase in portage_const.EBUILD_PHASES:
+ for phase in portage.const.EBUILD_PHASES:
if not phase in logentries:
continue
for msgtype,msgcontent in logentries[phase]:
logmodule = __import__("elog_modules.mod_"+s)
m = getattr(logmodule, "mod_"+s)
def timeout_handler(signum, frame):
- raise portage_exception.PortageException(
+ raise portage.exception.PortageException(
"Timeout in elog_process for system '%s'" % s)
import signal
signal.signal(signal.SIGALRM, timeout_handler)
writemsg("!!! Error while importing logging modules " + \
"while loading \"mod_%s\":\n" % str(s))
writemsg("%s\n" % str(e), noiselevel=-1)
- except portage_exception.PortageException, e:
+ except portage.exception.PortageException, e:
writemsg("%s\n" % str(e), noiselevel=-1)
# clean logfiles to avoid repetitions
global mtimedb
prev_mtimes = mtimedb["ldpath"]
envd_dir = os.path.join(target_root + EPREFIX, "etc", "env.d")
- portage_util.ensure_dirs(envd_dir, mode=0755)
+ portage.util.ensure_dirs(envd_dir, mode=0755)
fns = listdir(envd_dir, EmptyOnError=1)
fns.sort()
templist = []
file_path = os.path.join(envd_dir, x)
try:
myconfig = getconfig(file_path, expand=False)
- except portage_exception.ParseError, e:
+ except portage.exception.ParseError, e:
writemsg("!!! '%s'\n" % str(e), noiselevel=-1)
del e
continue
mtime_changed = False
lib_dirs = set()
- for lib_dir in portage_util.unique_array(specials["LDPATH"]+['usr/lib','usr/lib64','usr/lib32','lib','lib64','lib32']):
+ for lib_dir in portage.util.unique_array(specials["LDPATH"]+['usr/lib','usr/lib64','usr/lib32','lib','lib64','lib32']):
x = os.path.join(target_root + EPREFIX, lib_dir.lstrip(os.sep))
try:
newldpathtime = os.stat(x)[stat.ST_MTIME]
@param mycpv: CPV to load up (see setcpv), this is the same as calling init with mycpv=None
and then calling instance.setcpv(mycpv).
@type mycpv: String
- @param config_profile_path: Configurable path to the profile (usually PROFILE_PATH from portage_const)
+ @param config_profile_path: Configurable path to the profile (usually PROFILE_PATH from portage.const)
@type config_profile_path: String
- @param config_incrementals: List of incremental variables (usually portage_const.INCREMENTALS)
+ @param config_incrementals: List of incremental variables (usually portage.const.INCREMENTALS)
@type config_incrementals: List
@param config_root: path to read local config from (defaults to "/", see PORTAGE_CONFIGROOT)
@type config_root: String
writemsg(("!!! Error: %s='%s' is not a directory. " + \
"Please correct this.\n") % (varname, var),
noiselevel=-1)
- raise portage_exception.DirectoryNotFound(var)
+ raise portage.exception.DirectoryNotFound(var)
if config_root is None:
config_root = "/"
if not config_incrementals:
writemsg("incrementals not specified to class config\n")
- self.incrementals = copy.deepcopy(portage_const.INCREMENTALS)
+ self.incrementals = copy.deepcopy(portage.const.INCREMENTALS)
else:
self.incrementals = copy.deepcopy(config_incrementals)
if os.path.exists(parentsFile):
parents = grabfile(parentsFile)
if not parents:
- raise portage_exception.ParseError(
+ raise portage.exception.ParseError(
"Empty parent file: '%s'" % parents_file)
for parentPath in parents:
parentPath = normalize_path(os.path.join(
if os.path.exists(parentPath):
addProfile(parentPath)
else:
- raise portage_exception.ParseError(
+ raise portage.exception.ParseError(
"Parent '%s' not found: '%s'" % \
(parentPath, parentsFile))
self.profiles.append(currentPath)
self.make_defaults_use.append(cfg.get("USE", ""))
else:
self.make_defaults_use.append("")
- self.mygcfg = stack_dicts(mygcfg_dlists, incrementals=portage_const.INCREMENTALS, ignore_none=1)
+ self.mygcfg = stack_dicts(mygcfg_dlists, incrementals=portage.const.INCREMENTALS, ignore_none=1)
#self.mygcfg = grab_stacked("make.defaults", self.profiles, getconfig)
if self.mygcfg is None:
self.mygcfg = {}
self.backup_changes(var)
self.regenerate()
- self.features = portage_util.unique_array(self["FEATURES"].split())
+ self.features = portage.util.unique_array(self["FEATURES"].split())
if "gpg" in self.features:
if not os.path.exists(self["PORTAGE_GPG_DIR"]) or \
" Removing gpg from FEATURES.\n"), noiselevel=-1)
self.features.remove("gpg")
- if not portage_exec.sandbox_capable and \
+ if not portage.process.sandbox_capable and \
("sandbox" in self.features or "usersandbox" in self.features):
if self.profile_path is not None and \
os.path.realpath(self.profile_path) == \
for mypath, (gid, mode, modemask) in dir_mode_map.iteritems():
try:
mydir = normalize_path(os.path.join(self["ROOT"] + EPREFIX, mypath))
- portage_util.ensure_dirs(mydir, gid=gid, mode=mode, mask=modemask)
- except portage_exception.PortageException, e:
+ portage.util.ensure_dirs(mydir, gid=gid, mode=mode, mask=modemask)
+ except portage.exception.PortageException, e:
writemsg("!!! Directory initialization failed: '%s'\n" % mydir,
noiselevel=-1)
writemsg("!!! %s\n" % str(e),
myuse = self["USE"]
else:
myuse = mydbapi.aux_get(mycpv, ["USE"])[0]
- virts = flatten(portage_dep.use_reduce(portage_dep.paren_reduce(provides), uselist=myuse.split()))
+ virts = flatten(portage.dep.use_reduce(portage.dep.paren_reduce(provides), uselist=myuse.split()))
cp = dep_getkey(mycpv)
for virt in virts:
instead of as root.
Notes: os.system cannot be used because it messes with signal handling. Instead we
- use the portage_exec spawn* family of functions.
+ use the portage.process spawn* family of functions.
This function waits for the process to terminate.
elif 1 not in fd_pipes or 2 not in fd_pipes:
raise ValueError(fd_pipes)
pr, pw = os.pipe()
- mypids.extend(portage_exec.spawn(('tee', '-i', '-a', logfile),
+ mypids.extend(portage.process.spawn(('tee', '-i', '-a', logfile),
returnpid=True, fd_pipes={0:pr, 1:fd_pipes[1], 2:fd_pipes[2]}))
os.close(pr)
fd_pipes[1] = pw
if free:
keywords["opt_name"] += " bash"
- spawn_func = portage_exec.spawn_bash
+ spawn_func = portage.process.spawn_bash
else:
keywords["opt_name"] += " sandbox"
- spawn_func = portage_exec.spawn_sandbox
+ spawn_func = portage.process.spawn_sandbox
if sesandbox:
con = selinux.getcontext()
while mypids:
pid = mypids.pop(0)
retval = os.waitpid(pid, 0)[1]
- portage_exec.spawned_pids.remove(pid)
+ portage.process.spawned_pids.remove(pid)
if retval != os.EX_OK:
for pid in mypids:
if os.waitpid(pid, os.WNOHANG) == (0,0):
os.kill(pid, signal.SIGTERM)
os.waitpid(pid, 0)
- portage_exec.spawned_pids.remove(pid)
+ portage.process.spawned_pids.remove(pid)
if retval & 0xff:
return (retval & 0xff) << 8
return retval >> 8
for x in distdir_dirs:
mydir = os.path.join(mysettings["DISTDIR"], x)
- if portage_util.ensure_dirs(mydir, gid=portage_gid, mode=dirmode, mask=modemask):
+ if portage.util.ensure_dirs(mydir, gid=portage_gid, mode=dirmode, mask=modemask):
writemsg("Adjusting permissions recursively: '%s'\n" % mydir,
noiselevel=-1)
def onerror(e):
if not apply_recursive_permissions(mydir,
gid=portage_gid, dirmode=dirmode, dirmask=modemask,
filemode=filemode, filemask=modemask, onerror=onerror):
- raise portage_exception.OperationNotPermitted(
+ raise portage.exception.OperationNotPermitted(
"Failed to apply recursive permissions for the portage group.")
- except portage_exception.PortageException, e:
+ except portage.exception.PortageException, e:
if not os.path.isdir(mysettings["DISTDIR"]):
writemsg("!!! %s\n" % str(e), noiselevel=-1)
writemsg("!!! Directory Not Found: DISTDIR='%s'\n" % mysettings["DISTDIR"], noiselevel=-1)
else:
if use_locks and can_fetch:
if locks_in_subdir:
- file_lock = portage_locks.lockfile(mysettings["DISTDIR"]+"/"+locks_in_subdir+"/"+myfile,wantnewlockfile=1)
+ file_lock = portage.locks.lockfile(mysettings["DISTDIR"]+"/"+locks_in_subdir+"/"+myfile,wantnewlockfile=1)
else:
- file_lock = portage_locks.lockfile(mysettings["DISTDIR"]+"/"+myfile,wantnewlockfile=1)
+ file_lock = portage.locks.lockfile(mysettings["DISTDIR"]+"/"+myfile,wantnewlockfile=1)
try:
if not listonly:
if fsmirrors and not os.path.exists(myfile_path):
apply_secpass_permissions(
myfile_path, gid=portage_gid, mode=0664, mask=02,
stat_cached=mystat)
- except portage_exception.PortageException, e:
+ except portage.exception.PortageException, e:
if not os.access(myfile_path, os.R_OK):
writemsg("!!! Failed to adjust permissions:" + \
" %s\n" % str(e), noiselevel=-1)
not restrict_fetch:
fetched = 1 # Try to resume this download.
else:
- verified_ok, reason = portage_checksum.verify_all(
+ verified_ok, reason = portage.checksum.verify_all(
myfile_path, mydigests[myfile])
if not verified_ok:
writemsg("!!! Previously fetched" + \
con = con.replace(mysettings["PORTAGE_T"], mysettings["PORTAGE_FETCH_T"])
selinux.setexec(con)
- myret = portage_exec.spawn_bash(myfetch,
+ myret = portage.process.spawn_bash(myfetch,
env=mysettings.environ(), **spawn_keywords)
if mysettings.selinux_enabled():
try:
apply_secpass_permissions(myfile_path,
gid=portage_gid, mode=0664, mask=02)
- except portage_exception.FileNotFound, e:
+ except portage.exception.FileNotFound, e:
pass
- except portage_exception.PortageException, e:
+ except portage.exception.PortageException, e:
if not os.access(myfile_path, os.R_OK):
writemsg("!!! Failed to adjust permissions:" + \
" %s\n" % str(e), noiselevel=-1)
# file NOW, for those users who don't have a stable/continuous
# net connection. This way we have a chance to try to download
# from another mirror...
- verified_ok,reason = portage_checksum.verify_all(mysettings["DISTDIR"]+"/"+myfile, mydigests[myfile])
+ verified_ok,reason = portage.checksum.verify_all(mysettings["DISTDIR"]+"/"+myfile, mydigests[myfile])
if not verified_ok:
print reason
writemsg("!!! Fetched file: "+str(myfile)+" VERIFY FAILED!\n",
noiselevel=-1)
finally:
if use_locks and file_lock:
- portage_locks.unlockfile(file_lock)
+ portage.locks.unlockfile(file_lock)
if listonly:
writemsg_stdout("\n", noiselevel=-1)
"""
Generates a digest file if missing. Assumes all files are available.
DEPRECATED: this now only is a compability wrapper for
- portage_manifest.Manifest()
+ portage.manifest.Manifest()
NOTE: manifestonly and overwrite are useless with manifest2 and
are therefore ignored."""
if myportdb is None:
# fetches when sufficient digests already exist. To ease transition
# while Manifest 1 is being removed, only require hashes that will
# exist before and after the transition.
- required_hash_types = set(portage_const.MANIFEST1_HASH_FUNCTIONS
- ).intersection(portage_const.MANIFEST2_HASH_FUNCTIONS)
+ required_hash_types = set(portage.const.MANIFEST1_HASH_FUNCTIONS
+ ).intersection(portage.const.MANIFEST2_HASH_FUNCTIONS)
required_hash_types.add("size")
dist_hashes = mf.fhashdict.get("DIST", {})
missing_hashes = set()
assumeDistHashesSometimes=True,
assumeDistHashesAlways=(
"assume-digests" in mysettings.features))
- except portage_exception.FileNotFound, e:
+ except portage.exception.FileNotFound, e:
writemsg(("!!! File %s doesn't exist, can't update " + \
"Manifest\n") % e, noiselevel=-1)
return 0
and returns a dict with the filenames as keys and {checksumkey:checksum}
as the values.
DEPRECATED: this function is now only a compability wrapper for
- portage_manifest.Manifest()."""
+ portage.manifest.Manifest()."""
mysplit = myfilename.split(os.sep)
if mysplit[-2] == "files" and mysplit[-1].startswith("digest-"):
def digestcheck(myfiles, mysettings, strict=0, justmanifest=0):
"""Verifies checksums. Assumes all files have been downloaded.
DEPRECATED: this is now only a compability wrapper for
- portage_manifest.Manifest()."""
+ portage.manifest.Manifest()."""
if not strict:
return 1
pkgdir = mysettings["O"]
eout.eend(1)
writemsg("\n!!! Missing digest for %s\n" % str(e), noiselevel=-1)
return 0
- except portage_exception.FileNotFound, e:
+ except portage.exception.FileNotFound, e:
eout.eend(1)
writemsg("\n!!! A file listed in the Manifest could not be found: %s\n" % str(e),
noiselevel=-1)
return 0
- except portage_exception.DigestException, e:
+ except portage.exception.DigestException, e:
eout.eend(1)
writemsg("\n!!! Digest verification failed:\n", noiselevel=-1)
writemsg("!!! %s\n" % e.value[0], noiselevel=-1)
def eapi_is_supported(eapi):
- return str(eapi).strip() == str(portage_const.EAPI).strip()
+ return str(eapi).strip() == str(portage.const.EAPI).strip()
def doebuild_environment(myebuild, mydo, myroot, mysettings, debug, use_cache, mydbapi):
mycpv = cat+"/"+mypv
mysplit=pkgsplit(mypv,silent=0)
if mysplit is None:
- raise portage_exception.IncorrectParameter(
+ raise portage.exception.IncorrectParameter(
"Invalid ebuild path: '%s'" % myebuild)
if mydo != "depend":
mysettings["PV"] = mysplit[1]
mysettings["PR"] = mysplit[2]
- if portage_util.noiselimit < 0:
+ if portage.util.noiselimit < 0:
mysettings["PORTAGE_QUIET"] = "1"
if mydo != "depend":
mydbapi.aux_get(mycpv, ["EAPI", "INHERITED", "SLOT", "RESTRICT"])
if not eapi_is_supported(eapi):
# can't do anything with this.
- raise portage_exception.UnsupportedAPIException(mycpv, eapi)
+ raise portage.exception.UnsupportedAPIException(mycpv, eapi)
mysettings["PORTAGE_RESTRICT"] = " ".join(flatten(
- portage_dep.use_reduce(portage_dep.paren_reduce(
+ portage.dep.use_reduce(portage.dep.paren_reduce(
mysettings["RESTRICT"]), uselist=mysettings["USE"].split())))
if mysplit[2] == "r0":
try:
for mydir in mydirs:
- portage_util.ensure_dirs(mydir)
- portage_util.apply_secpass_permissions(mydir,
+ portage.util.ensure_dirs(mydir)
+ portage.util.apply_secpass_permissions(mydir,
gid=portage_gid, uid=portage_uid, mode=070, mask=0)
for dir_key in ("PORTAGE_BUILDDIR", "HOME", "PKG_LOGDIR", "T"):
"""These directories don't necessarily need to be group writable.
to the other phases being run by an unprivileged user. Currently,
we use the portage group to ensure that the unprivleged user still
has write access to these directories in any case."""
- portage_util.ensure_dirs(mysettings[dir_key], mode=0775)
- portage_util.apply_secpass_permissions(mysettings[dir_key],
+ portage.util.ensure_dirs(mysettings[dir_key], mode=0775)
+ portage.util.apply_secpass_permissions(mysettings[dir_key],
uid=portage_uid, gid=portage_gid)
- except portage_exception.PermissionDenied, e:
+ except portage.exception.PermissionDenied, e:
writemsg("Permission Denied: %s\n" % str(e), noiselevel=-1)
return 1
- except portage_exception.OperationNotPermitted, e:
+ except portage.exception.OperationNotPermitted, e:
writemsg("Operation Not Permitted: %s\n" % str(e), noiselevel=-1)
return 1
- except portage_exception.FileNotFound, e:
+ except portage.exception.FileNotFound, e:
writemsg("File Not Found: '%s'\n" % str(e), noiselevel=-1)
return 1
for subdir in kwargs["subdirs"]:
mydirs.append(os.path.join(basedir, subdir))
for mydir in mydirs:
- modified = portage_util.ensure_dirs(mydir,
+ modified = portage.util.ensure_dirs(mydir,
gid=portage_gid, mode=dirmode, mask=modemask)
# To avoid excessive recursive stat calls, we trigger
# recursion when the top level directory does not initially
if not apply_recursive_permissions(mydir,
gid=portage_gid, dirmode=dirmode, dirmask=modemask,
filemode=filemode, filemask=modemask, onerror=onerror):
- raise portage_exception.OperationNotPermitted(
+ raise portage.exception.OperationNotPermitted(
"Failed to apply recursive permissions for the portage group.")
- except portage_exception.PortageException, e:
+ except portage.exception.PortageException, e:
mysettings.features.remove(myfeature)
mysettings["FEATURES"] = " ".join(mysettings.features)
writemsg("!!! %s\n" % str(e), noiselevel=-1)
try:
apply_secpass_permissions(mysettings["WORKDIR"],
uid=portage_uid, gid=portage_gid, mode=workdir_mode)
- except portage_exception.FileNotFound:
+ except portage.exception.FileNotFound:
pass # ebuild.sh will create it
if mysettings.get("PORT_LOGDIR", "") == "":
del mysettings["PORT_LOGDIR"]
if "PORT_LOGDIR" in mysettings:
try:
- portage_util.ensure_dirs(mysettings["PORT_LOGDIR"],
+ portage.util.ensure_dirs(mysettings["PORT_LOGDIR"],
uid=portage_uid, gid=portage_gid, mode=02770)
- except portage_exception.PortageException, e:
+ except portage.exception.PortageException, e:
writemsg("!!! %s\n" % str(e), noiselevel=-1)
writemsg("!!! Permission issues with PORT_LOGDIR='%s'\n" % \
mysettings["PORT_LOGDIR"], noiselevel=-1)
mf = Manifest(pkgdir, mysettings["DISTDIR"])
try:
mf.checkTypeHashes("EBUILD")
- except portage_exception.FileNotFound, e:
+ except portage.exception.FileNotFound, e:
writemsg("!!! A file listed in the Manifest " + \
"could not be found: %s\n" % str(e), noiselevel=-1)
return 1
- except portage_exception.DigestException, e:
+ except portage.exception.DigestException, e:
writemsg("!!! Digest verification failed:\n", noiselevel=-1)
writemsg("!!! %s\n" % e.value[0], noiselevel=-1)
writemsg("!!! Reason: %s\n" % e.value[1], noiselevel=-1)
for k, v in izip(auxdbkeys, mybytes.splitlines()):
dbkey[k] = v
retval = os.waitpid(mypids[0], 0)[1]
- portage_exec.spawned_pids.remove(mypids[0])
+ portage.process.spawned_pids.remove(mypids[0])
# If it got a signal, return the signal that was sent, but
# shift in order to distinguish it from a return value. (just
- # like portage_exec.spawn() would do).
+ # like portage.process.spawn() would do).
if retval & 0xff:
return (retval & 0xff) << 8
# Otherwise, return its exit code.
myportdb=mydbapi)
elif "digest" in mysettings.features:
digestgen(aalist, mysettings, overwrite=0, myportdb=mydbapi)
- except portage_exception.PermissionDenied, e:
+ except portage.exception.PermissionDenied, e:
writemsg("!!! %s\n" % str(e), noiselevel=-1)
if mydo in ("digest", "manifest"):
return 1
if mydo in actionmap.keys():
if mydo=="package":
- portage_util.ensure_dirs(
+ portage.util.ensure_dirs(
os.path.join(mysettings["PKGDIR"], mysettings["CATEGORY"]))
- portage_util.ensure_dirs(
+ portage.util.ensure_dirs(
os.path.join(mysettings["PKGDIR"], "All"))
retval = spawnebuild(mydo,
actionmap, mysettings, debug, logfile=logfile)
finally:
if builddir_lock:
- portage_locks.unlockdir(builddir_lock)
+ portage.locks.unlockdir(builddir_lock)
# Make sure that DISTDIR is restored to it's normal value before we return!
if "PORTAGE_ACTUAL_DISTDIR" in mysettings:
newsplit.append(_expand_new_virtuals(x, edebug, mydbapi,
mysettings, myroot=myroot, trees=trees, **kwargs))
continue
- if portage_dep._dep_check_strict and \
+ if portage.dep._dep_check_strict and \
not isvalidatom(x, allow_blockers=True):
- raise portage_exception.ParseError(
+ raise portage.exception.ParseError(
"invalid atom: '%s'" % x)
mykey = dep_getkey(x)
if not mykey.startswith("virtual/"):
mycheck = dep_check(depstring, mydbapi, mysettings, myroot=myroot,
trees=trees, **kwargs)
if not mycheck[0]:
- raise portage_exception.ParseError(
+ raise portage.exception.ParseError(
"%s: %s '%s'" % (y[0], mycheck[1], depstring))
if isblocker:
virtual_atoms = [atom for atom in mycheck[1] \
myusesplit=[]
#convert parenthesis to sublists
- mysplit = portage_dep.paren_reduce(depstring)
+ mysplit = portage.dep.paren_reduce(depstring)
mymasks = set()
useforce = set()
useforce.update(mysettings.useforce)
useforce.difference_update(mymasks)
try:
- mysplit = portage_dep.use_reduce(mysplit, uselist=myusesplit,
+ mysplit = portage.dep.use_reduce(mysplit, uselist=myusesplit,
masklist=mymasks, matchall=(use=="all"), excludeall=useforce)
- except portage_exception.InvalidDependString, e:
+ except portage.exception.InvalidDependString, e:
return [0, str(e)]
# Do the || conversions
- mysplit=portage_dep.dep_opconvert(mysplit)
+ mysplit=portage.dep.dep_opconvert(mysplit)
if mysplit == []:
#dependencies were reduced to nothing
mysplit = _expand_new_virtuals(mysplit, edebug, mydbapi, mysettings,
use=use, mode=mode, myuse=myuse, use_cache=use_cache,
use_binaries=use_binaries, myroot=myroot, trees=trees)
- except portage_exception.ParseError, e:
+ except portage.exception.ParseError, e:
return [0, str(e)]
mysplit2=mysplit[:]
return mykey
def getmaskingreason(mycpv, settings=None, portdb=None):
- from portage_util import grablines
+ from portage.util import grablines
if settings is None:
settings = globals()["settings"]
if portdb is None:
# error message will have already been printed to stderr.
return ["corruption"]
if not eapi_is_supported(eapi):
- return ["required EAPI %s, supported EAPI %s" % (eapi, portage_const.EAPI)]
+ return ["required EAPI %s, supported EAPI %s" % (eapi, portage.const.EAPI)]
mygroups = mygroups.split()
pgroups = settings["ACCEPT_KEYWORDS"].split()
myarch = settings["ARCH"]
mydep = dep_expand(origdep, mydb=self, settings=self.settings)
mykey=dep_getkey(mydep)
mylist = match_from_list(mydep,self.cp_list(mykey,use_cache=use_cache))
- myslot = portage_dep.dep_getslot(mydep)
+ myslot = portage.dep.dep_getslot(mydep)
if myslot is not None:
mylist = [cpv for cpv in mylist \
if self.aux_get(cpv, ["SLOT"])[0] == myslot]
if re.search("portage_lockfile$",mypath):
if not os.environ.has_key("PORTAGE_MASTER_PID"):
writemsg("Lockfile removed: %s\n" % mypath, 1)
- portage_locks.unlockfile((mypath,None,None))
+ portage.locks.unlockfile((mypath,None,None))
else:
# Nothing we can do about it. We're probably sandboxed.
pass
# sanity check
for cp in [origcp,newcp]:
if not (isvalidatom(cp) and isjustname(cp)):
- raise portage_exception.InvalidPackageName(cp)
+ raise portage.exception.InvalidPackageName(cp)
origmatches=self.match(origcp,use_cache=0)
if not origmatches:
return
newslot=mylist[3]
if not isvalidatom(pkg):
- raise portage_exception.InvalidAtom(pkg)
+ raise portage.exception.InvalidAtom(pkg)
origmatches=self.match(pkg,use_cache=0)
del self.matchcache[mycat]
mymatch = match_from_list(mydep,
self.cp_list(mykey, use_cache=use_cache))
- myslot = portage_dep.dep_getslot(mydep)
+ myslot = portage.dep.dep_getslot(mydep)
if myslot is not None:
mymatch = [cpv for cpv in mymatch \
if self.aux_get(cpv, ["SLOT"])[0] == myslot]
self.matchcache[mycat]={}
if not self.matchcache[mycat].has_key(mydep):
mymatch=match_from_list(mydep,self.cp_list(mykey,use_cache=use_cache))
- myslot = portage_dep.dep_getslot(mydep)
+ myslot = portage.dep.dep_getslot(mydep)
if myslot is not None:
mymatch = [cpv for cpv in mymatch \
if self.aux_get(cpv, ["SLOT"])[0] == myslot]
f = atomic_ofstream(self._aux_cache_filename)
cPickle.dump(self._aux_cache, f, -1)
f.close()
- portage_util.apply_secpass_permissions(
+ portage.util.apply_secpass_permissions(
self._aux_cache_filename, gid=portage_gid, mode=0644)
except (IOError, OSError), e:
pass
mylines, myuse = self.dbapi.aux_get(mycpv, ["PROVIDE","USE"])
if mylines:
myuse = myuse.split()
- mylines = flatten(portage_dep.use_reduce(portage_dep.paren_reduce(mylines), uselist=myuse))
+ mylines = flatten(portage.dep.use_reduce(portage.dep.paren_reduce(mylines), uselist=myuse))
for myprovide in mylines:
mys = catpkgsplit(myprovide)
if not mys:
self.manifestMissingCache = []
if "gpg" in self.mysettings.features:
- self.manifestVerifyLevel = portage_gpg.EXISTS
+ self.manifestVerifyLevel = portage.gpg.EXISTS
if "strict" in self.mysettings.features:
- self.manifestVerifyLevel = portage_gpg.MARGINAL
- self.manifestVerifier = portage_gpg.FileChecker(self.mysettings["PORTAGE_GPG_DIR"], "gentoo.gpg", minimumTrust=self.manifestVerifyLevel)
+ self.manifestVerifyLevel = portage.gpg.MARGINAL
+ self.manifestVerifier = portage.gpg.FileChecker(self.mysettings["PORTAGE_GPG_DIR"], "gentoo.gpg", minimumTrust=self.manifestVerifyLevel)
elif "severe" in self.mysettings.features:
- self.manifestVerifyLevel = portage_gpg.TRUSTED
- self.manifestVerifier = portage_gpg.FileChecker(self.mysettings["PORTAGE_GPG_DIR"], "gentoo.gpg", requireSignedRing=True, minimumTrust=self.manifestVerifyLevel)
+ self.manifestVerifyLevel = portage.gpg.TRUSTED
+ self.manifestVerifier = portage.gpg.FileChecker(self.mysettings["PORTAGE_GPG_DIR"], "gentoo.gpg", requireSignedRing=True, minimumTrust=self.manifestVerifyLevel)
else:
- self.manifestVerifier = portage_gpg.FileChecker(self.mysettings["PORTAGE_GPG_DIR"], "gentoo.gpg", minimumTrust=self.manifestVerifyLevel)
+ self.manifestVerifier = portage.gpg.FileChecker(self.mysettings["PORTAGE_GPG_DIR"], "gentoo.gpg", minimumTrust=self.manifestVerifyLevel)
#self.root=settings["PORTDIR"]
self.porttree_root = os.path.realpath(porttree_root)
try:
for mydir in (self.depcachedir,):
- if portage_util.ensure_dirs(mydir, gid=portage_gid, mode=dirmode, mask=modemask):
+ if portage.util.ensure_dirs(mydir, gid=portage_gid, mode=dirmode, mask=modemask):
writemsg("Adjusting permissions recursively: '%s'\n" % mydir,
noiselevel=-1)
def onerror(e):
if not apply_recursive_permissions(mydir,
gid=portage_gid, dirmode=dirmode, dirmask=modemask,
filemode=filemode, filemask=modemask, onerror=onerror):
- raise portage_exception.OperationNotPermitted(
+ raise portage.exception.OperationNotPermitted(
"Failed to apply recursive permissions for the portage group.")
- except portage_exception.PortageException, e:
+ except portage.exception.PortageException, e:
pass
def close_caches(self):
myManifestPath = "/".join(myebuild.split("/")[:-1])+"/Manifest"
if "gpg" in self.mysettings.features:
try:
- mys = portage_gpg.fileStats(myManifestPath)
+ mys = portage.gpg.fileStats(myManifestPath)
if (myManifestPath in self.manifestCache) and \
(self.manifestCache[myManifestPath] == mys):
pass
elif self.manifestVerifier:
if not self.manifestVerifier.verify(myManifestPath):
# Verification failed the desired level.
- raise portage_exception.UntrustedSignature, "Untrusted Manifest: %(manifest)s" % {"manifest":myManifestPath}
+ raise portage.exception.UntrustedSignature, "Untrusted Manifest: %(manifest)s" % {"manifest":myManifestPath}
if ("severe" in self.mysettings.features) and \
- (mys != portage_gpg.fileStats(myManifestPath)):
- raise portage_exception.SecurityViolation, "Manifest changed: %(manifest)s" % {"manifest":myManifestPath}
+ (mys != portage.gpg.fileStats(myManifestPath)):
+ raise portage.exception.SecurityViolation, "Manifest changed: %(manifest)s" % {"manifest":myManifestPath}
- except portage_exception.InvalidSignature, e:
+ except portage.exception.InvalidSignature, e:
if ("strict" in self.mysettings.features) or \
("severe" in self.mysettings.features):
raise
writemsg("!!! INVALID MANIFEST SIGNATURE DETECTED: %(manifest)s\n" % {"manifest":myManifestPath})
- except portage_exception.MissingSignature, e:
+ except portage.exception.MissingSignature, e:
if ("severe" in self.mysettings.features):
raise
if ("strict" in self.mysettings.features):
if myManifestPath not in self.manifestMissingCache:
writemsg("!!! WARNING: Missing signature in: %(manifest)s\n" % {"manifest":myManifestPath})
self.manifestMissingCache.insert(0,myManifestPath)
- except (OSError,portage_exception.FileNotFound), e:
+ except (OSError,portage.exception.FileNotFound), e:
if ("strict" in self.mysettings.features) or \
("severe" in self.mysettings.features):
- raise portage_exception.SecurityViolation, "Error in verification of signatures: %(errormsg)s" % {"errormsg":str(e)}
+ raise portage.exception.SecurityViolation, "Error in verification of signatures: %(errormsg)s" % {"errormsg":str(e)}
writemsg("!!! Manifest is missing or inaccessable: %(manifest)s\n" % {"manifest":myManifestPath},
noiselevel=-1)
if useflags is None:
useflags = mysettings["USE"].split()
- myurilist = portage_dep.paren_reduce(myuris)
- myurilist = portage_dep.use_reduce(myurilist,uselist=useflags,matchall=all)
+ myurilist = portage.dep.paren_reduce(myuris)
+ myurilist = portage.dep.use_reduce(myurilist,uselist=useflags,matchall=all)
newuris = flatten(myurilist)
myfiles = []
reason = "digest missing"
else:
try:
- ok, reason = portage_checksum.verify_all(
+ ok, reason = portage.checksum.verify_all(
os.path.join(self.mysettings["DISTDIR"], x), mysums[x])
- except portage_exception.FileNotFound, e:
+ except portage.exception.FileNotFound, e:
ok = False
reason = "File Not Found: '%s'" % str(e)
if not ok:
else:
print "ERROR: xmatch doesn't handle",level,"query!"
raise KeyError
- myslot = portage_dep.dep_getslot(mydep)
+ myslot = portage.dep.dep_getslot(mydep)
if myslot is not None:
slotmatches = []
for cpv in myval:
keys, eapi = self.aux_get(mycpv, ["KEYWORDS", "EAPI"])
except KeyError:
continue
- except portage_exception.PortageException, e:
+ except portage.exception.PortageException, e:
writemsg("!!! Error: aux_get('%s', ['KEYWORDS', 'EAPI'])\n" % \
mycpv, noiselevel=-1)
writemsg("!!! %s\n" % str(e), noiselevel=-1)
# sanity check
for cp in [origcp,newcp]:
if not (isvalidatom(cp) and isjustname(cp)):
- raise portage_exception.InvalidPackageName(cp)
+ raise portage.exception.InvalidPackageName(cp)
origcat = origcp.split("/")[0]
mynewcat=newcp.split("/")[0]
origmatches=self.dbapi.cp_list(origcp)
newslot=mylist[3]
if not isvalidatom(pkg):
- raise portage_exception.InvalidAtom(pkg)
+ raise portage.exception.InvalidAtom(pkg)
origmatches=self.dbapi.match(pkg)
if not origmatches:
raise ValueError
self.myroot=myroot
- protect_obj = portage_util.ConfigProtect(myroot + EPREFIX,
+ protect_obj = portage.util.ConfigProtect(myroot,
mysettings.get("CONFIG_PROTECT","").split(),
mysettings.get("CONFIG_PROTECT_MASK","").split())
self.updateprotect = protect_obj.updateprotect
if self._lock_vdb:
raise AssertionError("Lock already held.")
# At least the parent needs to exist for the lock file.
- portage_util.ensure_dirs(self.dbroot)
- self._lock_vdb = portage_locks.lockdir(self.dbroot)
+ portage.util.ensure_dirs(self.dbroot)
+ self._lock_vdb = portage.locks.lockdir(self.dbroot)
def unlockdb(self):
if self._lock_vdb:
- portage_locks.unlockdir(self._lock_vdb)
+ portage.locks.unlockdir(self._lock_vdb)
self._lock_vdb = None
def getpath(self):
try:
doebuild_environment(myebuildpath, "prerm", self.myroot,
self.settings, 0, 0, self.vartree.dbapi)
- except portage_exception.UnsupportedAPIException, e:
+ except portage.exception.UnsupportedAPIException, e:
# Sometimes this happens due to corruption of the EAPI file.
writemsg("!!! FAILED prerm: %s\n" % \
os.path.join(self.dbdir, "EAPI"), noiselevel=-1)
writemsg("%s\n" % str(e), noiselevel=-1)
return 1
catdir = os.path.dirname(self.settings["PORTAGE_BUILDDIR"])
- portage_util.ensure_dirs(os.path.dirname(catdir),
+ portage.util.ensure_dirs(os.path.dirname(catdir),
uid=portage_uid, gid=portage_gid, mode=070, mask=0)
builddir_lock = None
catdir_lock = None
try:
if myebuildpath:
- catdir_lock = portage_locks.lockdir(catdir)
- portage_util.ensure_dirs(catdir,
+ catdir_lock = portage.locks.lockdir(catdir)
+ portage.util.ensure_dirs(catdir,
uid=portage_uid, gid=portage_gid,
mode=070, mask=0)
- builddir_lock = portage_locks.lockdir(
+ builddir_lock = portage.locks.lockdir(
self.settings["PORTAGE_BUILDDIR"])
try:
- portage_locks.unlockdir(catdir_lock)
+ portage.locks.unlockdir(catdir_lock)
finally:
catdir_lock = None
# Eventually, we'd like to pass in the saved ebuild env here...
finally:
if builddir_lock:
- portage_locks.unlockdir(builddir_lock)
+ portage.locks.unlockdir(builddir_lock)
try:
if myebuildpath and not catdir_lock:
# Lock catdir for removal if empty.
- catdir_lock = portage_locks.lockdir(catdir)
+ catdir_lock = portage.locks.lockdir(catdir)
finally:
if catdir_lock:
try:
if e.errno != errno.ENOTEMPTY:
raise
del e
- portage_locks.unlockdir(catdir_lock)
+ portage.locks.unlockdir(catdir_lock)
env_update(target_root=self.myroot, prev_mtimes=ldpath_mtimes,
contents=contents)
return os.EX_OK
continue
mymd5 = None
try:
- mymd5 = portage_checksum.perform_md5(obj, calc_prelink=1)
- except portage_exception.FileNotFound, e:
+ mymd5 = portage.checksum.perform_md5(obj, calc_prelink=1)
+ except portage.exception.FileNotFound, e:
# the file has disappeared between now and our stat call
writemsg_stdout("--- !obj %s %s\n" % ("obj", obj))
continue
elif self.isprotected(mydest):
# Use md5 of the target in ${D} if it exists...
try:
- newmd5 = portage_checksum.perform_md5(
+ newmd5 = portage.checksum.perform_md5(
join(srcroot, myabsto))
- except portage_exception.FileNotFound:
+ except portage.exception.FileNotFound:
# Maybe the target is merged already.
try:
- newmd5 = portage_checksum.perform_md5(
+ newmd5 = portage.checksum.perform_md5(
myrealto)
- except portage_exception.FileNotFound:
+ except portage.exception.FileNotFound:
newmd5 = None
mydest = new_protect_filename(mydest,newmd5=newmd5)
return 1
elif stat.S_ISREG(mymode):
# we are merging a regular file
- mymd5=portage_checksum.perform_md5(mysrc,calc_prelink=1)
+ mymd5=portage.checksum.perform_md5(mysrc,calc_prelink=1)
# calculate config file protection stuff
mydestdir=os.path.dirname(mydest)
moveme=1
# we only need to tweak mydest if cfg file management is in play.
if self.isprotected(mydest):
# we have a protection path; enable config file management.
- destmd5=portage_checksum.perform_md5(mydest,calc_prelink=1)
+ destmd5=portage.checksum.perform_md5(mydest,calc_prelink=1)
if mymd5==destmd5:
#file already in place; simply update mtimes of destination
os.utime(mydest,(thismtime,thismtime))
# and now we're at the end. yay.
myf.close()
- mymd5 = portage_checksum.perform_md5(mydest, calc_prelink=1)
+ mymd5 = portage.checksum.perform_md5(mydest, calc_prelink=1)
os.utime(mydest,(thismtime,thismtime))
if mymtime!=None:
class FetchlistDict(UserDict.DictMixin):
"""This provide a mapping interface to retrieve fetch lists. It's used
- to allow portage_manifest.Manifest to access fetch lists via a standard
+ to allow portage.manifest.Manifest to access fetch lists via a standard
mapping interface rather than use the dbapi directly."""
def __init__(self, pkgdir, settings, mydbapi):
"""pkgdir is a directory containing ebuilds and settings is passed into
try:
""" Don't lock the tbz2 file because the filesytem could be readonly or
shared by a cluster."""
- #tbz2_lock = portage_locks.lockfile(mytbz2, wantnewlockfile=1)
+ #tbz2_lock = portage.locks.lockfile(mytbz2, wantnewlockfile=1)
mypkg = os.path.basename(mytbz2)[:-5]
xptbz2 = xpak.tbz2(mytbz2)
infloc = os.path.join(builddir, "build-info")
myebuild = os.path.join(
infloc, os.path.basename(mytbz2)[:-4] + "ebuild")
- portage_util.ensure_dirs(os.path.dirname(catdir),
+ portage.util.ensure_dirs(os.path.dirname(catdir),
uid=portage_uid, gid=portage_gid, mode=070, mask=0)
- catdir_lock = portage_locks.lockdir(catdir)
- portage_util.ensure_dirs(catdir,
+ catdir_lock = portage.locks.lockdir(catdir)
+ portage.util.ensure_dirs(catdir,
uid=portage_uid, gid=portage_gid, mode=070, mask=0)
- builddir_lock = portage_locks.lockdir(builddir)
+ builddir_lock = portage.locks.lockdir(builddir)
try:
- portage_locks.unlockdir(catdir_lock)
+ portage.locks.unlockdir(catdir_lock)
finally:
catdir_lock = None
try:
raise
del e
for mydir in (builddir, pkgloc, infloc):
- portage_util.ensure_dirs(mydir, uid=portage_uid,
+ portage.util.ensure_dirs(mydir, uid=portage_uid,
gid=portage_gid, mode=0755)
writemsg_stdout(">>> Extracting info\n")
xptbz2.unpackinfo(infloc)
mysettings.load_infodir(infloc)
# Store the md5sum in the vdb.
fp = open(os.path.join(infloc, "BINPKGMD5"), "w")
- fp.write(str(portage_checksum.perform_md5(mytbz2))+"\n")
+ fp.write(str(portage.checksum.perform_md5(mytbz2))+"\n")
fp.close()
debug = mysettings.get("PORTAGE_DEBUG", "") == "1"
return retval
writemsg_stdout(">>> Extracting %s\n" % mypkg)
- retval = portage_exec.spawn_bash(
+ retval = portage.process.spawn_bash(
"bzip2 -dqc -- '%s' | tar -xp -C '%s' -f -" % (mytbz2, pkgloc),
env=mysettings.environ())
if retval != os.EX_OK:
writemsg("!!! Error Extracting '%s'\n" % mytbz2, noiselevel=-1)
return retval
- #portage_locks.unlockfile(tbz2_lock)
+ #portage.locks.unlockfile(tbz2_lock)
#tbz2_lock = None
mylink = dblink(mycat, mypkg, myroot, mysettings, vartree=vartree,
return retval
finally:
if tbz2_lock:
- portage_locks.unlockfile(tbz2_lock)
+ portage.locks.unlockfile(tbz2_lock)
if builddir_lock:
try:
shutil.rmtree(builddir)
if e.errno != errno.ENOENT:
raise
del e
- portage_locks.unlockdir(builddir_lock)
+ portage.locks.unlockdir(builddir_lock)
try:
if not catdir_lock:
# Lock catdir for removal if empty.
- catdir_lock = portage_locks.lockdir(catdir)
+ catdir_lock = portage.locks.lockdir(catdir)
finally:
if catdir_lock:
try:
if e.errno != errno.ENOTEMPTY:
raise
del e
- portage_locks.unlockdir(catdir_lock)
+ portage.locks.unlockdir(catdir_lock)
def deprecated_profile_check():
if not os.access(DEPRECATED_PROFILE_FILE, os.R_OK):
f = atomic_ofstream(filename)
cPickle.dump(d, f, -1)
f.close()
- portage_util.apply_secpass_permissions(filename, uid=uid, gid=portage_gid, mode=0664)
+ portage.util.apply_secpass_permissions(filename, uid=uid, gid=portage_gid, mode=0664)
except (IOError, OSError), e:
pass
update_data = grab_updates(updpath)
else:
update_data = grab_updates(updpath, prev_mtimes)
- except portage_exception.DirectoryNotFound:
+ except portage.exception.DirectoryNotFound:
writemsg("--- 'profiles/updates' is empty or not available. Empty portage tree?\n")
return
myupd = None
del trees[myroot]["porttree"], myroot, portdb
settings = config(config_root=config_root, target_root=target_root,
- config_incrementals=portage_const.INCREMENTALS)
+ config_incrementals=portage.const.INCREMENTALS)
settings.lock()
settings.validate()
myroots = [(settings["ROOT"], settings)]
if settings["ROOT"] != "/":
settings = config(config_root=None, target_root=None,
- config_incrementals=portage_const.INCREMENTALS)
+ config_incrementals=portage.const.INCREMENTALS)
settings.lock()
settings.validate()
myroots.append((settings["ROOT"], settings))
for myroot, mysettings in myroots:
- trees[myroot] = portage_util.LazyItemsDict(trees.get(myroot, None))
+ trees[myroot] = portage.util.LazyItemsDict(trees.get(myroot, None))
trees[myroot].addLazySingleton("virtuals", mysettings.getvirtuals, myroot)
trees[myroot].addLazySingleton(
"vartree", vartree, myroot, categories=mysettings.categories,
# portage.py -- core Portage functionality
# Copyright 1998-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: portage_exec.py 3483 2006-06-10 21:40:40Z genone $
+# $Id$
import os, atexit, signal, sys
-import portage_data
+import portage.data
-from portage_util import dump_traceback
-from portage_const import BASH_BINARY, SANDBOX_BINARY
+from portage.util import dump_traceback
+from portage.const import BASH_BINARY, SANDBOX_BINARY
try:
except SystemExit:
exc_info = sys.exc_info()
except: # No idea what they called, so we need this broad except here.
- dump_traceback("Error in portage_exec.run_exitfuncs", noiselevel=0)
+ dump_traceback("Error in portage.process.run_exitfuncs", noiselevel=0)
exc_info = sys.exc_info()
if exc_info is not None:
if os.access(filename, os.X_OK) and os.path.isfile(filename):
return filename
return None
+=======
+# portage.py -- core Portage functionality
+# Copyright 1998-2004 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+
+import os, atexit, signal, sys
+import portage.data
+
+from portage.util import dump_traceback
+from portage.const import BASH_BINARY, SANDBOX_BINARY
+
+
+try:
+ import resource
+ max_fd_limit = resource.getrlimit(resource.RLIMIT_NOFILE)[0]
+except ImportError:
+ max_fd_limit = 256
+
+if os.path.isdir("/proc/%i/fd" % os.getpid()):
+ def get_open_fds():
+ return map(int, [fd for fd in os.listdir("/proc/%i/fd" % os.getpid()) if fd.isdigit()])
+else:
+ def get_open_fds():
+ return xrange(max_fd_limit)
+
+sandbox_capable = (os.path.isfile(SANDBOX_BINARY) and
+ os.access(SANDBOX_BINARY, os.X_OK))
+
+def spawn_bash(mycommand, debug=False, opt_name=None, **keywords):
+ """
+ Spawns a bash shell running a specific commands
+
+ @param mycommand: The command for bash to run
+ @type mycommand: String
+ @param debug: Turn bash debugging on (set -x)
+ @type debug: Boolean
+ @param opt_name: Name of the spawned process (detaults to binary name)
+ @type opt_name: String
+ @param keywords: Extra Dictionary arguments to pass to spawn
+ @type keywords: Dictionary
+ """
+
+ args = [BASH_BINARY]
+ if not opt_name:
+ opt_name = os.path.basename(mycommand.split()[0])
+ if debug:
+ # Print commands and their arguments as they are executed.
+ args.append("-x")
+ args.append("-c")
+ args.append(mycommand)
+ return spawn(args, opt_name=opt_name, **keywords)
+
+def spawn_sandbox(mycommand, opt_name=None, **keywords):
+ if not sandbox_capable:
+ return spawn_bash(mycommand, opt_name=opt_name, **keywords)
+ args=[SANDBOX_BINARY]
+ if not opt_name:
+ opt_name = os.path.basename(mycommand.split()[0])
+ args.append(mycommand)
+ return spawn(args, opt_name=opt_name, **keywords)
+
+_exithandlers = []
+def atexit_register(func, *args, **kargs):
+ """Wrapper around atexit.register that is needed in order to track
+ what is registered. For example, when portage restarts itself via
+ os.execv, the atexit module does not work so we have to do it
+ manually by calling the run_exitfuncs() function in this module."""
+ _exithandlers.append((func, args, kargs))
+
+def run_exitfuncs():
+ """This should behave identically to the routine performed by
+ the atexit module at exit time. It's only necessary to call this
+ function when atexit will not work (because of os.execv, for
+ example)."""
+
+ # This function is a copy of the private atexit._run_exitfuncs()
+ # from the python 2.4.2 sources. The only difference from the
+ # original function is in the output to stderr.
+ exc_info = None
+ while _exithandlers:
+ func, targs, kargs = _exithandlers.pop()
+ try:
+ func(*targs, **kargs)
+ except SystemExit:
+ exc_info = sys.exc_info()
+ except: # No idea what they called, so we need this broad except here.
+ dump_traceback("Error in portage.process.run_exitfuncs", noiselevel=0)
+ exc_info = sys.exc_info()
+
+ if exc_info is not None:
+ raise exc_info[0], exc_info[1], exc_info[2]
+
+atexit.register(run_exitfuncs)
+
+# We need to make sure that any processes spawned are killed off when
+# we exit. spawn() takes care of adding and removing pids to this list
+# as it creates and cleans up processes.
+spawned_pids = []
+def cleanup():
+ while spawned_pids:
+ pid = spawned_pids.pop()
+ try:
+ if os.waitpid(pid, os.WNOHANG) == (0, 0):
+ os.kill(pid, signal.SIGTERM)
+ os.waitpid(pid, 0)
+ except OSError:
+ # This pid has been cleaned up outside
+ # of spawn().
+ pass
+
+atexit_register(cleanup)
+
+def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
+ uid=None, gid=None, groups=None, umask=None, logfile=None,
+ path_lookup=True):
+ """
+ Spawns a given command.
+
+ @param mycommand: the command to execute
+ @type mycommand: String or List (Popen style list)
+ @param env: A dict of Key=Value pairs for env variables
+ @type env: Dictionary
+ @param opt_name: an optional name for the spawn'd process (defaults to the binary name)
+ @type opt_name: String
+ @param fd_pipes: A dict of mapping for pipes, { '0': stdin, '1': stdout } for example
+ @type fd_pipes: Dictionary
+ @param returnpid: Return the Process IDs for a successful spawn.
+ NOTE: This requires the caller clean up all the PIDs, otherwise spawn will clean them.
+ @type returnpid: Boolean
+ @param uid: User ID to spawn as; useful for dropping privilages
+ @type uid: Integer
+ @param gid: Group ID to spawn as; useful for dropping privilages
+ @type gid: Integer
+ @param groups: Group ID's to spawn in: useful for having the process run in multiple group contexts.
+ @type groups: List
+ @param umask: An integer representing the umask for the process (see man chmod for umask details)
+ @type umask: Integer
+ @param logfile: name of a file to use for logging purposes
+ @type logfile: String
+ @param path_lookup: If the binary is not fully specified then look for it in PATH
+ @type path_lookup: Boolean
+
+ logfile requires stdout and stderr to be assigned to this process (ie not pointed
+ somewhere else.)
+
+ """
+
+ # mycommand is either a str or a list
+ if isinstance(mycommand, str):
+ mycommand = mycommand.split()
+
+ # If an absolute path to an executable file isn't given
+ # search for it unless we've been told not to.
+ binary = mycommand[0]
+ if (not os.path.isabs(binary) or not os.path.isfile(binary)
+ or not os.access(binary, os.X_OK)):
+ binary = path_lookup and find_binary(binary) or None
+ if not binary:
+ return -1
+
+ # If we haven't been told what file descriptors to use
+ # default to propogating our stdin, stdout and stderr.
+ if fd_pipes is None:
+ fd_pipes = {0:0, 1:1, 2:2}
+
+ # mypids will hold the pids of all processes created.
+ mypids = []
+
+ if logfile:
+ # Using a log file requires that stdout and stderr
+ # are assigned to the process we're running.
+ if 1 not in fd_pipes or 2 not in fd_pipes:
+ raise ValueError(fd_pipes)
+
+ # Create a pipe
+ (pr, pw) = os.pipe()
+
+ # Create a tee process, giving it our stdout and stderr
+ # as well as the read end of the pipe.
+ mypids.extend(spawn(('tee', '-i', '-a', logfile),
+ returnpid=True, fd_pipes={0:pr,
+ 1:fd_pipes[1], 2:fd_pipes[2]}))
+
+ # We don't need the read end of the pipe, so close it.
+ os.close(pr)
+
+ # Assign the write end of the pipe to our stdout and stderr.
+ fd_pipes[1] = pw
+ fd_pipes[2] = pw
+
+ pid = os.fork()
+
+ if not pid:
+ try:
+ _exec(binary, mycommand, opt_name, fd_pipes,
+ env, gid, groups, uid, umask)
+ except Exception, e:
+ # We need to catch _any_ exception so that it doesn't
+ # propogate out of this function and cause exiting
+ # with anything other than os._exit()
+ sys.stderr.write("%s:\n %s\n" % (e, " ".join(mycommand)))
+ sys.stderr.flush()
+ os._exit(1)
+
+ # Add the pid to our local and the global pid lists.
+ mypids.append(pid)
+ spawned_pids.append(pid)
+
+ # If we started a tee process the write side of the pipe is no
+ # longer needed, so close it.
+ if logfile:
+ os.close(pw)
+
+ # If the caller wants to handle cleaning up the processes, we tell
+ # it about all processes that were created.
+ if returnpid:
+ return mypids
+
+ # Otherwise we clean them up.
+ while mypids:
+
+ # Pull the last reader in the pipe chain. If all processes
+ # in the pipe are well behaved, it will die when the process
+ # it is reading from dies.
+ pid = mypids.pop(0)
+
+ # and wait for it.
+ retval = os.waitpid(pid, 0)[1]
+
+ # When it's done, we can remove it from the
+ # global pid list as well.
+ spawned_pids.remove(pid)
+
+ if retval:
+ # If it failed, kill off anything else that
+ # isn't dead yet.
+ for pid in mypids:
+ if os.waitpid(pid, os.WNOHANG) == (0,0):
+ os.kill(pid, signal.SIGTERM)
+ os.waitpid(pid, 0)
+ spawned_pids.remove(pid)
+
+ # If it got a signal, return the signal that was sent.
+ if (retval & 0xff):
+ return ((retval & 0xff) << 8)
+
+ # Otherwise, return its exit code.
+ return (retval >> 8)
+
+ # Everything succeeded
+ return 0
+
+def _exec(binary, mycommand, opt_name, fd_pipes, env, gid, groups, uid, umask):
+
+ """
+ Execute a given binary with options
+
+ @param binary: Name of program to execute
+ @type binary: String
+ @param mycommand: Options for program
+ @type mycommand: String
+ @param opt_name: Name of process (defaults to binary)
+ @type opt_name: String
+ @param fd_pipes: Mapping pipes to destination; { 0:0, 1:1, 2:2 }
+ @type fd_pipes: Dictionary
+ @param env: Key,Value mapping for Environmental Variables
+ @type env: Dictionary
+ @param gid: Group ID to run the process under
+ @type gid: Integer
+ @param groups: Groups the Process should be in.
+ @type groups: Integer
+ @param uid: User ID to run the process under
+ @type uid: Integer
+ @param umask: an int representing a unix umask (see man chmod for umask details)
+ @type umask: Integer
+ @rtype: None
+ @returns: Never returns (calls os.execve)
+ """
+
+ # If the process we're creating hasn't been given a name
+ # assign it the name of the executable.
+ if not opt_name:
+ opt_name = os.path.basename(binary)
+
+ # Set up the command's argument list.
+ myargs = [opt_name]
+ myargs.extend(mycommand[1:])
+
+ # Set up the command's pipes.
+ my_fds = {}
+ # To protect from cases where direct assignment could
+ # clobber needed fds ({1:2, 2:1}) we first dupe the fds
+ # into unused fds.
+ for fd in fd_pipes:
+ my_fds[fd] = os.dup(fd_pipes[fd])
+ # Then assign them to what they should be.
+ for fd in my_fds:
+ os.dup2(my_fds[fd], fd)
+ # Then close _all_ fds that haven't been explictly
+ # requested to be kept open.
+ for fd in get_open_fds():
+ if fd not in my_fds:
+ try:
+ os.close(fd)
+ except OSError:
+ pass
+
+ # Set requested process permissions.
+ if gid:
+ os.setgid(gid)
+ if groups:
+ os.setgroups(groups)
+ if uid:
+ os.setuid(uid)
+ if umask:
+ os.umask(umask)
+
+ # And switch to the new process.
+ os.execve(binary, myargs, env)
+
+def find_binary(binary):
+ """
+ Given a binary name, find the binary in PATH
+
+ @param binary: Name of the binary to find
+ @type string
+ @rtype: None or string
+ @returns: full path to binary or None if the binary could not be located.
+ """
+
+ for path in os.getenv("PATH", "").split(":"):
+ filename = "%s/%s" % (path, binary)
+ if os.access(filename, os.X_OK) and os.path.isfile(filename):
+ return filename
+ return None
+