Expand file tree
/
Copy pathvmtk.py
More file actions
Latest commit
executable file
·121 lines (99 loc) · 4.22 KB
/
Copy pathvmtk.py
File metadata and controls
executable file
·121 lines (99 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python
importsys
importos
if__name__=='__main__':
ifsys.platform=='darwin':
ldEnvironmentVariable="DYLD_LIBRARY_PATH"
elifsys.platform=='win32':
ldEnvironmentVariable="PATH"
else:
ldEnvironmentVariable="LD_LIBRARY_PATH"
currentEnviron=dict()
currentEnviron[ldEnvironmentVariable] =""
currentEnviron["PYTHONPATH"] =""
ifos.environ.has_key(ldEnvironmentVariable):
currentEnviron[ldEnvironmentVariable] =os.environ[ldEnvironmentVariable]
ifos.environ.has_key("PYTHONPATH"):
currentEnviron["PYTHONPATH"] =os.environ["PYTHONPATH"]
newEnviron= {}
vmtkhome=os.path.dirname(os.path.abspath(__file__))
ifvmtkhome.endswith('bin'):
vmtkhome=os.path.join(os.path.dirname(os.path.abspath(__file__)),"..")
else:
vmtkhome=os.path.join(os.path.dirname(os.path.abspath(__file__)),"..","..","..")
vtkdir= [elforelinos.listdir(os.path.join(vmtkhome,"lib")) ifel.startswith('vtk')][0]
newEnviron[ldEnvironmentVariable] =os.path.join(vmtkhome,"bin") +os.path.pathsep+ \
os.path.join(vmtkhome,"lib",vtkdir) +os.path.pathsep+ \
os.path.join(vmtkhome,"lib","vmtk") +os.path.pathsep+ \
os.path.join(vmtkhome,"lib","InsightToolkit")
os.environ[ldEnvironmentVariable] =newEnviron[ldEnvironmentVariable] +os.path.pathsep+currentEnviron[ldEnvironmentVariable]
sys.path.append(os.path.join(vmtkhome,"bin","Python"))
sys.path.append(os.path.join(vmtkhome,"lib",vtkdir))
sys.path.append(os.path.join(vmtkhome,"lib","vmtk"))
fromvmtkimportpypes
vmtkOptions= ['--help', '--ui', '--file']
iflen(sys.argv) >1andsys.argv[1] notinvmtkOptions:
arguments=sys.argv[1:]
print"Executing", ' '.join(arguments)
pipe=pypes.Pype()
pipe.ExitOnError=0
pipe.Arguments=arguments
pipe.ParseArguments()
pipe.Execute()
sys.exit(0)
eliflen(sys.argv) >1and'--file'insys.argv:
fileindex=sys.argv.index('--file')+1
iffileindex<len(sys.argv):
inputfile=open(sys.argv[fileindex],'r')
physicalLines= [lineforlineininputfile.readlines() iflineandline.strip() andline.strip()[0]!='#']
lines= []
forlineinphysicalLines:
iflinesandlines[-1].endswith('\\\n'):
lines[-1] =lines[-1][:-2] +line
else:
lines.append(line)
forlineinlines:
pipe=pypes.Pype()
pipe.ExitOnError=0
pipe.Arguments=line.split()
pipe.ParseArguments()
pipe.Execute()
elif'--help'insys.argv:
print'Usage: \tvmtk [--ui pad|console]\t\tStart in interactive mode\n\tvmtk [PYPE]\t\t\tExecute the pype [PYPE]\n\tvmtk --file [FILE]\t\tExecute the content of file [FILE]'
sys.exit(0)
else:
ui='pad'
if'--ui'insys.argvandsys.argv.index('--ui') !=len(sys.argv)-1:
ui=sys.argv[sys.argv.index('--ui')+1]
ifui=='pad':
try:
fromvmtkimportpypepad
exceptImportError:
ui='console'
else:
pypepad.RunPypeTkPad()
ifui=='console':
try:
importreadline
exceptImportError:
pass
else:
readline.parse_and_bind("tab: complete")
while1:
try:
inputString=raw_input("vmtk> ")
exceptEOFError:
sys.stdout.write('\n')
sys.exit(0)
ifnotinputString:
continue
print"Executing", inputString
splitString=inputString.split()
pipe=pypes.Pype()
pipe.ExitOnError=0
pipe.Arguments=inputString.split()
pipe.ParseArguments()
try:
pipe.Execute()
exceptException:
continue