changeset 7:ef0297b352d8 draft

Uploaded
author fubar
date Fri, 19 Dec 2014 18:22:38 -0500
parents 42637d352d09
children 4e4f094c338c
files rgToolFactory.py
diffstat 1 files changed, 48 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/rgToolFactory.py	Fri Dec 19 17:03:32 2014 -0500
+++ b/rgToolFactory.py	Fri Dec 19 18:22:38 2014 -0500
@@ -153,12 +153,14 @@
         self.html = []
         a = self.cl.append
         a(opts.interpreter)
-        if self.treatbashSpecial and opts.interpreter in ['bash','sh']:
-            a(self.sfile)
-        else:
-            a('-') # stdin
-        a(opts.input_tab)
-        a(opts.output_tab)
+        # cannot use pipe input on test - change so always eg Rscript myscript.R
+        #if self.treatbashSpecial and opts.interpreter in ['bash','sh']:
+        #    a(self.sfile)
+        #else:
+        #    a('-') # stdin
+        #a(opts.input_tab)
+        #a(opts.output_tab)
+        a(self.sfile)
         self.outFormats = 'tabular' # TODO make this an option at tool generation time
         self.inputFormats = 'tabular' # TODO make this an option at tool generation time
         self.test1Input = '%s_test1_input.xls' % self.toolname
@@ -538,14 +540,52 @@
         htmlf.close()
         self.html = html
 
-
     def run(self):
         """
         scripts must be small enough not to fill the pipe!
         """
         my_env = os.environ.copy()
         if self.treatbashSpecial and self.opts.interpreter in ['bash','sh']:
-          retval = self.runBash(pth)
+          retval = self.runBash()
+        else:
+            if self.opts.output_dir:
+                ste = open(self.elog,'w')
+                sto = open(self.tlog,'w')
+                sto.write('## Toolfactory running %s as %s script\n' % (self.toolname,self.opts.interpreter))
+                sto.flush()
+                p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=ste,cwd=self.opts.output_dir,env=my_env)
+            else:
+                p = subprocess.Popen(self.cl,shell=False,cwd=self.opts.output_dir,env=my_env)
+            # p.stdin.write(self.script)
+            #print >> p.stdin, self.script
+            #p.stdin.close()
+            retval = p.wait()
+            if self.opts.output_dir:
+                sto.close()
+                ste.close()
+                # get stderr, allowing for case where it's very large
+                tmp_stderr = open( self.elog, 'rb' )
+                stderr = ''
+                try:
+                    while True:
+                        stderr += tmp_stderr.read( buffsize )
+                        if not stderr or len( stderr ) % buffsize != 0:
+                            break
+                except OverflowError:
+                    pass
+                tmp_stderr.close()
+            if self.opts.make_HTML:
+                self.makeHtml()
+        return retval
+
+    def old_run(self):
+        """
+        can't use pipe as stdin on test. go figure
+        scripts must be small enough not to fill the pipe!
+        """
+        my_env = os.environ.copy()
+        if self.treatbashSpecial and self.opts.interpreter in ['bash','sh']:
+          retval = self.runBash()
         else:
             if self.opts.output_dir:
                 ste = open(self.elog,'w')