ia64/xen-unstable

changeset 13807:afb41f6bc30a

Break out the Python path interrogation into a separate script. This has the
advantage that the temporary path manipulation cannot affect the main script,
and that it can be shared with other programs, such as xm-test.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Thu Feb 01 12:48:53 2007 +0000 (2007-02-01)
parents f73e71aa0a90
children a9f30d8eea75
files tools/misc/Makefile tools/misc/xen-python-path tools/misc/xend
line diff
     1.1 --- a/tools/misc/Makefile	Thu Feb 01 11:55:31 2007 +0000
     1.2 +++ b/tools/misc/Makefile	Thu Feb 01 12:48:53 2007 +0000
     1.3 @@ -12,7 +12,7 @@ HDRS     = $(wildcard *.h)
     1.4  TARGETS  = xenperf xc_shadow
     1.5  
     1.6  INSTALL_BIN  = $(TARGETS) xencons
     1.7 -INSTALL_SBIN = netfix xm xen-bugtool xend xenperf
     1.8 +INSTALL_SBIN = netfix xm xen-bugtool xen-python-path xend xenperf
     1.9  
    1.10  .PHONY: all
    1.11  all: build
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/misc/xen-python-path	Thu Feb 01 12:48:53 2007 +0000
     2.3 @@ -0,0 +1,41 @@
     2.4 +#!/usr/bin/env python
     2.5 +#  -*- mode: python; -*-
     2.6 +#============================================================================
     2.7 +# This library is free software; you can redistribute it and/or
     2.8 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
     2.9 +# License as published by the Free Software Foundation.
    2.10 +#
    2.11 +# This library is distributed in the hope that it will be useful,
    2.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.14 +# Lesser General Public License for more details.
    2.15 +#
    2.16 +# You should have received a copy of the GNU Lesser General Public
    2.17 +# License along with this library; if not, write to the Free Software
    2.18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.19 +#============================================================================
    2.20 +# Copyright (C) 2007 XenSource Inc.
    2.21 +#============================================================================
    2.22 +
    2.23 +
    2.24 +# Use the auxbin module in Xend to determine the correct Python path.  We
    2.25 +# take the first installed instance of auxbin that we find, and then run it
    2.26 +# to determine the correct path, appending that to sys.path.
    2.27 +
    2.28 +AUXBIN = 'xen/util/auxbin.py'
    2.29 +
    2.30 +import os
    2.31 +import os.path
    2.32 +import sys
    2.33 +
    2.34 +for p in ['python%s' % sys.version[:3], 'python']:
    2.35 +    for l in ['/usr/lib64', '/usr/lib']:
    2.36 +        d = os.path.join(l, p)
    2.37 +        if os.path.exists(os.path.join(d, AUXBIN)):
    2.38 +            sys.path.append(d)
    2.39 +            import xen.util.auxbin
    2.40 +            print os.path.join(xen.util.auxbin.libpath(), p)
    2.41 +            sys.exit(0)
    2.42 +
    2.43 +print >>sys.stderr, "Cannot find Xen Python modules."
    2.44 +sys.exit(1)
     3.1 --- a/tools/misc/xend	Thu Feb 01 11:55:31 2007 +0000
     3.2 +++ b/tools/misc/xend	Thu Feb 01 12:48:53 2007 +0000
     3.3 @@ -31,23 +31,13 @@ import signal
     3.4  import time
     3.5  import commands
     3.6  
     3.7 -
     3.8 -# Use the auxbin module in Xend to determine the correct Python path.  We
     3.9 -# take the first installed instance of auxbin that we find, and then run it
    3.10 -# to determine the correct path, appending that to sys.path.
    3.11 -
    3.12 -AUXBIN = 'xen/util/auxbin.py'
    3.13 +result = commands.getstatusoutput(os.path.join(os.path.dirname(sys.argv[0]),
    3.14 +                                               'xen-python-path'))
    3.15 +if result[0] != 0:
    3.16 +    print >>sys.stderr, result[1]
    3.17 +    sys.exit(1)
    3.18  
    3.19 -for p in ['python%s' % sys.version[:3], 'python']:
    3.20 -    for l in ['/usr/lib64', '/usr/lib']:
    3.21 -        d = os.path.join(l, p)
    3.22 -        if os.path.exists(os.path.join(d, AUXBIN)):
    3.23 -            sys.path.append(d)
    3.24 -            import xen.util.auxbin
    3.25 -            libpath = os.path.join(xen.util.auxbin.libpath(), p)
    3.26 -            sys.path = sys.path[:-1]
    3.27 -            sys.path.append(libpath)
    3.28 -            break
    3.29 +sys.path.append(result[1])
    3.30  
    3.31  from xen.xend.server import SrvDaemon
    3.32