0
|
1 import os
|
|
2 import sys
|
|
3 import tempfile
|
|
4
|
6
|
5 PLY = 'ply'
|
5
|
6 POLYDATA = 'POLYDATA'
|
6
|
7 VTK = 'vtk'
|
5
|
8
|
0
|
9
|
5
|
10 def asbool(val):
|
|
11 return str(val).lower() in ['yes', 'true']
|
0
|
12
|
5
|
13
|
|
14 def get_format_and_type(galaxy_ext):
|
0
|
15 # Define the output file format and type.
|
|
16 format = None
|
|
17 datatype = None
|
5
|
18 if galaxy_ext in ['vtkascii', 'vtkbinary']:
|
6
|
19 format = VTK
|
5
|
20 elif galaxy_ext in ['plyascii', 'plybinary']:
|
6
|
21 format = PLY
|
5
|
22 if galaxy_ext in ['vtkascii', 'plyascii']:
|
0
|
23 datatype = 'ascii'
|
5
|
24 elif galaxy_ext in ['vtkbinary', 'plybinary']:
|
0
|
25 datatype = 'binary'
|
|
26 return format, datatype
|
|
27
|
5
|
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 """
|
5
|
35 file_path = get_temporary_file_path(tmp_dir, format)
|
0
|
36 # Remove the file so we can create a symlink.
|
5
|
37 os.remove(file_path)
|
|
38 os.symlink(input_file, file_path)
|
0
|
39 return file_path
|
|
40
|
5
|
41
|
|
42 def get_temp_dir(prefix='tmp-vtk-', dir=None):
|
0
|
43 """
|
|
44 Return a temporary directory.
|
|
45 """
|
5
|
46 return tempfile.mkdtemp(prefix=prefix, dir=dir)
|
0
|
47
|
5
|
48
|
|
49 def get_tempfilename(dir=None, suffix=None):
|
0
|
50 """
|
|
51 Return a temporary file name.
|
|
52 """
|
5
|
53 fd, name = tempfile.mkstemp(suffix=suffix, dir=dir)
|
|
54 os.close(fd)
|
0
|
55 return name
|
|
56
|
5
|
57
|
|
58 def get_temporary_file_path(tmp_dir, file_extension):
|
0
|
59 """
|
|
60 Return the path to a temporary file with a valid VTK format
|
|
61 file extension.
|
|
62 """
|
5
|
63 return get_tempfilename(tmp_dir, file_extension)
|
|
64
|
0
|
65
|
5
|
66 def stop_err(msg):
|
|
67 sys.stderr.write("%s\n" % msg)
|
0
|
68 sys.exit()
|