Make non-native python path handling a fallback
PATCH 1/1 Make non-native python path handling a fallback
Although I don't really agree with the installing of the python bits to the non-native paths, I can see where it's useful as long as the module ABI doesn't change if you're trying to distribute binary tarballs. But with the current handling it adds module lookup costs for the native path case (which would be the norm) as well as prevents using PYTHONPATH to look to a different location for the modules.
The attached patch changes things so that at first, the xen module is attempted to be imported from the stock paths. If we get an ImportError exception, then it adds /usr/lib/python to the end of the python path and imports again.
Jeremy
===== tools/misc/netfix 1.13 vs edited =====
tools/misc/netfix +6 -3
@@ -9,9 +9,12 @@ from getopt import getopt -# Default install path for Xen binary packages. -sys.path = [ '/usr/lib/python' ] + sys.path -from xen.util.Brctl import * +# add fallback path for non-native python path installs if needed +try: + from xen.util.Brctl import * +except ImportError: + sys.path.append('/usr/lib/python') + from xen.util.Brctl import * short_options = 'hvqni:b:c' long_options = ['help', 'verbose', 'quiet',
===== tools/misc/xend 1.20 vs edited =====
tools/misc/xend +6 -3
@@ -30,9 +30,12 @@ XCS_PIDFILE = "/var/run/xcs.pid" XCS_ARGS = (XCS_EXEC, "-p", XCS_PIDFILE) -# Default install path for Xen binary packages. -sys.path = [ '/usr/lib/python' ] + sys.path -from xen.xend.server import SrvDaemon +# add fallback path for non-native python path installs if needed +try: + from xen.xend.server import SrvDaemon +except ImportError: + sys.path.append('/usr/lib/python') + from xen.xend.server import SrvDaemon class CheckError(ValueError): pass
===== tools/misc/xensv 1.4 vs edited =====
tools/misc/xensv +6 -3
@@ -22,9 +22,12 @@ import sys import re -# Default install path for Xen binary packages. -sys.path = [ '/usr/lib/python' ] + sys.path -from xen.xend.server.params import XEND_PID_FILE +# add fallback path for non-native python path installs if needed +try: + from xen.xend.server.params import XEND_PID_FILE +except ImportError: + sys.path.append('/usr/lib/python') + from xen.xend.server.params import XEND_PID_FILE class CheckError(ValueError): pass
===== tools/misc/xm 1.9 vs edited =====
tools/misc/xm +6 -3
@@ -2,8 +2,11 @@ # -*- mode: python; -*- import sys -# Default install path for Xen binary packages. -sys.path = [ '/usr/lib/python' ] + sys.path -from xen.xm import main +# add fallback path for non-native python path installs if needed +try: + from xen.xm import main +except ImportError: + sys.path.append('/usr/lib/python') + from xen.xm import main main.main(sys.argv)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel