# portage.py -- core Portage functionality
# Copyright 1998-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id$
+# $Id: portage.py 4664 2006-10-12 10:49:27Z zmedico $
VERSION="$Rev$"[6:-2] + "-svn"
mysettings, debug=debug, free=1, logfile=logfile)
mycpv = "/".join((mysettings["CATEGORY"], mysettings["PF"]))
+
# Make sure we get the correct tree in case there are overlays.
mytree = os.path.realpath(
os.path.dirname(os.path.dirname(mysettings["O"])))
# portage_checksum.py -- core Portage functionality
# Copyright 1998-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: /var/cvsroot/gentoo-src/portage/pym/portage_checksum.py,v 1.10.2.2 2005/08/10 05:42:03 ferringb Exp $
+# $Id: portage_checksum.py 3835 2006-07-11 00:59:10Z zmedico $
from portage_const import PRIVATE_PATH,PRELINK_BINARY,HASHING_BLOCKSIZE
if mydict["size"] != mysize:
return False,("Filesize does not match recorded size", mysize, mydict["size"])
except OSError, e:
- return False, str(e)
+ if e.errno == errno.ENOENT:
+ raise portage_exception.FileNotFound(filename)
+ return False, (str(e), None, None)
for x in mydict.keys():
if x == "size":
continue
# portage: Constants
# Copyright 1998-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: /var/cvsroot/gentoo-src/portage/pym/portage_const.py,v 1.3.2.3 2005/04/29 04:56:35 jstubbs Exp $
+# $Id: portage_const.py 3483 2006-06-10 21:40:40Z genone $
import os
# ===========================================================================
INVALID_ENV_FILE = "/etc/spork/is/not/valid/profile.env"
CUSTOM_MIRRORS_FILE = USER_CONFIG_PATH+"/mirrors"
CONFIG_MEMORY_FILE = PRIVATE_PATH + "/config"
+COLOR_MAP_FILE = USER_CONFIG_PATH + "/color.map"
INCREMENTALS=["USE","USE_EXPAND","USE_EXPAND_HIDDEN","FEATURES","ACCEPT_KEYWORDS","ACCEPT_LICENSE","CONFIG_PROTECT_MASK","CONFIG_PROTECT","PRELINK_PATH","PRELINK_PATH_MASK"]
-STICKIES=["KEYWORDS_ACCEPT","USE","CFLAGS","CXXFLAGS","MAKEOPTS","EXTRA_ECONF","EXTRA_EINSTALL","EXTRA_EMAKE"]
-EBUILD_PHASES = ["setup","unpack","compile","test","install","preinst","postinst","prerm","postrm"]
+EBUILD_PHASES = ["setup", "unpack", "compile", "test", "install",
+ "preinst", "postinst", "prerm", "postrm", "other"]
EAPI = "prefix"
# portage_data.py -- Calculated/Discovered Data Values
# Copyright 1998-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id$
+# $Id: portage_data.py 4530 2006-09-25 21:16:32Z zmedico $
import os,pwd,grp
# deps.py -- Portage dependency resolution functions
# Copyright 2003-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: /var/cvsroot/gentoo-src/portage/pym/portage_dep.py,v 1.15.2.3 2005/04/02 14:07:59 jstubbs Exp $
+# $Id: portage_dep.py 4598 2006-10-05 11:52:50Z zmedico $
# DEPEND SYNTAX:
# Copyright 1998-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: /var/cvsroot/gentoo-src/portage/pym/portage_exception.py,v 1.8.2.1 2005/01/16 02:35:33 carpaski Exp $
+# $Id: portage_exception.py 3483 2006-06-10 21:40:40Z genone $
class PortageException(Exception):
class OperationNotPermitted(PortageException):
"""An operation was not permitted operating system"""
+class PermissionDenied(PortageException):
+ """Permission denied"""
+
+class ReadOnlyFileSystem(PortageException):
+ """Read-only file system"""
+
class CommandNotFound(PortageException):
"""A required binary was not available or executable"""
# portage.py -- core Portage functionality
# Copyright 1998-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: /var/cvsroot/gentoo-src/portage/pym/portage_exec.py,v 1.13.2.4 2005/04/17 09:01:56 jstubbs Exp $
+# $Id: portage_exec.py 3483 2006-06-10 21:40:40Z genone $
import os, atexit, signal, sys
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))
os.dup2(my_fds[fd], fd)
# Then close _all_ fds that haven't been explictly
# requested to be kept open.
- for fd in range(max_fd_limit):
+ for fd in get_open_fds():
if fd not in my_fds:
try:
os.close(fd)
# portage_gpg.py -- core Portage functionality
# Copyright 2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: /var/cvsroot/gentoo-src/portage/pym/portage_gpg.py,v 1.6.2.1 2005/01/16 02:35:33 carpaski Exp $
+# $Id: portage_gpg.py 3483 2006-06-10 21:40:40Z genone $
import os
# portage_localization.py -- Code to manage/help portage localization.
# Copyright 2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: /var/cvsroot/gentoo-src/portage/pym/portage_localization.py,v 1.2.2.1 2005/01/16 02:35:33 carpaski Exp $
+# $Id: portage_localization.py 3483 2006-06-10 21:40:40Z genone $
# We define this to make the transition easier for us.
# portage: Lock management code
# Copyright 2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id$
+# $Id: portage_locks.py 4449 2006-09-14 07:52:39Z zmedico $
import errno
--- /dev/null
+# portage.py -- core Portage functionality
+# Copyright 1998-2004 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id: portage.py 3483 2006-06-10 21:40:40Z genone $
+
+import portage_exception, socket, smtplib, os, sys, time
+from email.MIMEText import MIMEText as TextMessage
+from email.MIMEMultipart import MIMEMultipart as MultipartMessage
+from email.MIMEBase import MIMEBase as BaseMessage
+
+def create_message(sender, recipient, subject, body, attachments=None):
+ if attachments == None:
+ mymessage = TextMessage(body)
+ else:
+ mymessage = MultipartMessage()
+ mymessage.attach(TextMessage(body))
+ for x in attachments:
+ if isinstance(x, BaseMessage):
+ mymessage.attach(x)
+ elif isinstance(x, str):
+ mymessage.attach(TextMessage(x))
+ else:
+ raise portage_exception.PortageException("Can't handle type of attachment: %s" % type(x))
+
+ mymessage.set_unixfrom(sender)
+ mymessage["To"] = recipient
+ mymessage["From"] = sender
+ mymessage["Subject"] = subject
+ mymessage["Date"] = time.strftime("%a, %d %b %Y %H:%M:%S %z")
+
+ return mymessage
+
+def send_mail(mysettings, message):
+ mymailhost = "localhost"
+ mymailport = 25
+ mymailuser = ""
+ mymailpasswd = ""
+ myrecipient = "root@localhost"
+
+ # Syntax for PORTAGE_ELOG_MAILURI (if defined):
+ # adress [[user:passwd@]mailserver[:port]]
+ # where adress: recipient adress
+ # user: username for smtp auth (defaults to none)
+ # passwd: password for smtp auth (defaults to none)
+ # mailserver: smtp server that should be used to deliver the mail (defaults to localhost)
+ # alternatively this can also be the absolute path to a sendmail binary if you don't want to use smtp
+ # port: port to use on the given smtp server (defaults to 25, values > 100000 indicate that starttls should be used on (port-100000))
+ if " " in mysettings["PORTAGE_ELOG_MAILURI"]:
+ myrecipient, mymailuri = mysettings["PORTAGE_ELOG_MAILURI"].split()
+ if "@" in mymailuri:
+ myauthdata, myconndata = mymailuri.rsplit("@", 1)
+ try:
+ mymailuser,mymailpasswd = myauthdata.split(":")
+ except ValueError:
+ print "!!! invalid SMTP AUTH configuration, trying unauthenticated ..."
+ else:
+ myconndata = mymailuri
+ if ":" in myconndata:
+ mymailhost,mymailport = myconndata.split(":")
+ else:
+ mymailhost = myconndata
+ else:
+ myrecipient = mysettings["PORTAGE_ELOG_MAILURI"]
+
+ myfrom = message.get("From")
+
+ # user wants to use a sendmail binary instead of smtp
+ if mymailhost[0] == os.sep and os.path.exists(mymailhost):
+ fd = os.popen(mymailhost+" -f "+myfrom+" "+myrecipient, "w")
+ fd.write(message.as_string())
+ if fd.close() != None:
+ sys.stderr.write("!!! %s returned with a non-zero exit code. This generally indicates an error.\n" % mymailhost)
+ else:
+ try:
+ if int(mymailport) > 100000:
+ myconn = smtplib.SMTP(mymailhost, int(mymailport) - 100000)
+ myconn.starttls()
+ else:
+ myconn = smtplib.SMTP(mymailhost, mymailport)
+ if mymailuser != "" and mymailpasswd != "":
+ myconn.login(mymailuser, mymailpasswd)
+ myconn.sendmail(myfrom, myrecipient, message.as_string())
+ myconn.quit()
+ except smtplib.SMTPException, e:
+ raise portage_exception.PortageException("!!! An error occured while trying to send logmail:\n"+str(e))
+ except socket.error, e:
+ raise portage_exception.PortageException("!!! A network error occured while trying to send logmail:\n"+str(e)+"\nSure you configured PORTAGE_ELOG_MAILURI correctly?")
+ return
+
--- /dev/null
+# Copyright 1999-2006 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
+
+import selinux
+from selinux import is_selinux_enabled
+from selinux_aux import setexec, secure_symlink, secure_rename, \
+ secure_copy, secure_mkdir, getcontext, get_sid, get_lsid
+# Copyright 1999-2006 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
import errno, os, re, sys
# Copyright 2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id$
+# $Id: portage_util.py 4603 2006-10-06 03:28:25Z zmedico $
from portage_exception import PortageException, FileNotFound, \
OperationNotPermitted, PermissionDenied, ReadOnlyFileSystem
#invalid token
#lex.error_leader(self.filename,lex.lineno)
if not tolerant:
- writemsg("!!! invalid token (not \"=\") "+str(equ)+"\n",
+ writemsg("!!! Invalid token (not \"=\") "+str(equ)+"\n",
noiselevel=-1)
raise Exception("ParseError: Invalid token (not '='): "+str(mycfg)+": line "+str(lex.lineno))
else:
ver_regexp = re.compile("^(cvs\\.)?(\\d+)((\\.\\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\\d*)*)(-r(\\d+))?$")
suffix_regexp = re.compile("^(alpha|beta|rc|pre|p)(\\d*)$")
suffix_value = {"pre": -2, "p": 0, "alpha": -4, "beta": -3, "rc": -1}
+endversion_keys = ["pre", "p", "alpha", "beta", "rc"]
+
def ververify(myver, silent=1):
if ver_regexp.match(myver):