annotate imagej2_base_utils.py @ 0:64aacdf3171f draft

planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
author iuc
date Fri, 19 Jun 2015 16:59:58 -0400
parents
children 0ff301860507
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
1 import os
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
2 import shutil
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
3 import sys
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
4 import tempfile
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
5
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
6 FIJI_JAR_DIR = os.environ.get( 'FIJI_JAR_DIR', None )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
7 FIJI_OSX_JAVA3D_DIR = os.environ.get( 'FIJI_OSX_JAVA3D_DIR', None )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
8 FIJI_PLUGIN_DIR = os.environ.get( 'FIJI_PLUGIN_DIR', None )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
9 FIJI_ROOT_DIR = os.environ.get( 'FIJI_ROOT_DIR', None )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
10
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
11 BUFF_SIZE = 1048576
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
12
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
13 def cleanup_before_exit( tmp_dir ):
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
14 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
15 Remove temporary files and directories prior to tool exit.
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
16 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
17 if tmp_dir and os.path.exists( tmp_dir ):
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
18 shutil.rmtree( tmp_dir )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
19
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
20 def get_base_cmd_bunwarpj( jvm_memory ):
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
21 if FIJI_JAR_DIR is not None and FIJI_PLUGIN_DIR is not None:
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
22 if jvm_memory in [ None, 'None' ]:
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
23 jvm_memory_str = ''
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
24 else:
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
25 jvm_memory_str = '-Xmx%s' % jvm_memory
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
26 bunwarpj_base_cmd = "java %s -cp %s/ij-1.49k.jar:%s/bUnwarpJ_-2.6.1.jar bunwarpj.bUnwarpJ_" % \
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
27 ( jvm_memory_str, FIJI_JAR_DIR, FIJI_PLUGIN_DIR )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
28 return bunwarpj_base_cmd
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
29 return None
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
30
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
31 def get_base_command_imagej2( memory_size=None, macro=None, jython_script=None ):
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
32 imagej2_executable = get_imagej2_executable()
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
33 if imagej2_executable:
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
34 cmd = '%s --headless -DXincgc' % imagej2_executable
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
35 if memory_size is not None:
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
36 memory_size_cmd = ' -DXms=%s -DXmx=%s' % ( memory_size, memory_size )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
37 cmd += memory_size_cmd
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
38 if macro is not None:
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
39 cmd += ' --macro %s' % os.path.abspath( macro )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
40 if jython_script is not None:
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
41 cmd += ' --jython -u %s' % os.path.abspath( jython_script )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
42 return cmd
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
43 return None
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
44
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
45 def get_file_extension( image_format ):
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
46 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
47 Return a valid bioformats file extension based on the received
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
48 value of image_format( e.g., "gif" is returned as ".gif".
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
49 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
50 return '.%s' % image_format
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
51
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
52 def get_file_name_without_extension( file_path ):
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
53 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
54 Eliminate the .ext from the received file name, assuming that
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
55 the file name consists of only a single '.'.
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
56 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
57 if os.path.exists( file_path ):
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
58 path, name = os.path.split( file_path )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
59 name_items = name.split( '.' )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
60 return name_items[ 0 ]
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
61 return None
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
62
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
63 def get_imagej2_executable():
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
64 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
65 Fiji names the ImageJ executable different names for different
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
66 architectures, so figure out which name we need.
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
67 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
68 platform_dict = get_platform_info_dict()
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
69 if platform_dict.get( 'architecture', None ) in [ 'x86_64' ]:
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
70 if platform_dict.get( 'os', None ) in [ 'darwin' ]:
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
71 return 'ImageJ-macosx'
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
72 if platform_dict.get( 'os', None ) in [ 'linux' ]:
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
73 return 'ImageJ-linux64'
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
74 return None
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
75
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
76 def get_input_image_path( tmp_dir, input_file, image_format ):
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
77 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
78 Bioformats uses file extensions (e.g., .job, .gif, etc)
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
79 when reading and writing image files, so the Galaxy dataset
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
80 naming convention of setting all file extensions as .dat
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
81 must be handled.
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
82 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
83 image_path = get_temporary_image_path( tmp_dir, image_format )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
84 # Remove the file so we can create a symlink.
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
85 os.remove( image_path )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
86 os.symlink( input_file, image_path )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
87 return image_path
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
88
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
89 def get_max_heap_size_value( max_heap_size_type, max_heap_size ):
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
90 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
91 Return a string that can be used by the javabridge to set the size
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
92 of the memory allocation pool used by the JVM. The value must be
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
93 determined to be a multiple of 1024 or it will be ignored.
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
94 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
95 if max_heap_size_type == 'default':
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
96 return None
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
97 if max_heap_size_type == 'megabytes':
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
98 if max_heap_size % 1024 not in [ 0, 256, 512 ]:
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
99 return None
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
100 return '%sm' % str( max_heap_size )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
101 if max_heap_size_type == 'gigabytes':
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
102 return '%sg' % str( max_heap_size )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
103
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
104 def get_platform_info_dict():
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
105 '''Return a dict with information about the current platform.'''
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
106 platform_dict = {}
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
107 sysname, nodename, release, version, machine = os.uname()
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
108 platform_dict[ 'os' ] = sysname.lower()
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
109 platform_dict[ 'architecture' ] = machine.lower()
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
110 return platform_dict
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
111
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
112 def get_stderr_exception( tmp_err, tmp_stderr, tmp_stdout ):
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
113 tmp_stderr.close()
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
114 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
115 Return a stderr string of reasonable size.
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
116 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
117 # Get stderr, allowing for case where it's very large.
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
118 tmp_stderr = open( tmp_err, 'rb' )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
119 stderr_str = ''
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
120 buffsize = BUFF_SIZE
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
121 try:
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
122 while True:
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
123 stderr_str += tmp_stderr.read( buffsize )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
124 if not stderr_str or len( stderr_str ) % buffsize != 0:
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
125 break
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
126 except OverflowError:
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
127 pass
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
128 tmp_stderr.close()
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
129 tmp_stdout.close()
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
130 return str( stderr_str )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
131
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
132 def get_temp_dir( prefix='tmp-imagej-', dir=None ):
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
133 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
134 Return a temporary directory.
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
135 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
136 return tempfile.mkdtemp( prefix=prefix, dir=dir )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
137
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
138 def get_tempfilename( dir=None, suffix=None ):
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
139 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
140 Return a temporary file name.
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
141 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
142 fd, name = tempfile.mkstemp( suffix=suffix, dir=dir )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
143 os.close( fd )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
144 return name
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
145
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
146 def get_temporary_image_path( tmp_dir, image_format ):
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
147 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
148 Return the path to a temporary file with a valid image format
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
149 file extension that can be used with bioformats.
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
150 """
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
151 file_extension = get_file_extension( image_format )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
152 return get_tempfilename( tmp_dir, file_extension )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
153
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
154 def stop_err( msg ):
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
155 sys.stderr.write( msg )
64aacdf3171f planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
156 sys.exit( 1 )