diff imagej2_base_utils.py @ 3:9a24b7e68010 draft

planemo upload commit 8f8692e83217a072a3ed928469621f1f606ab28a-dirty
author iuc
date Tue, 04 Aug 2015 11:15:04 -0400
parents cf9ed4ef641d
children 7a8b05b111f9
line wrap: on
line diff
--- a/imagej2_base_utils.py	Fri Jun 26 05:28:18 2015 -0400
+++ b/imagej2_base_utils.py	Tue Aug 04 11:15:04 2015 -0400
@@ -30,17 +30,17 @@
 
 def get_base_command_imagej2( memory_size=None, macro=None, jython_script=None ):
     imagej2_executable = get_imagej2_executable()
-    if imagej2_executable:
-        cmd = '%s --headless -DXincgc' % imagej2_executable
-        if memory_size is not None:
-            memory_size_cmd = ' -DXms=%s -DXmx=%s' % ( memory_size, memory_size )
-            cmd += memory_size_cmd
-        if macro is not None:
-            cmd += ' --macro %s' % os.path.abspath( macro )
-        if jython_script is not None:
-            cmd += ' --jython -u %s' % os.path.abspath( jython_script )
-        return cmd
-    return None
+    if imagej2_executable is None:
+        return None
+    cmd = '%s --ij2 --headless --debug' % imagej2_executable
+    if memory_size is not None:
+        memory_size_cmd = ' -DXms=%s -DXmx=%s' % ( memory_size, memory_size )
+        cmd += memory_size_cmd
+    if macro is not None:
+        cmd += ' --macro %s' % os.path.abspath( macro )
+    if jython_script is not None:
+        cmd += ' --jython %s' % os.path.abspath( jython_script )
+    return cmd
 
 def get_file_extension( image_format ):
     """
@@ -109,7 +109,7 @@
     platform_dict[ 'architecture' ] = machine.lower()
     return platform_dict
 
-def get_stderr_exception( tmp_err, tmp_stderr, tmp_stdout ):
+def get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout, include_stdout=False ):
     tmp_stderr.close()
     """
     Return a stderr string of reasonable size.
@@ -126,8 +126,21 @@
     except OverflowError:
         pass
     tmp_stderr.close()
+    if include_stdout:
+        tmp_stdout = open( tmp_out, 'rb' )
+        stdout_str = ''
+        buffsize = BUFF_SIZE
+        try:
+            while True:
+                stdout_str += tmp_stdout.read( buffsize )
+                if not stdout_str or len( stdout_str ) % buffsize != 0:
+                    break
+        except OverflowError:
+            pass
     tmp_stdout.close()
-    return str( stderr_str )
+    if include_stdout:
+        return 'STDOUT\n%s\n\nSTDERR\n%s\n' % ( stdout_str, stderr_str )
+    return stderr_str
 
 def get_temp_dir( prefix='tmp-imagej-', dir=None ):
     """
@@ -151,6 +164,15 @@
     file_extension = get_file_extension( image_format )
     return get_tempfilename( tmp_dir, file_extension )
 
+def handle_none_type( val, val_type='float' ):
+    if val is None:
+        return ' None'
+    else:
+        if val_type == 'float':
+            return ' %.1f' % val
+        elif val_type == 'int':
+            return ' %d' % val
+
 def stop_err( msg ):
     sys.stderr.write( msg )
     sys.exit( 1 )