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