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