Script xalt_parse_mpirun_args_in_py
[hide private]
[frames] | no frames]

Source Code for Script script-xalt_parse_mpirun_args_in_py

 1  #----------------------------------------------------------------------- 
 2  # XALT: A tool that tracks users jobs and environments on a cluster. 
 3  # Copyright (C) 2013-2014 University of Texas at Austin 
 4  # Copyright (C) 2013-2014 University of Tennessee 
 5  #  
 6  # This library is free software; you can redistribute it and/or modify 
 7  # it under the terms of the GNU Lesser General Public License as 
 8  # published by the Free Software Foundation; either version 2.1 of  
 9  # the License, or (at your option) any later version.  
10  # 
11  # This library is distributed in the hope that it will be useful, 
12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
14  # Lesser  General Public License for more details.  
15  # 
16  # You should have received a copy of the GNU Lesser General Public 
17  # License along with this library; if not, write to the Free 
18  # Software Foundation, Inc., 59 Temple Place, Suite 330, 
19  # Boston, MA 02111-1307 USA 
20  #----------------------------------------------------------------------- 
21   
22  from __future__ import print_function 
23  import os, re, sys 
24  dirNm, execName = os.path.split(os.path.realpath(sys.argv[0])) 
25  sys.path.insert(1,os.path.realpath(os.path.join(dirNm, "../libexec"))) 
26   
27  from xalt_util  import which 
28   
29   
30 -def find_cmd(ignoreT, i, argA):
31 """ 32 Walk the command line and find the command by ignoring names in ignoreT 33 such as env time, etc 34 35 @param ignoreT: Table of names to ignore. 36 @param i: The location in the argA array to start looking. 37 @param argA: The command line split into an array. 38 """ 39 N = len(argA) 40 cmd = None 41 while (i < N): 42 arg = argA[i] 43 i = i + 1 44 bare = os.path.basename(arg) 45 if (not (bare in ignoreT)): 46 cmd = arg 47 break 48 return cmd
49
50 -def find_exec(ignoreT, argT, cmdArg, argA, *n, **kw):
51 """ 52 Walk the command line and first walk over the command line options. 53 54 @param ignoreT: Table of names to ignore. 55 @param argT: Table of command line args. Keys are the name of the argument, values are the number of arguments it takes (> 0). 56 @param cmdArg: command (like in ibrun.symm) that points to a user program. 57 @param argA: The command line split into an array. 58 @param kw: If dot=True then add "." to the end of PATH. 59 """ 60 N = len(argA) 61 62 if ('dot' in kw): 63 os.environ['PATH'] = os.environ.get('PATH',"") + ":." 64 65 i = 0 66 while (i < N): 67 arg = argA[i] 68 if (arg == cmdArg): 69 return which(find_cmd(ignoreT, 0, argA[i+1].split())) 70 71 n = argT.get(arg,-1) 72 if (n > 0): 73 i += n + 1 74 continue 75 if (arg[0:1] == "-"): 76 i = i + 1 77 continue 78 break 79 80 path = which(find_cmd(ignoreT, i, argA)) or "unknown" 81 return path
82