comparison icqsol_utils.py @ 0:e778cabd999c draft

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