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