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