From: Zac Medico Date: Tue, 31 Oct 2006 04:23:06 +0000 (-0000) Subject: Rely on PYTHONPATH instead of PORTAGE_PYM_PATH for locating portage's python modules... X-Git-Tag: v2.1.2~527 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=64396f7e8e3914d66d4b5efb9bfd80c8cd7a72fd;p=portage.git Rely on PYTHONPATH instead of PORTAGE_PYM_PATH for locating portage's python modules, then fall back to an explicit sys.path insertion if an ImportError occurs. svn path=/main/trunk/; revision=4884 --- diff --git a/NEWS b/NEWS index 64cd1da6a..7f0bc40cc 100644 --- a/NEWS +++ b/NEWS @@ -19,7 +19,7 @@ portage-2.1.2 order and detection of circular dependencies. * The world and system sets allow automatic update of all installed slots. * DEPEND atoms support SLOT dependencies of the form ${CATEGORY}/${PN}:${SLOT}. -* Development: Extend PORTAGE_PYM_PATH support to allow overriding the hardcoded +* Development: Extend PYTHONPATH support to allow overriding the hardcoded /usr/lib/portage/pym for development/testing purposes portage-2.1.1 diff --git a/bin/archive-conf b/bin/archive-conf index 0417e97cc..b3d17cc6f 100755 --- a/bin/archive-conf +++ b/bin/archive-conf @@ -11,9 +11,13 @@ # import os, sys, string -sys.path.insert(0, os.environ.get("PORTAGE_PYM_PATH", "/usr/lib/portage/pym")) +try: + import portage +except ImportError: + sys.path.insert(0, "/usr/lib/portage/pym") + import portage -import portage, dispatch_conf +import dispatch_conf FIND_EXTANT_CONTENTS = "find %s -name CONTENTS" diff --git a/bin/chkcontents b/bin/chkcontents index 4523b6306..aae45c6bc 100755 --- a/bin/chkcontents +++ b/bin/chkcontents @@ -9,8 +9,11 @@ # the right files). import string, os.path, os, sys -sys.path.insert(0, os.environ.get("PORTAGE_PYM_PATH", "/usr/lib/portage/pym")) -import portage +try: + import portage +except ImportError: + sys.path.insert(0, "/usr/lib/portage/pym") + import portage def CONTENTScheck(path): try: diff --git a/bin/clean_locks b/bin/clean_locks index 9c7e110ce..71db0b8e2 100755 --- a/bin/clean_locks +++ b/bin/clean_locks @@ -4,9 +4,11 @@ # $Id$ import os,sys,errno -sys.path.insert(0, os.environ.get("PORTAGE_PYM_PATH", "/usr/lib/portage/pym")) - -import portage_locks +try: + import portage_locks +except ImportError: + sys.path.insert(0, "/usr/lib/portage/pym") + import portage_locks if not sys.argv[1:] or "--help" in sys.argv or "-h" in sys.argv: import portage diff --git a/bin/dispatch-conf b/bin/dispatch-conf index 277d6ef4b..2309b680f 100755 --- a/bin/dispatch-conf +++ b/bin/dispatch-conf @@ -15,9 +15,13 @@ from stat import * from random import * import atexit, commands, os, re, shutil, stat, string, sys -sys.path.insert(0, os.environ.get("PORTAGE_PYM_PATH", "/usr/lib/portage/pym")) +try: + import portage +except ImportError: + sys.path.insert(0, "/usr/lib/portage/pym") + import portage -import portage, dispatch_conf +import dispatch_conf from portage_exec import find_binary FIND_EXTANT_CONFIGS = "find '%s' %s -iname '._cfg????_%s'" diff --git a/bin/ebuild b/bin/ebuild index 2d8c0890e..da405db07 100755 --- a/bin/ebuild +++ b/bin/ebuild @@ -21,9 +21,13 @@ if "merge" in pargs: os.environ["FEATURES"] = os.environ.get("FEATURES", "") + " -noauto" os.environ["PORTAGE_CALLER"]="ebuild" -sys.path.insert(0, os.environ.get("PORTAGE_PYM_PATH", "/usr/lib/portage/pym")) +try: + import portage +except ImportError: + sys.path.insert(0, "/usr/lib/portage/pym") + import portage -import portage, portage_util, portage_const +import portage_util, portage_const # do this _after_ 'import portage' to prevent unnecessary tracing if debug and "python-trace" in portage.features: diff --git a/bin/emaint b/bin/emaint index 016c64ea4..bff6856f8 100755 --- a/bin/emaint +++ b/bin/emaint @@ -1,12 +1,16 @@ #!/usr/bin/python -O import sys, os -sys.path.insert(0, os.environ.get("PORTAGE_PYM_PATH", "/usr/lib/portage/pym")) from optparse import OptionParser, OptionValueError import re +try: + import portage +except ImportError: + sys.path.insert(0, "/usr/lib/portage/pym") + import portage -import os, portage, portage_const, portage_exception +import portage_const, portage_exception class WorldHandler(object): def name(): diff --git a/bin/emerge b/bin/emerge index 933b461d0..959224a12 100755 --- a/bin/emerge +++ b/bin/emerge @@ -21,10 +21,13 @@ except KeyboardInterrupt: sys.exit(1) import os, stat -sys.path.insert(0, os.environ.get("PORTAGE_PYM_PATH", "/usr/lib/portage/pym")) os.environ["PORTAGE_LEGACY_GLOBALS"] = "false" -import portage +try: + import portage +except ImportError: + sys.path.insert(0, "/usr/lib/portage/pym") + import portage del os.environ["PORTAGE_LEGACY_GLOBALS"] from portage import digraph diff --git a/bin/env-update b/bin/env-update index 1026b1fc1..b245b3990 100755 --- a/bin/env-update +++ b/bin/env-update @@ -4,7 +4,6 @@ # $Id$ import os,sys -sys.path.insert(0, os.environ.get("PORTAGE_PYM_PATH", "/usr/lib/portage/pym")) def usage(status): print "Usage: env-update [--no-ldconfig]" @@ -24,5 +23,9 @@ if len(sys.argv) > 1: print "!!! Invalid command line options!\n" usage(1) -import portage +try: + import portage +except ImportError: + sys.path.insert(0, "/usr/lib/portage/pym") + import portage portage.env_update(makelinks) diff --git a/bin/fix-db.py b/bin/fix-db.py index fef1a4d44..e8bbad2ca 100755 --- a/bin/fix-db.py +++ b/bin/fix-db.py @@ -4,7 +4,12 @@ # $Id$ import os,sys,re -sys.path.insert(0, os.environ.get("PORTAGE_PYM_PATH", "/usr/lib/portage/pym")) + +try: + import portage +except ImportError: + sys.path.insert(0, "/usr/lib/portage/pym") + import portage from stat import * from output import * diff --git a/bin/fixpackages b/bin/fixpackages index f9d09dec2..f7c1bf51d 100755 --- a/bin/fixpackages +++ b/bin/fixpackages @@ -5,9 +5,11 @@ import os,sys os.environ["PORTAGE_CALLER"]="fixpackages" -sys.path.insert(0, os.environ.get("PORTAGE_PYM_PATH", "/usr/lib/portage/pym")) - -import portage +try: + import portage +except ImportError: + sys.path.insert(0, "/usr/lib/portage/pym") + import portage mysettings = portage.settings mytrees = portage.db diff --git a/bin/md5check.py b/bin/md5check.py index 98f3c8107..c83331ede 100755 --- a/bin/md5check.py +++ b/bin/md5check.py @@ -5,9 +5,11 @@ import os,sys,string os.environ["FEATURES"]="mirror cvs" -sys.path.insert(0, os.environ.get("PORTAGE_PYM_PATH", "/usr/lib/portage/pym")) - -import portage +try: + import portage +except ImportError: + sys.path.insert(0, "/usr/lib/portage/pym") + import portage from threading import * from output import red,green,blue,bold from random import shuffle diff --git a/bin/pkgname b/bin/pkgname index 546b05d3c..ee4807744 100755 --- a/bin/pkgname +++ b/bin/pkgname @@ -4,9 +4,11 @@ # $Id$ import sys, os -sys.path.insert(0, os.environ.get("PORTAGE_PYM_PATH", "/usr/lib/portage/pym")) - -import portage +try: + import portage +except ImportError: + sys.path.insert(0, "/usr/lib/portage/pym") + import portage a=portage.pkgsplit(sys.argv[1]) if a: diff --git a/bin/portageq b/bin/portageq index 0424647b7..5ee16c4ec 100755 --- a/bin/portageq +++ b/bin/portageq @@ -20,7 +20,6 @@ except KeyboardInterrupt: sys.exit(1) import os -sys.path.insert(0, os.environ.get("PORTAGE_PYM_PATH", "/usr/lib/portage/pym")) import types,string @@ -332,7 +331,11 @@ def main(): if uses_root: os.environ["ROOT"] = sys.argv[2] global portage - import portage + try: + import portage + except ImportError: + sys.path.insert(0, "/usr/lib/portage/pym") + import portage if uses_root: sys.argv[2] = portage.root function(sys.argv[2:]) diff --git a/bin/regenworld b/bin/regenworld index d5e28dd7f..a7428ed9e 100755 --- a/bin/regenworld +++ b/bin/regenworld @@ -4,8 +4,12 @@ # $Id$ import sys, os -sys.path.insert(0, os.environ.get("PORTAGE_PYM_PATH", "/usr/lib/portage/pym")) -import portage, string, re +try: + import portage +except ImportError: + sys.path.insert(0, "/usr/lib/portage/pym") + import portage +import string, re __candidatematcher__ = re.compile("^[0-9]+: \\*\\*\\* emerge ") __noncandidatematcher__ = re.compile(" sync( |$)| clean( |$)| search( |$)|--oneshot|--fetchonly| unmerge( |$)") diff --git a/bin/repoman b/bin/repoman index c05ae9e40..4e8f7fc14 100755 --- a/bin/repoman +++ b/bin/repoman @@ -11,7 +11,6 @@ import errno, os, shutil, sys if not hasattr(__builtins__, "set"): from sets import Set as set exename=os.path.basename(sys.argv[0]) -sys.path.insert(0, os.environ.get("PORTAGE_PYM_PATH", "/usr/lib/portage/pym")) version="1.2" allowed_filename_chars="a-zA-Z0-9._-+:" @@ -24,7 +23,11 @@ map(allowed_filename_chars_set.setdefault, map(chr, map(ord, [".", "-", "_", "+" import string,signal,re,pickle,tempfile os.environ["PORTAGE_LEGACY_GLOBALS"] = "false" -import portage +try: + import portage +except ImportError: + sys.path.insert(0, "/usr/lib/portage/pym") + import portage del os.environ["PORTAGE_LEGACY_GLOBALS"] import portage_checksum diff --git a/bin/xpak b/bin/xpak index 1a0743773..8dcbf145c 100755 --- a/bin/xpak +++ b/bin/xpak @@ -8,7 +8,10 @@ if len(sys.argv)!=3: print "xpak: expecting three arguments." sys.exit(1) -sys.path.insert(0, os.environ.get("PORTAGE_PYM_PATH", "/usr/lib/portage/pym")) +try: + import xpak +except ImportError: + sys.path.insert(0, "/usr/lib/portage/pym") + import xpak -import xpak xpak.xpak(sys.argv[1],sys.argv[2])