Script xalt_parse_mpirun_args_in_py
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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