ia64/xen-unstable

view tools/python/xen/util/auxbin.py @ 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 47e836fc59de
children 23f9857f642f
line source
1 #============================================================================
2 # This library is free software; you can redistribute it and/or
3 # modify it under the terms of version 2.1 of the GNU Lesser General Public
4 # License as published by the Free Software Foundation.
5 #
6 # This library is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # Lesser General Public License for more details.
10 #
11 # You should have received a copy of the GNU Lesser General Public
12 # License along with this library; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 #============================================================================
15 # Copyright (C) 2005-2006 XenSource Inc.
16 #============================================================================
19 import os
20 import os.path
21 import sys
22 from xen.util.path import SBINDIR,BINDIR,LIBEXEC,LIBDIR,PRIVATE_BINDIR
24 def execute(exe, args = None):
25 exepath = pathTo(exe)
26 a = [ exepath ]
27 if args:
28 a.extend(args)
29 try:
30 os.execv(exepath, a)
31 except OSError, exn:
32 print exepath, ": ", exn
33 sys.exit(1)
35 SEARCHDIRS = [ BINDIR, SBINDIR, LIBEXEC, PRIVATE_BINDIR ]
36 def pathTo(exebin):
37 for dir in SEARCHDIRS:
38 exe = os.path.join(dir, exebin)
39 if os.path.exists(exe):
40 return exe
41 return None
43 def path():
44 return LIBEXEC
46 def libpath():
47 return LIBDIR