ia64/xen-unstable

changeset 19616:61501fa86b1b

python: get rid of hardcoded search pathes in python code.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue May 19 02:16:37 2009 +0100 (2009-05-19)
parents 13a4f4e6d0a3
children 62ec6aae4ba9
files .hgignore tools/python/Makefile tools/python/xen/util/auxbin.py
line diff
     1.1 --- a/.hgignore	Tue May 19 02:12:04 2009 +0100
     1.2 +++ b/.hgignore	Tue May 19 02:16:37 2009 +0100
     1.3 @@ -183,6 +183,7 @@
     1.4  ^tools/misc/xenpm$
     1.5  ^tools/pygrub/build/.*$
     1.6  ^tools/python/build/.*$
     1.7 +^tools/python/xen/util/path\.py$
     1.8  ^tools/security/secpol_tool$
     1.9  ^tools/security/xen/.*$
    1.10  ^tools/security/xensec_tool$
     2.1 --- a/tools/python/Makefile	Tue May 19 02:12:04 2009 +0100
     2.2 +++ b/tools/python/Makefile	Tue May 19 02:16:37 2009 +0100
     2.3 @@ -13,9 +13,18 @@ POTFILE := $(PODIR)/xen-xm.pot
     2.4  I18NSRCFILES = $(shell find xen/xm/ -name '*.py')
     2.5  CATALOGS = $(patsubst %,xen/xm/messages/%.mo,$(LINGUAS))
     2.6  NLSDIR = $(SHAREDIR)/locale
     2.7 +xenpath = "xen/util/path.py"
     2.8 +  
     2.9 +.PHONY: build buildpy genpath
    2.10 +genpath:
    2.11 +	rm -f ${xenpath}
    2.12 +	echo "SBINDIR=\"$(SBINDIR)\"" >> ${xenpath}
    2.13 +	echo "BINDIR=\"$(BINDIR)\"" >> ${xenpath}
    2.14 +	echo "LIBEXEC=\"$(LIBEXEC)\"" >> ${xenpath}
    2.15 +	echo "LIBDIR=\"$(LIBDIR)\"" >> ${xenpath}
    2.16 +	echo "PRIVATE_BINDIR=\"$(PRIVATE_BINDIR)\"" >> ${xenpath}
    2.17  
    2.18 -.PHONY: build buildpy
    2.19 -buildpy: 
    2.20 +buildpy: genpath 
    2.21  	CC="$(CC)" CFLAGS="$(CFLAGS)" $(PYTHON) setup.py build
    2.22  
    2.23  build: buildpy refresh-pot refresh-po $(CATALOGS)
     3.1 --- a/tools/python/xen/util/auxbin.py	Tue May 19 02:12:04 2009 +0100
     3.2 +++ b/tools/python/xen/util/auxbin.py	Tue May 19 02:16:37 2009 +0100
     3.3 @@ -16,19 +16,10 @@
     3.4  #============================================================================
     3.5  
     3.6  
     3.7 -LIB_32 = "/usr/lib"
     3.8 -LIB_64 = "/usr/lib64"
     3.9 -LIB_BIN_SUFFIX = "xen/bin"
    3.10 -
    3.11 -## The architectures on which the LIB_64 directory is used.  This
    3.12 -# deliberately excludes ia64 and ppc64, and Solaris.
    3.13 -LIB_64_ARCHS = [ 'x86_64', 's390x', 'sparc64']
    3.14 -
    3.15 -
    3.16  import os
    3.17  import os.path
    3.18  import sys
    3.19 -
    3.20 +from xen.util.path import SBINDIR,BINDIR,LIBEXEC,LIBDIR,PRIVATE_BINDIR
    3.21  
    3.22  def execute(exe, args = None):
    3.23      exepath = pathTo(exe)
    3.24 @@ -41,26 +32,16 @@ def execute(exe, args = None):
    3.25          print exepath, ": ", exn
    3.26          sys.exit(1)
    3.27  
    3.28 -
    3.29 -def pathTo(exe):
    3.30 -    return os.path.join(path(), exe)
    3.31 -
    3.32 +SEARCHDIRS = [ BINDIR, SBINDIR, LIBEXEC, PRIVATE_BINDIR ]
    3.33 +def pathTo(exebin):
    3.34 +    for dir in SEARCHDIRS:
    3.35 +        exe = os.path.join(dir, exebin)
    3.36 +        if os.path.exists(exe):
    3.37 +            return exe
    3.38 +    return None
    3.39  
    3.40  def path():
    3.41 -    return os.path.join(libpath(), LIB_BIN_SUFFIX)
    3.42 -
    3.43 +    return LIBEXEC
    3.44  
    3.45  def libpath():
    3.46 -    machine = os.uname()[4]
    3.47 -    if sys.argv[0] != '-c':
    3.48 -        prefix = os.path.dirname(os.path.dirname(sys.argv[0]))
    3.49 -        path = os.path.join(prefix, os.path.basename(LIB_64))
    3.50 -        if machine in LIB_64_ARCHS and os.path.exists(path):
    3.51 -            return path
    3.52 -        path = os.path.join(prefix, os.path.basename(LIB_32))
    3.53 -        if os.path.exists(path):
    3.54 -            return path
    3.55 -    if machine in LIB_64_ARCHS and os.path.exists(LIB_64):
    3.56 -        return LIB_64
    3.57 -    else:
    3.58 -        return LIB_32
    3.59 +    return LIBDIR