From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1NlSDx-0004UU-9k for garchives@archives.gentoo.org; Sat, 27 Feb 2010 19:21:15 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DBA0DE07A9; Sat, 27 Feb 2010 19:21:11 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 62B98E07A9 for ; Sat, 27 Feb 2010 19:21:11 +0000 (UTC) Received: from stork.gentoo.org (stork.gentoo.org [64.127.104.133]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTP id DE412672A1 for ; Sat, 27 Feb 2010 19:21:10 +0000 (UTC) Received: from grobian by stork.gentoo.org with local (Exim 4.69) (envelope-from ) id 1NlSDu-0000bs-HH for gentoo-commits@lists.gentoo.org; Sat, 27 Feb 2010 19:21:10 +0000 To: gentoo-commits@lists.gentoo.org From: "Fabian Groffen (grobian)" Subject: [gentoo-commits] portage r15481 - in main/branches/prefix: bin pym/_emerge pym/portage pym/portage/dbapi pym/portage/package/ebuild pym/portage/util X-VCS-Repository: portage X-VCS-Revision: 15481 X-VCS-Files: main/branches/prefix/pym/portage/util/ExtractKernelVersion.py main/branches/prefix/pym/portage/util/digestgen.py main/branches/prefix/pym/portage/util/env_update.py main/branches/prefix/bin/repoman main/branches/prefix/pym/_emerge/Scheduler.py main/branches/prefix/pym/portage/__init__.py main/branches/prefix/pym/portage/dbapi/vartree.py main/branches/prefix/pym/portage/package/ebuild/doebuild.py X-VCS-Directories: bin pym/_emerge pym/portage pym/portage/dbapi pym/portage/package/ebuild pym/portage/util X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen Content-Type: text/plain; charset=UTF-8 Message-Id: Sender: Fabian Groffen Date: Sat, 27 Feb 2010 19:21:10 +0000 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 564bb789-da5f-49a8-b956-226f2f76839d X-Archives-Hash: f232cb5acc0775f759aaf4eb5796a830 Author: grobian Date: 2010-02-27 19:21:09 +0000 (Sat, 27 Feb 2010) New Revision: 15481 Added: main/branches/prefix/pym/portage/util/ExtractKernelVersion.py main/branches/prefix/pym/portage/util/digestgen.py main/branches/prefix/pym/portage/util/env_update.py Modified: main/branches/prefix/bin/repoman main/branches/prefix/pym/_emerge/Scheduler.py main/branches/prefix/pym/portage/__init__.py main/branches/prefix/pym/portage/dbapi/vartree.py main/branches/prefix/pym/portage/package/ebuild/doebuild.py Log: Merged from trunk -r15451:15455 | 15452 | Move env_update to portage.util.env_update.envupdate. = | | zmedico | = | =20 | 15453 | Move ExtractKernelVersion = | | zmedico | portage.util.ExtractKernelVersion. = | =20 | 15454 | Move digestgen to portage.util.digestgen. = | | zmedico | = | =20 | 15455 | Define 'long' for Python 3. = | | arfrever | = | Modified: main/branches/prefix/bin/repoman =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- main/branches/prefix/bin/repoman 2010-02-27 19:01:26 UTC (rev 15480) +++ main/branches/prefix/bin/repoman 2010-02-27 19:21:09 UTC (rev 15481) @@ -75,6 +75,7 @@ green, nocolor, red, turquoise, yellow from portage.output import ConsoleStyleFile, StyleWriter from portage.util import cmp_sort_key, writemsg_level +from portage.util.digestgen import digestgen =20 if sys.hexversion >=3D 0x3000000: basestring =3D str @@ -1011,7 +1012,7 @@ portage._doebuild_manifest_exempt_depend -=3D 1 =20 repoman_settings["O"] =3D checkdir - if not portage.digestgen(mysettings=3Drepoman_settings, myportdb=3Dpor= tdb): + if not digestgen(mysettings=3Drepoman_settings, myportdb=3Dportdb): print("Unable to generate manifest.") dofail =3D 1 if options.mode =3D=3D "manifest": @@ -2339,7 +2340,7 @@ mydone=3D[] if repolevel=3D=3D3: # In a package dir repoman_settings["O"] =3D startdir - portage.digestgen(mysettings=3Drepoman_settings, myportdb=3Dportdb) + digestgen(mysettings=3Drepoman_settings, myportdb=3Dportdb) elif repolevel=3D=3D2: # In a category dir for x in myfiles: xs=3Dx.split("/") @@ -2353,7 +2354,7 @@ repoman_settings["O"] =3D os.path.join(startdir, xs[0]) if not os.path.isdir(repoman_settings["O"]): continue - portage.digestgen(mysettings=3Drepoman_settings, myportdb=3Dportdb) + digestgen(mysettings=3Drepoman_settings, myportdb=3Dportdb) elif repolevel=3D=3D1: # repo-cvsroot print(green("RepoMan sez:"), "\"You're rather crazy... doing the enti= re repository.\"\n") for x in myfiles: @@ -2368,7 +2369,7 @@ repoman_settings["O"] =3D os.path.join(startdir, xs[0], xs[1]) if not os.path.isdir(repoman_settings["O"]): continue - portage.digestgen(mysettings=3Drepoman_settings, myportdb=3Dportdb) + digestgen(mysettings=3Drepoman_settings, myportdb=3Dportdb) else: print(red("I'm confused... I don't know where I am!")) sys.exit(1) Modified: main/branches/prefix/pym/_emerge/Scheduler.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- main/branches/prefix/pym/_emerge/Scheduler.py 2010-02-27 19:01:26 UTC= (rev 15480) +++ main/branches/prefix/pym/_emerge/Scheduler.py 2010-02-27 19:21:09 UTC= (rev 15481) @@ -24,6 +24,7 @@ from portage.sets import SETPREFIX from portage.sets.base import InternalPackageSet from portage.util import writemsg, writemsg_level +from portage.util.digestgen import digestgen =20 from _emerge.BinpkgPrefetcher import BinpkgPrefetcher from _emerge.Blocker import Blocker @@ -591,7 +592,7 @@ if ebuild_path is None: raise AssertionError("ebuild not found for '%s'" % x.cpv) pkgsettings['O'] =3D os.path.dirname(ebuild_path) - if not portage.digestgen(mysettings=3Dpkgsettings, myportdb=3Dportdb)= : + if not digestgen(mysettings=3Dpkgsettings, myportdb=3Dportdb): writemsg_level( "!!! Unable to generate manifest for '%s'.\n" \ % x.cpv, level=3Dlogging.ERROR, noiselevel=3D-1) Modified: main/branches/prefix/pym/portage/__init__.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- main/branches/prefix/pym/portage/__init__.py 2010-02-27 19:01:26 UTC = (rev 15480) +++ main/branches/prefix/pym/portage/__init__.py 2010-02-27 19:21:09 UTC = (rev 15481) @@ -42,8 +42,6 @@ # which is unavailable. from StringIO import StringIO =20 - from time import sleep - from itertools import chain import platform import warnings =20 @@ -121,7 +119,10 @@ 'pickle_read,pickle_write,stack_dictlist,stack_dicts,' + \ 'stack_lists,unique_array,varexpand,writedict,writemsg,' + \ 'writemsg_stdout,write_atomic', + 'portage.util.digestgen:digestgen', 'portage.util.digraph:digraph', + 'portage.util.env_update:env_update', + 'portage.util.ExtractKernelVersion:ExtractKernelVersion', 'portage.util.listdir:cacheddir,listdir', 'portage.versions', 'portage.versions:best,catpkgsplit,catsplit,cpv_getkey,' + \ @@ -535,529 +536,6 @@ mylink=3Dmydir+"/"+mylink return os.path.normpath(mylink) =20 -#parse /etc/env.d and generate /etc/profile.env - -def env_update(makelinks=3D1, target_root=3DNone, prev_mtimes=3DNone, co= ntents=3DNone, - env=3DNone, writemsg_level=3DNone): - if writemsg_level is None: - writemsg_level =3D portage.util.writemsg_level - if target_root is None: - global settings - target_root =3D settings["ROOT"] - if prev_mtimes is None: - global mtimedb - prev_mtimes =3D mtimedb["ldpath"] - if env is None: - env =3D os.environ - envd_dir =3D os.path.join(target_root, EPREFIX_LSTRIP, "etc", "env.d") - portage.util.ensure_dirs(envd_dir, mode=3D0o755) - fns =3D listdir(envd_dir, EmptyOnError=3D1) - fns.sort() - templist =3D [] - for x in fns: - if len(x) < 3: - continue - if not x[0].isdigit() or not x[1].isdigit(): - continue - if x.startswith(".") or x.endswith("~") or x.endswith(".bak"): - continue - templist.append(x) - fns =3D templist - del templist - - space_separated =3D set(["CONFIG_PROTECT", "CONFIG_PROTECT_MASK"]) - colon_separated =3D set(["ADA_INCLUDE_PATH", "ADA_OBJECTS_PATH", - "CLASSPATH", "INFODIR", "INFOPATH", "KDEDIRS", "LDPATH", "MANPATH", - "PATH", "PKG_CONFIG_PATH", "PRELINK_PATH", "PRELINK_PATH_MASK", - "PYTHONPATH", "ROOTPATH"]) - - config_list =3D [] - - for x in fns: - file_path =3D os.path.join(envd_dir, x) - try: - myconfig =3D getconfig(file_path, expand=3DFalse) - except portage.exception.ParseError as e: - writemsg("!!! '%s'\n" % str(e), noiselevel=3D-1) - del e - continue - if myconfig is None: - # broken symlink or file removed by a concurrent process - writemsg("!!! File Not Found: '%s'\n" % file_path, noiselevel=3D-1) - continue - - config_list.append(myconfig) - if "SPACE_SEPARATED" in myconfig: - space_separated.update(myconfig["SPACE_SEPARATED"].split()) - del myconfig["SPACE_SEPARATED"] - if "COLON_SEPARATED" in myconfig: - colon_separated.update(myconfig["COLON_SEPARATED"].split()) - del myconfig["COLON_SEPARATED"] - - env =3D {} - specials =3D {} - for var in space_separated: - mylist =3D [] - for myconfig in config_list: - if var in myconfig: - for item in myconfig[var].split(): - if item and not item in mylist: - mylist.append(item) - del myconfig[var] # prepare for env.update(myconfig) - if mylist: - env[var] =3D " ".join(mylist) - specials[var] =3D mylist - - for var in colon_separated: - mylist =3D [] - for myconfig in config_list: - if var in myconfig: - for item in myconfig[var].split(":"): - if item and not item in mylist: - mylist.append(item) - del myconfig[var] # prepare for env.update(myconfig) - if mylist: - env[var] =3D ":".join(mylist) - specials[var] =3D mylist - - for myconfig in config_list: - """Cumulative variables have already been deleted from myconfig so tha= t - they won't be overwritten by this dict.update call.""" - env.update(myconfig) -=09 - if EPREFIX =3D=3D '': - sleep_for_mtime_granularity =3D dolinkingstuff( - target_root, specials, prelink_capable, - makelinks, contents, prev_mtimes, env) - else: - sleep_for_mtime_granularity =3D False - writeshellprofile(target_root, env, sleep_for_mtime_granularity) - -def dolinkingstuff(target_root, specials, prelink_capable, makelinks, - contents, prev_mtimes, env): - # updating this stuff will never work in an offset, other than ROOT - # (e.g. not in Prefix), hence the EPREFIX is not taken into account - # here since this code should never be triggered on an offset install - ldsoconf_path =3D os.path.join(target_root, "etc", "ld.so.conf") - try: - myld =3D codecs.open(_unicode_encode(ldsoconf_path, - encoding=3D_encodings['fs'], errors=3D'strict'), - mode=3D'r', encoding=3D_encodings['content'], errors=3D'replace') - myldlines=3Dmyld.readlines() - myld.close() - oldld=3D[] - for x in myldlines: - #each line has at least one char (a newline) - if x[0]=3D=3D"#": - continue - oldld.append(x[:-1]) - except (IOError, OSError) as e: - if e.errno !=3D errno.ENOENT: - raise - oldld =3D None - - ld_cache_update=3DFalse - - newld =3D specials["LDPATH"] - if (oldld!=3Dnewld): - #ld.so.conf needs updating and ldconfig needs to be run - myfd =3D atomic_ofstream(ldsoconf_path) - myfd.write("# ld.so.conf autogenerated by env-update; make all changes= to\n") - myfd.write("# contents of /etc/env.d directory\n") - for x in specials["LDPATH"]: - myfd.write(x+"\n") - myfd.close() - ld_cache_update=3DTrue - - # Update prelink.conf if we are prelink-enabled - if prelink_capable: - newprelink =3D atomic_ofstream( - os.path.join(target_root, "etc", "prelink.conf")) - newprelink.write("# prelink.conf autogenerated by env-update; make all= changes to\n") - newprelink.write("# contents of /etc/env.d directory\n") - - for x in ["/bin","/sbin","/usr/bin","/usr/sbin","/lib","/usr/lib"]: - newprelink.write("-l "+x+"\n"); - for x in specials["LDPATH"]+specials["PATH"]+specials["PRELINK_PATH"]: - if not x: - continue - if x[-1]!=3D'/': - x=3Dx+"/" - plmasked=3D0 - for y in specials["PRELINK_PATH_MASK"]: - if not y: - continue - if y[-1]!=3D'/': - y=3Dy+"/" - if y=3D=3Dx[0:len(y)]: - plmasked=3D1 - break - if not plmasked: - newprelink.write("-h "+x+"\n") - for x in specials["PRELINK_PATH_MASK"]: - newprelink.write("-b "+x+"\n") - newprelink.close() - - # Portage stores mtimes with 1 second granularity but in >=3Dpython-2.5= finer - # granularity is possible. In order to avoid the potential ambiguity o= f - # mtimes that differ by less than 1 second, sleep here if any of the - # directories have been modified during the current second. - sleep_for_mtime_granularity =3D False - current_time =3D long(time.time()) - mtime_changed =3D False - lib_dirs =3D set() - for lib_dir in portage.util.unique_array(specials["LDPATH"]+['usr/lib',= 'usr/lib64','usr/lib32','lib','lib64','lib32']): - x =3D os.path.join(target_root, lib_dir.lstrip(os.sep)) - try: - newldpathtime =3D os.stat(x)[stat.ST_MTIME] - lib_dirs.add(normalize_path(x)) - except OSError as oe: - if oe.errno =3D=3D errno.ENOENT: - try: - del prev_mtimes[x] - except KeyError: - pass - # ignore this path because it doesn't exist - continue - raise - if newldpathtime =3D=3D current_time: - sleep_for_mtime_granularity =3D True - if x in prev_mtimes: - if prev_mtimes[x] =3D=3D newldpathtime: - pass - else: - prev_mtimes[x] =3D newldpathtime - mtime_changed =3D True - else: - prev_mtimes[x] =3D newldpathtime - mtime_changed =3D True - - if mtime_changed: - ld_cache_update =3D True - - if makelinks and \ - not ld_cache_update and \ - contents is not None: - libdir_contents_changed =3D False - for mypath, mydata in contents.items(): - if mydata[0] not in ("obj","sym"): - continue - head, tail =3D os.path.split(mypath) - if head in lib_dirs: - libdir_contents_changed =3D True - break - if not libdir_contents_changed: - makelinks =3D False - - ldconfig =3D "/sbin/ldconfig" - if "CHOST" in env and "CBUILD" in env and \ - env["CHOST"] !=3D env["CBUILD"]: - from portage.process import find_binary - ldconfig =3D find_binary("%s-ldconfig" % env["CHOST"]) - - # Only run ldconfig as needed - if (ld_cache_update or makelinks) and ldconfig: - # ldconfig has very different behaviour between FreeBSD and Linux - if ostype=3D=3D"Linux" or ostype.lower().endswith("gnu"): - # We can't update links if we haven't cleaned other versions first, a= s - # an older package installed ON TOP of a newer version will cause ldc= onfig - # to overwrite the symlinks we just made. -X means no links. After 'c= lean' - # we can safely create links. - writemsg_level(_(">>> Regenerating %setc/ld.so.cache...\n") % \ - (target_root,)) - if makelinks: - os.system("cd / ; %s -r '%s'" % (ldconfig, target_root)) - else: - os.system("cd / ; %s -X -r '%s'" % (ldconfig, target_root)) - elif ostype in ("FreeBSD","DragonFly"): - writemsg_level(_(">>> Regenerating %svar/run/ld-elf.so.hints...\n") %= \ - target_root) - os.system(("cd / ; %s -elf -i " + \ - "-f '%svar/run/ld-elf.so.hints' '%setc/ld.so.conf'") % \ - (ldconfig, target_root, target_root)) - - del specials["LDPATH"] - - return sleep_for_mtime_granularity - -def writeshellprofile(target_root, env, sleep_for_mtime_granularity): - penvnotice =3D "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\= n" - penvnotice +=3D "# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES\n= " - cenvnotice =3D penvnotice[:] - penvnotice +=3D "# GO INTO "+EPREFIX+"/etc/profile NOT "+EPREFIX+"/etc/= profile.env\n\n" - cenvnotice +=3D "# GO INTO "+EPREFIX+"/etc/csh.cshrc NOT "+EPREFIX+"/et= c/csh.env\n\n" - - #create /etc/profile.env for bash support - outfile =3D atomic_ofstream(os.path.join(target_root, EPREFIX_LSTRIP, "= etc", "profile.env")) - outfile.write(penvnotice) - - env_keys =3D [ x for x in env if x !=3D "LDPATH" ] - env_keys.sort() - for k in env_keys: - v =3D env[k] - if v.startswith('$') and not v.startswith('${'): - outfile.write("export %s=3D$'%s'\n" % (k, v[1:])) - else: - outfile.write("export %s=3D'%s'\n" % (k, v)) - outfile.close() - - #create /etc/csh.env for (t)csh support - outfile =3D atomic_ofstream(os.path.join(target_root, EPREFIX_LSTRIP, "= etc", "csh.env")) - outfile.write(cenvnotice) - for x in env_keys: - outfile.write("setenv %s '%s'\n" % (x, env[x])) - outfile.close() - - if sleep_for_mtime_granularity: - while current_time =3D=3D long(time.time()): - sleep(1) - -def ExtractKernelVersion(base_dir): - """ - Try to figure out what kernel version we are running - @param base_dir: Path to sources (usually /usr/src/linux) - @type base_dir: string - @rtype: tuple( version[string], error[string]) - @returns: - 1. tuple( version[string], error[string]) - Either version or error is populated (but never both) - - """ - lines =3D [] - pathname =3D os.path.join(base_dir, 'Makefile') - try: - f =3D codecs.open(_unicode_encode(pathname, - encoding=3D_encodings['fs'], errors=3D'strict'), mode=3D'r', - encoding=3D_encodings['content'], errors=3D'replace') - except OSError as details: - return (None, str(details)) - except IOError as details: - return (None, str(details)) - - try: - for i in range(4): - lines.append(f.readline()) - except OSError as details: - return (None, str(details)) - except IOError as details: - return (None, str(details)) - - lines =3D [l.strip() for l in lines] - - version =3D '' - - #XXX: The following code relies on the ordering of vars within the Make= file - for line in lines: - # split on the '=3D' then remove annoying whitespace - items =3D line.split("=3D") - items =3D [i.strip() for i in items] - if items[0] =3D=3D 'VERSION' or \ - items[0] =3D=3D 'PATCHLEVEL': - version +=3D items[1] - version +=3D "." - elif items[0] =3D=3D 'SUBLEVEL': - version +=3D items[1] - elif items[0] =3D=3D 'EXTRAVERSION' and \ - items[-1] !=3D items[0]: - version +=3D items[1] - - # Grab a list of files named localversion* and sort them - localversions =3D os.listdir(base_dir) - for x in range(len(localversions)-1,-1,-1): - if localversions[x][:12] !=3D "localversion": - del localversions[x] - localversions.sort() - - # Append the contents of each to the version string, stripping ALL whit= espace - for lv in localversions: - version +=3D "".join( " ".join( grabfile( base_dir+ "/" + lv ) ).split= () ) - - # Check the .config for a CONFIG_LOCALVERSION and append that too, also= stripping whitespace - kernelconfig =3D getconfig(base_dir+"/.config") - if kernelconfig and "CONFIG_LOCALVERSION" in kernelconfig: - version +=3D "".join(kernelconfig["CONFIG_LOCALVERSION"].split()) - - return (version,None) - -def digestgen(myarchives=3DNone, mysettings=3DNone, - overwrite=3DNone, manifestonly=3DNone, myportdb=3DNone): - """ - Generates a digest file if missing. Fetches files if necessary. - NOTE: myarchives and mysettings used to be positional arguments, - so their order must be preserved for backward compatibility. - @param mysettings: the ebuild config (mysettings["O"] must correspond - to the ebuild's parent directory) - @type mysettings: config - @param myportdb: a portdbapi instance - @type myportdb: portdbapi - @rtype: int - @returns: 1 on success and 0 on failure - """ - if mysettings is None: - raise TypeError("portage.digestgen(): missing" + \ - " required 'mysettings' parameter") - if myportdb is None: - warnings.warn("portage.digestgen() called without 'myportdb' parameter= ", - DeprecationWarning, stacklevel=3D2) - global portdb - myportdb =3D portdb - if overwrite is not None: - warnings.warn("portage.digestgen() called with " + \ - "deprecated 'overwrite' parameter", - DeprecationWarning, stacklevel=3D2) - if manifestonly is not None: - warnings.warn("portage.digestgen() called with " + \ - "deprecated 'manifestonly' parameter", - DeprecationWarning, stacklevel=3D2) - global _doebuild_manifest_exempt_depend - try: - _doebuild_manifest_exempt_depend +=3D 1 - distfiles_map =3D {} - fetchlist_dict =3D FetchlistDict(mysettings["O"], mysettings, myportdb= ) - for cpv in fetchlist_dict: - try: - for myfile in fetchlist_dict[cpv]: - distfiles_map.setdefault(myfile, []).append(cpv) - except portage.exception.InvalidDependString as e: - writemsg("!!! %s\n" % str(e), noiselevel=3D-1) - del e - return 0 - mytree =3D os.path.dirname(os.path.dirname(mysettings["O"])) - manifest1_compat =3D False - mf =3D Manifest(mysettings["O"], mysettings["DISTDIR"], - fetchlist_dict=3Dfetchlist_dict, manifest1_compat=3Dmanifest1_compat) - # Don't require all hashes since that can trigger excessive - # 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 =3D set() - required_hash_types.add("size") - required_hash_types.add(portage.const.MANIFEST2_REQUIRED_HASH) - dist_hashes =3D mf.fhashdict.get("DIST", {}) - - # To avoid accidental regeneration of digests with the incorrect - # files (such as partially downloaded files), trigger the fetch - # code if the file exists and it's size doesn't match the current - # manifest entry. If there really is a legitimate reason for the - # digest to change, `ebuild --force digest` can be used to avoid - # triggering this code (or else the old digests can be manually - # removed from the Manifest). - missing_files =3D [] - for myfile in distfiles_map: - myhashes =3D dist_hashes.get(myfile) - if not myhashes: - try: - st =3D os.stat(os.path.join(mysettings["DISTDIR"], myfile)) - except OSError: - st =3D None - if st is None or st.st_size =3D=3D 0: - missing_files.append(myfile) - continue - size =3D myhashes.get("size") - - try: - st =3D os.stat(os.path.join(mysettings["DISTDIR"], myfile)) - except OSError as e: - if e.errno !=3D errno.ENOENT: - raise - del e - if size =3D=3D 0: - missing_files.append(myfile) - continue - if required_hash_types.difference(myhashes): - missing_files.append(myfile) - continue - else: - if st.st_size =3D=3D 0 or size is not None and size !=3D st.st_size: - missing_files.append(myfile) - continue - - if missing_files: - mytree =3D os.path.realpath(os.path.dirname( - os.path.dirname(mysettings["O"]))) - fetch_settings =3D config(clone=3Dmysettings) - debug =3D mysettings.get("PORTAGE_DEBUG") =3D=3D "1" - for myfile in missing_files: - uris =3D set() - for cpv in distfiles_map[myfile]: - myebuild =3D os.path.join(mysettings["O"], - catsplit(cpv)[1] + ".ebuild") - # for RESTRICT=3Dfetch, mirror, etc... - doebuild_environment(myebuild, "fetch", - mysettings["ROOT"], fetch_settings, - debug, 1, myportdb) - uris.update(myportdb.getFetchMap( - cpv, mytree=3Dmytree)[myfile]) - - fetch_settings["A"] =3D myfile # for use by pkg_nofetch() - - try: - st =3D os.stat(os.path.join( - mysettings["DISTDIR"],myfile)) - except OSError: - st =3D None - - if not fetch({myfile : uris}, fetch_settings): - writemsg(_("!!! Fetch failed for %s, can't update " - "Manifest\n") % myfile, noiselevel=3D-1) - if myfile in dist_hashes and \ - st is not None and st.st_size > 0: - # stat result is obtained before calling fetch(), - # since fetch may rename the existing file if the - # digest does not match. - writemsg(_("!!! If you would like to " - "forcefully replace the existing " - "Manifest entry\n!!! for %s, use " - "the following command:\n") % myfile + \ - "!!! " + colorize("INFORM", - "ebuild --force %s manifest" % \ - os.path.basename(myebuild)) + "\n", - noiselevel=3D-1) - return 0 - writemsg_stdout(_(">>> Creating Manifest for %s\n") % mysettings["O"]) - try: - mf.create(assumeDistHashesSometimes=3DTrue, - assumeDistHashesAlways=3D( - "assume-digests" in mysettings.features)) - except portage.exception.FileNotFound as e: - writemsg(_("!!! File %s doesn't exist, can't update " - "Manifest\n") % e, noiselevel=3D-1) - return 0 - except portage.exception.PortagePackageException as e: - writemsg(("!!! %s\n") % (e,), noiselevel=3D-1) - return 0 - try: - mf.write(sign=3DFalse) - except portage.exception.PermissionDenied as e: - writemsg(_("!!! Permission Denied: %s\n") % (e,), noiselevel=3D-1) - return 0 - if "assume-digests" not in mysettings.features: - distlist =3D list(mf.fhashdict.get("DIST", {})) - distlist.sort() - auto_assumed =3D [] - for filename in distlist: - if not os.path.exists( - os.path.join(mysettings["DISTDIR"], filename)): - auto_assumed.append(filename) - if auto_assumed: - mytree =3D os.path.realpath( - os.path.dirname(os.path.dirname(mysettings["O"]))) - cp =3D os.path.sep.join(mysettings["O"].split(os.path.sep)[-2:]) - pkgs =3D myportdb.cp_list(cp, mytree=3Dmytree) - pkgs.sort() - writemsg_stdout(" digest.assumed" + portage.output.colorize("WARN", - str(len(auto_assumed)).rjust(18)) + "\n") - for pkg_key in pkgs: - fetchlist =3D myportdb.getFetchMap(pkg_key, mytree=3Dmytree) - pv =3D pkg_key.split("/")[1] - for filename in auto_assumed: - if filename in fetchlist: - writemsg_stdout( - " %s::%s\n" % (pv, filename)) - return 1 - finally: - _doebuild_manifest_exempt_depend -=3D 1 - def digestParseFile(myfilename, mysettings=3DNone): """(filename) -- Parses a given file for entries matching: Modified: main/branches/prefix/pym/portage/dbapi/vartree.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- main/branches/prefix/pym/portage/dbapi/vartree.py 2010-02-27 19:01:26= UTC (rev 15480) +++ main/branches/prefix/pym/portage/dbapi/vartree.py 2010-02-27 19:21:09= UTC (rev 15481) @@ -25,6 +25,7 @@ 'writemsg,writemsg_level,write_atomic,atomic_ofstream,writedict,' + \ 'grabfile,grabdict,normalize_path,new_protect_filename,getlibpaths', 'portage.util.digraph:digraph', + 'portage.util.env_update:env_update', 'portage.util.listdir:dircache,listdir', 'portage.versions:best,catpkgsplit,catsplit,cpv_getkey,pkgcmp,' + \ '_pkgsplit@pkgsplit', @@ -39,7 +40,7 @@ FileNotFound, PermissionDenied, UnsupportedAPIException from portage.localization import _ =20 -from portage import dep_expand, env_update, \ +from portage import dep_expand, \ abssymlink, movefile, _movefile, bsd_chflags =20 # This is a special version of the os module, wrapped for unicode suppor= t. Modified: main/branches/prefix/pym/portage/package/ebuild/doebuild.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- main/branches/prefix/pym/portage/package/ebuild/doebuild.py 2010-02-2= 7 19:01:26 UTC (rev 15480) +++ main/branches/prefix/pym/portage/package/ebuild/doebuild.py 2010-02-2= 7 19:21:09 UTC (rev 15481) @@ -21,23 +21,35 @@ import portage portage.proxy.lazyimport.lazyimport(globals(), 'portage.package.ebuild.config:check_config_instance', + 'portage.util.digestgen:digestgen', + 'portage.util.ExtractKernelVersion:ExtractKernelVersion' ) =20 -from portage import auxdbkeys, bsd_chflags, dep_check, digestcheck, dige= stgen, eapi_is_supported, ExtractKernelVersion, merge, os, selinux, Strin= gIO, unmerge, _encodings, _parse_eapi_ebuild_head, _os_merge, _shell_quot= e, _split_ebuild_name_glep55, _unicode_decode, _unicode_encode -from portage.const import EBUILD_SH_ENV_FILE, EBUILD_SH_BINARY, INVALID_= ENV_FILE, MISC_SH_BINARY -from portage.data import portage_gid, portage_uid, secpass, uid, userpri= v_groups +from portage import auxdbkeys, bsd_chflags, dep_check, digestcheck, \ + eapi_is_supported, merge, os, selinux, StringIO, \ + unmerge, _encodings, _parse_eapi_ebuild_head, _os_merge, \ + _shell_quote, _split_ebuild_name_glep55, _unicode_decode, _unicode_enco= de +from portage.const import EBUILD_SH_ENV_FILE, EBUILD_SH_BINARY, \ + INVALID_ENV_FILE, MISC_SH_BINARY +from portage.data import portage_gid, portage_uid, secpass, \ + uid, userpriv_groups from portage.dbapi.virtual import fakedbapi -from portage.dep import Atom, paren_enclose, paren_normalize, paren_redu= ce, use_reduce +from portage.dep import Atom, paren_enclose, paren_normalize, \ + paren_reduce, use_reduce from portage.elog import elog_process from portage.elog.messages import eerror, eqawarn -from portage.exception import DigestException, FileNotFound, IncorrectPa= rameter, InvalidAtom, InvalidDependString, PermissionDenied, UnsupportedA= PIException +from portage.exception import DigestException, FileNotFound, \ + IncorrectParameter, InvalidAtom, InvalidDependString, PermissionDenied,= \ + UnsupportedAPIException from portage.localization import _ from portage.manifest import Manifest from portage.output import style_to_ansi_code from portage.package.ebuild.fetch import fetch from portage.package.ebuild.prepare_build_dirs import prepare_build_dirs from portage.package.ebuild._pty import _create_pty_or_pipe -from portage.util import apply_recursive_permissions, apply_secpass_perm= issions, noiselimit, normalize_path, writemsg, writemsg_stdout, write_ato= mic +from portage.util import apply_recursive_permissions, \ + apply_secpass_permissions, noiselimit, normalize_path, \ + writemsg, writemsg_stdout, write_atomic from portage.versions import _pkgsplit =20 def doebuild_environment(myebuild, mydo, myroot, mysettings, Copied: main/branches/prefix/pym/portage/util/ExtractKernelVersion.py (fr= om rev 15455, main/trunk/pym/portage/util/ExtractKernelVersion.py) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- main/branches/prefix/pym/portage/util/ExtractKernelVersion.py = (rev 0) +++ main/branches/prefix/pym/portage/util/ExtractKernelVersion.py 2010-02= -27 19:21:09 UTC (rev 15481) @@ -0,0 +1,77 @@ +# Copyright 2010 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id$ + +__all__ =3D ['ExtractKernelVersion'] + +import codecs + +from portage import os, _encodings, _unicode_encode +from portage.util import getconfig, grabfile + +def ExtractKernelVersion(base_dir): + """ + Try to figure out what kernel version we are running + @param base_dir: Path to sources (usually /usr/src/linux) + @type base_dir: string + @rtype: tuple( version[string], error[string]) + @returns: + 1. tuple( version[string], error[string]) + Either version or error is populated (but never both) + + """ + lines =3D [] + pathname =3D os.path.join(base_dir, 'Makefile') + try: + f =3D codecs.open(_unicode_encode(pathname, + encoding=3D_encodings['fs'], errors=3D'strict'), mode=3D'r', + encoding=3D_encodings['content'], errors=3D'replace') + except OSError as details: + return (None, str(details)) + except IOError as details: + return (None, str(details)) + + try: + for i in range(4): + lines.append(f.readline()) + except OSError as details: + return (None, str(details)) + except IOError as details: + return (None, str(details)) + + lines =3D [l.strip() for l in lines] + + version =3D '' + + #XXX: The following code relies on the ordering of vars within the Make= file + for line in lines: + # split on the '=3D' then remove annoying whitespace + items =3D line.split("=3D") + items =3D [i.strip() for i in items] + if items[0] =3D=3D 'VERSION' or \ + items[0] =3D=3D 'PATCHLEVEL': + version +=3D items[1] + version +=3D "." + elif items[0] =3D=3D 'SUBLEVEL': + version +=3D items[1] + elif items[0] =3D=3D 'EXTRAVERSION' and \ + items[-1] !=3D items[0]: + version +=3D items[1] + + # Grab a list of files named localversion* and sort them + localversions =3D os.listdir(base_dir) + for x in range(len(localversions)-1,-1,-1): + if localversions[x][:12] !=3D "localversion": + del localversions[x] + localversions.sort() + + # Append the contents of each to the version string, stripping ALL whit= espace + for lv in localversions: + version +=3D "".join( " ".join( grabfile( base_dir+ "/" + lv ) ).split= () ) + + # Check the .config for a CONFIG_LOCALVERSION and append that too, also= stripping whitespace + kernelconfig =3D getconfig(base_dir+"/.config") + if kernelconfig and "CONFIG_LOCALVERSION" in kernelconfig: + version +=3D "".join(kernelconfig["CONFIG_LOCALVERSION"].split()) + + return (version,None) Copied: main/branches/prefix/pym/portage/util/digestgen.py (from rev 1545= 5, main/trunk/pym/portage/util/digestgen.py) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- main/branches/prefix/pym/portage/util/digestgen.py = (rev 0) +++ main/branches/prefix/pym/portage/util/digestgen.py 2010-02-27 19:21:0= 9 UTC (rev 15481) @@ -0,0 +1,204 @@ +# Copyright 2010 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id$ + +__all__ =3D ['digestgen'] + +import errno +import warnings + +import portage +portage.proxy.lazyimport.lazyimport(globals(), + 'portage.package.ebuild.doebuild:doebuild_environment', +) + +from portage import os +from portage.const import MANIFEST2_REQUIRED_HASH +from portage.dbapi.porttree import FetchlistDict +from portage.exception import InvalidDependString, FileNotFound, \ + PermissionDenied, PortagePackageException +from portage.localization import _ +from portage.manifest import Manifest +from portage.output import colorize +from portage.package.ebuild.config import config +from portage.package.ebuild.fetch import fetch +from portage.util import writemsg, writemsg_stdout +from portage.versions import catsplit + +def digestgen(myarchives=3DNone, mysettings=3DNone, + overwrite=3DNone, manifestonly=3DNone, myportdb=3DNone): + """ + Generates a digest file if missing. Fetches files if necessary. + NOTE: myarchives and mysettings used to be positional arguments, + so their order must be preserved for backward compatibility. + @param mysettings: the ebuild config (mysettings["O"] must correspond + to the ebuild's parent directory) + @type mysettings: config + @param myportdb: a portdbapi instance + @type myportdb: portdbapi + @rtype: int + @returns: 1 on success and 0 on failure + """ + if mysettings is None: + raise TypeError("portage.digestgen(): missing" + \ + " required 'mysettings' parameter") + if myportdb is None: + warnings.warn("portage.digestgen() called without 'myportdb' parameter= ", + DeprecationWarning, stacklevel=3D2) + myportdb =3D portage.portdb + if overwrite is not None: + warnings.warn("portage.digestgen() called with " + \ + "deprecated 'overwrite' parameter", + DeprecationWarning, stacklevel=3D2) + if manifestonly is not None: + warnings.warn("portage.digestgen() called with " + \ + "deprecated 'manifestonly' parameter", + DeprecationWarning, stacklevel=3D2) + + try: + portage._doebuild_manifest_exempt_depend +=3D 1 + distfiles_map =3D {} + fetchlist_dict =3D FetchlistDict(mysettings["O"], mysettings, myportdb= ) + for cpv in fetchlist_dict: + try: + for myfile in fetchlist_dict[cpv]: + distfiles_map.setdefault(myfile, []).append(cpv) + except InvalidDependString as e: + writemsg("!!! %s\n" % str(e), noiselevel=3D-1) + del e + return 0 + mytree =3D os.path.dirname(os.path.dirname(mysettings["O"])) + manifest1_compat =3D False + mf =3D Manifest(mysettings["O"], mysettings["DISTDIR"], + fetchlist_dict=3Dfetchlist_dict, manifest1_compat=3Dmanifest1_compat) + # Don't require all hashes since that can trigger excessive + # 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 =3D set() + required_hash_types.add("size") + required_hash_types.add(MANIFEST2_REQUIRED_HASH) + dist_hashes =3D mf.fhashdict.get("DIST", {}) + + # To avoid accidental regeneration of digests with the incorrect + # files (such as partially downloaded files), trigger the fetch + # code if the file exists and it's size doesn't match the current + # manifest entry. If there really is a legitimate reason for the + # digest to change, `ebuild --force digest` can be used to avoid + # triggering this code (or else the old digests can be manually + # removed from the Manifest). + missing_files =3D [] + for myfile in distfiles_map: + myhashes =3D dist_hashes.get(myfile) + if not myhashes: + try: + st =3D os.stat(os.path.join(mysettings["DISTDIR"], myfile)) + except OSError: + st =3D None + if st is None or st.st_size =3D=3D 0: + missing_files.append(myfile) + continue + size =3D myhashes.get("size") + + try: + st =3D os.stat(os.path.join(mysettings["DISTDIR"], myfile)) + except OSError as e: + if e.errno !=3D errno.ENOENT: + raise + del e + if size =3D=3D 0: + missing_files.append(myfile) + continue + if required_hash_types.difference(myhashes): + missing_files.append(myfile) + continue + else: + if st.st_size =3D=3D 0 or size is not None and size !=3D st.st_size: + missing_files.append(myfile) + continue + + if missing_files: + mytree =3D os.path.realpath(os.path.dirname( + os.path.dirname(mysettings["O"]))) + fetch_settings =3D config(clone=3Dmysettings) + debug =3D mysettings.get("PORTAGE_DEBUG") =3D=3D "1" + for myfile in missing_files: + uris =3D set() + for cpv in distfiles_map[myfile]: + myebuild =3D os.path.join(mysettings["O"], + catsplit(cpv)[1] + ".ebuild") + # for RESTRICT=3Dfetch, mirror, etc... + doebuild_environment(myebuild, "fetch", + mysettings["ROOT"], fetch_settings, + debug, 1, myportdb) + uris.update(myportdb.getFetchMap( + cpv, mytree=3Dmytree)[myfile]) + + fetch_settings["A"] =3D myfile # for use by pkg_nofetch() + + try: + st =3D os.stat(os.path.join( + mysettings["DISTDIR"],myfile)) + except OSError: + st =3D None + + if not fetch({myfile : uris}, fetch_settings): + writemsg(_("!!! Fetch failed for %s, can't update " + "Manifest\n") % myfile, noiselevel=3D-1) + if myfile in dist_hashes and \ + st is not None and st.st_size > 0: + # stat result is obtained before calling fetch(), + # since fetch may rename the existing file if the + # digest does not match. + writemsg(_("!!! If you would like to " + "forcefully replace the existing " + "Manifest entry\n!!! for %s, use " + "the following command:\n") % myfile + \ + "!!! " + colorize("INFORM", + "ebuild --force %s manifest" % \ + os.path.basename(myebuild)) + "\n", + noiselevel=3D-1) + return 0 + writemsg_stdout(_(">>> Creating Manifest for %s\n") % mysettings["O"]) + try: + mf.create(assumeDistHashesSometimes=3DTrue, + assumeDistHashesAlways=3D( + "assume-digests" in mysettings.features)) + except FileNotFound as e: + writemsg(_("!!! File %s doesn't exist, can't update " + "Manifest\n") % e, noiselevel=3D-1) + return 0 + except PortagePackageException as e: + writemsg(("!!! %s\n") % (e,), noiselevel=3D-1) + return 0 + try: + mf.write(sign=3DFalse) + except PermissionDenied as e: + writemsg(_("!!! Permission Denied: %s\n") % (e,), noiselevel=3D-1) + return 0 + if "assume-digests" not in mysettings.features: + distlist =3D list(mf.fhashdict.get("DIST", {})) + distlist.sort() + auto_assumed =3D [] + for filename in distlist: + if not os.path.exists( + os.path.join(mysettings["DISTDIR"], filename)): + auto_assumed.append(filename) + if auto_assumed: + mytree =3D os.path.realpath( + os.path.dirname(os.path.dirname(mysettings["O"]))) + cp =3D os.path.sep.join(mysettings["O"].split(os.path.sep)[-2:]) + pkgs =3D myportdb.cp_list(cp, mytree=3Dmytree) + pkgs.sort() + writemsg_stdout(" digest.assumed" + colorize("WARN", + str(len(auto_assumed)).rjust(18)) + "\n") + for pkg_key in pkgs: + fetchlist =3D myportdb.getFetchMap(pkg_key, mytree=3Dmytree) + pv =3D pkg_key.split("/")[1] + for filename in auto_assumed: + if filename in fetchlist: + writemsg_stdout( + " %s::%s\n" % (pv, filename)) + return 1 + finally: + portage._doebuild_manifest_exempt_depend -=3D 1 Copied: main/branches/prefix/pym/portage/util/env_update.py (from rev 154= 55, main/trunk/pym/portage/util/env_update.py) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- main/branches/prefix/pym/portage/util/env_update.py = (rev 0) +++ main/branches/prefix/pym/portage/util/env_update.py 2010-02-27 19:21:= 09 UTC (rev 15481) @@ -0,0 +1,307 @@ +# Copyright 2010 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id$ + +__all__ =3D ['env_update'] + +import codecs +import errno +import stat +import sys +import time + +import portage +from portage import os, _encodings, _unicode_encode +from portage.checksum import prelink_capable +from portage.data import ostype +from portage.exception import ParseError +from portage.localization import _ +from portage.process import find_binary +from portage.util import atomic_ofstream, ensure_dirs, getconfig, \ + normalize_path, writemsg +from portage.util.listdir import listdir + +if sys.hexversion >=3D 0x3000000: + long =3D int + +def env_update(makelinks=3D1, target_root=3DNone, prev_mtimes=3DNone, co= ntents=3DNone, + env=3DNone, writemsg_level=3DNone): + """ + Parse /etc/env.d and use it to generate /etc/profile.env, csh.env, + ld.so.conf, and prelink.conf. Finally, run ldconfig. + """ + if writemsg_level is None: + writemsg_level =3D portage.util.writemsg_level + if target_root is None: + target_root =3D portage.settings["ROOT"] + if prev_mtimes is None: + prev_mtimes =3D portage.mtimedb["ldpath"] + if env is None: + env =3D os.environ + envd_dir =3D os.path.join(target_root, EPREFIX_LSTRIP, "etc", "env.d") + ensure_dirs(envd_dir, mode=3D0o755) + fns =3D listdir(envd_dir, EmptyOnError=3D1) + fns.sort() + templist =3D [] + for x in fns: + if len(x) < 3: + continue + if not x[0].isdigit() or not x[1].isdigit(): + continue + if x.startswith(".") or x.endswith("~") or x.endswith(".bak"): + continue + templist.append(x) + fns =3D templist + del templist + + space_separated =3D set(["CONFIG_PROTECT", "CONFIG_PROTECT_MASK"]) + colon_separated =3D set(["ADA_INCLUDE_PATH", "ADA_OBJECTS_PATH", + "CLASSPATH", "INFODIR", "INFOPATH", "KDEDIRS", "LDPATH", "MANPATH", + "PATH", "PKG_CONFIG_PATH", "PRELINK_PATH", "PRELINK_PATH_MASK", + "PYTHONPATH", "ROOTPATH"]) + + config_list =3D [] + + for x in fns: + file_path =3D os.path.join(envd_dir, x) + try: + myconfig =3D getconfig(file_path, expand=3DFalse) + except ParseError as e: + writemsg("!!! '%s'\n" % str(e), noiselevel=3D-1) + del e + continue + if myconfig is None: + # broken symlink or file removed by a concurrent process + writemsg("!!! File Not Found: '%s'\n" % file_path, noiselevel=3D-1) + continue + + config_list.append(myconfig) + if "SPACE_SEPARATED" in myconfig: + space_separated.update(myconfig["SPACE_SEPARATED"].split()) + del myconfig["SPACE_SEPARATED"] + if "COLON_SEPARATED" in myconfig: + colon_separated.update(myconfig["COLON_SEPARATED"].split()) + del myconfig["COLON_SEPARATED"] + + env =3D {} + specials =3D {} + for var in space_separated: + mylist =3D [] + for myconfig in config_list: + if var in myconfig: + for item in myconfig[var].split(): + if item and not item in mylist: + mylist.append(item) + del myconfig[var] # prepare for env.update(myconfig) + if mylist: + env[var] =3D " ".join(mylist) + specials[var] =3D mylist + + for var in colon_separated: + mylist =3D [] + for myconfig in config_list: + if var in myconfig: + for item in myconfig[var].split(":"): + if item and not item in mylist: + mylist.append(item) + del myconfig[var] # prepare for env.update(myconfig) + if mylist: + env[var] =3D ":".join(mylist) + specials[var] =3D mylist + + for myconfig in config_list: + """Cumulative variables have already been deleted from myconfig so tha= t + they won't be overwritten by this dict.update call.""" + env.update(myconfig) + + if EPREFIX =3D=3D '': + sleep_for_mtime_granularity =3D dolinkingstuff( + target_root, specials, prelink_capable, + makelinks, contents, prev_mtimes, env) + else: + sleep_for_mtime_granularity =3D False + writeshellprofile(target_root, env, sleep_for_mtime_granularity) + +def dolinkingstuff(target_root, specials, prelink_capable, makelinks, + contents, prev_mtimes, env): + # updating this stuff will never work in an offset, other than ROOT + # (e.g. not in Prefix), hence the EPREFIX is not taken into account + # here since this code should never be triggered on an offset install + ldsoconf_path =3D os.path.join(target_root, "etc", "ld.so.conf") + try: + myld =3D codecs.open(_unicode_encode(ldsoconf_path, + encoding=3D_encodings['fs'], errors=3D'strict'), + mode=3D'r', encoding=3D_encodings['content'], errors=3D'replace') + myldlines=3Dmyld.readlines() + myld.close() + oldld=3D[] + for x in myldlines: + #each line has at least one char (a newline) + if x[:1] =3D=3D "#": + continue + oldld.append(x[:-1]) + except (IOError, OSError) as e: + if e.errno !=3D errno.ENOENT: + raise + oldld =3D None + + ld_cache_update=3DFalse + + newld =3D specials["LDPATH"] + if (oldld !=3D newld): + #ld.so.conf needs updating and ldconfig needs to be run + myfd =3D atomic_ofstream(ldsoconf_path) + myfd.write("# ld.so.conf autogenerated by env-update; make all changes= to\n") + myfd.write("# contents of /etc/env.d directory\n") + for x in specials["LDPATH"]: + myfd.write(x + "\n") + myfd.close() + ld_cache_update=3DTrue + + # Update prelink.conf if we are prelink-enabled + if prelink_capable: + newprelink =3D atomic_ofstream( + os.path.join(target_root, "etc", "prelink.conf")) + newprelink.write("# prelink.conf autogenerated by env-update; make all= changes to\n") + newprelink.write("# contents of /etc/env.d directory\n") + + for x in ["/bin","/sbin","/usr/bin","/usr/sbin","/lib","/usr/lib"]: + newprelink.write("-l %s\n" % (x,)); + prelink_paths =3D [] + prelink_paths +=3D specials.get("LDPATH", []) + prelink_paths +=3D specials.get("PATH", []) + prelink_paths +=3D specials.get("PRELINK_PATH", []) + prelink_path_mask =3D specials.get("PRELINK_PATH_MASK", []) + for x in prelink_paths: + if not x: + continue + if x[-1:] !=3D '/': + x +=3D "/" + plmasked =3D 0 + for y in prelink_path_mask: + if not y: + continue + if y[-1] !=3D '/': + y +=3D "/" + if y =3D=3D x[0:len(y)]: + plmasked =3D 1 + break + if not plmasked: + newprelink.write("-h %s\n" % (x,)) + for x in prelink_path_mask: + newprelink.write("-b %s\n" % (x,)) + newprelink.close() + + # Portage stores mtimes with 1 second granularity but in >=3Dpython-2.5= finer + # granularity is possible. In order to avoid the potential ambiguity o= f + # mtimes that differ by less than 1 second, sleep here if any of the + # directories have been modified during the current second. + sleep_for_mtime_granularity =3D False + current_time =3D long(time.time()) + mtime_changed =3D False + lib_dirs =3D set() + for lib_dir in set(specials["LDPATH"] + \ + ['usr/lib','usr/lib64','usr/lib32','lib','lib64','lib32']): + x =3D os.path.join(target_root, lib_dir.lstrip(os.sep)) + try: + newldpathtime =3D os.stat(x)[stat.ST_MTIME] + lib_dirs.add(normalize_path(x)) + except OSError as oe: + if oe.errno =3D=3D errno.ENOENT: + try: + del prev_mtimes[x] + except KeyError: + pass + # ignore this path because it doesn't exist + continue + raise + if newldpathtime =3D=3D current_time: + sleep_for_mtime_granularity =3D True + if x in prev_mtimes: + if prev_mtimes[x] =3D=3D newldpathtime: + pass + else: + prev_mtimes[x] =3D newldpathtime + mtime_changed =3D True + else: + prev_mtimes[x] =3D newldpathtime + mtime_changed =3D True + + if mtime_changed: + ld_cache_update =3D True + + if makelinks and \ + not ld_cache_update and \ + contents is not None: + libdir_contents_changed =3D False + for mypath, mydata in contents.items(): + if mydata[0] not in ("obj", "sym"): + continue + head, tail =3D os.path.split(mypath) + if head in lib_dirs: + libdir_contents_changed =3D True + break + if not libdir_contents_changed: + makelinks =3D False + + ldconfig =3D "/sbin/ldconfig" + if "CHOST" in env and "CBUILD" in env and \ + env["CHOST"] !=3D env["CBUILD"]: + ldconfig =3D find_binary("%s-ldconfig" % env["CHOST"]) + + # Only run ldconfig as needed + if (ld_cache_update or makelinks) and ldconfig: + # ldconfig has very different behaviour between FreeBSD and Linux + if ostype =3D=3D "Linux" or ostype.lower().endswith("gnu"): + # We can't update links if we haven't cleaned other versions first, a= s + # an older package installed ON TOP of a newer version will cause ldc= onfig + # to overwrite the symlinks we just made. -X means no links. After 'c= lean' + # we can safely create links. + writemsg_level(_(">>> Regenerating %setc/ld.so.cache...\n") % \ + (target_root,)) + if makelinks: + os.system("cd / ; %s -r '%s'" % (ldconfig, target_root)) + else: + os.system("cd / ; %s -X -r '%s'" % (ldconfig, target_root)) + elif ostype in ("FreeBSD","DragonFly"): + writemsg_level(_(">>> Regenerating %svar/run/ld-elf.so.hints...\n") %= \ + target_root) + os.system(("cd / ; %s -elf -i " + \ + "-f '%svar/run/ld-elf.so.hints' '%setc/ld.so.conf'") % \ + (ldconfig, target_root, target_root)) + + del specials["LDPATH"] + + return sleep_for_mtime_granularity + +def writeshellprofile(target_root, env, sleep_for_mtime_granularity): + penvnotice =3D "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\= n" + penvnotice +=3D "# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES\n= " + cenvnotice =3D penvnotice[:] + penvnotice +=3D "# GO INTO " + EPREFIX + "/etc/profile NOT /etc/profile= .env\n\n" + cenvnotice +=3D "# GO INTO " + EPREFIX + "/etc/csh.cshrc NOT /etc/csh.e= nv\n\n" + + #create /etc/profile.env for bash support + outfile =3D atomic_ofstream(os.path.join(target_root, EPREFIX_LSTRIP, "= etc", "profile.env")) + outfile.write(penvnotice) + + env_keys =3D [ x for x in env if x !=3D "LDPATH" ] + env_keys.sort() + for k in env_keys: + v =3D env[k] + if v.startswith('$') and not v.startswith('${'): + outfile.write("export %s=3D$'%s'\n" % (k, v[1:])) + else: + outfile.write("export %s=3D'%s'\n" % (k, v)) + outfile.close() + + #create /etc/csh.env for (t)csh support + outfile =3D atomic_ofstream(os.path.join(target_root, EPREFIX_LSTRIP, "= etc", "csh.env")) + outfile.write(cenvnotice) + for x in env_keys: + outfile.write("setenv %s '%s'\n" % (x, env[x])) + outfile.close() + + if sleep_for_mtime_granularity: + while current_time =3D=3D long(time.time()): + time.sleep(1)