0
|
1 import os
|
|
2 import sys
|
|
3 import tempfile
|
|
4
|
5
|
5 PLY = 'ply'
|
4
|
6 POLYDATA = 'POLYDATA'
|
5
|
7 VTK = 'vtk'
|
4
|
8
|
0
|
9
|
4
|
10 def asbool(val):
|
|
11 return str(val).lower() in ['yes', 'true']
|
0
|
12
|
4
|
13
|
|
14 def get_format_and_type(galaxy_ext):
|
0
|
15 # Define the output file format and type.
|
|
16 format = None
|
|
17 datatype = None
|
4
|
18 if galaxy_ext in ['vtkascii', 'vtkbinary']:
|
5
|
19 format = VTK
|
4
|
20 elif galaxy_ext in ['plyascii', 'plybinary']:
|
5
|
21 format = PLY
|
4
|
22 if galaxy_ext in ['vtkascii', 'plyascii']:
|
0
|
23 datatype = 'ascii'
|
4
|
24 elif galaxy_ext in ['vtkbinary', 'plybinary']:
|
0
|
25 datatype = 'binary'
|
|
26 return format, datatype
|
|
27
|
4
|
28
|
|
29 def get_input_file_path(tmp_dir, input_file, format):
|
0
|
30 """
|
|
31 iCqSol uses file extensions (e.g., .ply, .vtk) when reading and
|
|
32 writing files, so the Galaxy dataset naming convention of
|
|
33 setting all file extensions as .dat must be handled.
|
|
34 """
|
4
|
35 file_path = get_temporary_file_path(tmp_dir, format)
|
0
|
36 # Remove the file so we can create a symlink.
|
4
|
37 os.remove(file_path)
|
|
38 os.symlink(input_file, file_path)
|
0
|
39 return file_path
|
|
40
|
4
|
41
|
|
42 def get_temp_dir(prefix='tmp-vtk-', dir=None):
|
0
|
43 """
|
|
44 Return a temporary directory.
|
|
45 """
|
4
|
46 return tempfile.mkdtemp(prefix=prefix, dir=dir)
|
0
|
47
|
4
|
48
|
|
49 def get_tempfilename(dir=None, suffix=None):
|
0
|
50 """
|
|
51 Return a temporary file name.
|
|
52 """
|
9
|
53 if suffix is None:
|
|
54 s = None
|
|
55 elif suffix.startswith('.'):
|
|
56 s = suffix
|
|
57 else:
|
|
58 s = '.%s' % suffix
|
|
59 fd, name = tempfile.mkstemp(suffix=s, dir=dir)
|
4
|
60 os.close(fd)
|
0
|
61 return name
|
|
62
|
4
|
63
|
|
64 def get_temporary_file_path(tmp_dir, file_extension):
|
0
|
65 """
|
|
66 Return the path to a temporary file with a valid VTK format
|
|
67 file extension.
|
|
68 """
|
4
|
69 return get_tempfilename(tmp_dir, file_extension)
|
|
70
|
0
|
71
|
4
|
72 def stop_err(msg):
|
|
73 sys.stderr.write("%s\n" % msg)
|
0
|
74 sys.exit()
|