\n"""
flist = os.listdir(self.opts.output_dir)
- flist = [x for x in flist if x <> 'Rplots.pdf']
+ flist = [x for x in flist if x != 'Rplots.pdf']
flist.sort()
html = []
html.append(galhtmlprefix % progname)
- html.append('
Galaxy Tool "%s" run at %s
' % (self.scriptname,timenow()))
+ html.append('
Galaxy Tool "%s" run at %s
' % (self.scriptname, timenow()))
fhtml = []
if len(flist) > 0:
- logfiles = [x for x in flist if x.lower().endswith('.log')] # log file names determine sections
+ logfiles = [x for x in flist if x.lower().endswith('.log')] # log file names determine sections
logfiles.sort()
- logfiles = [x for x in logfiles if abspath(x) <> abspath(self.tlog)]
- logfiles.append(abspath(self.tlog)) # make it the last one
+ logfiles = [x for x in logfiles if abspath(x) != abspath(self.tlog)]
+ logfiles.append(abspath(self.tlog)) # make it the last one
pdflist = []
npdf = len([x for x in flist if os.path.splitext(x)[-1].lower() == '.pdf'])
- for rownum,fname in enumerate(flist):
- dname,e = os.path.splitext(fname)
- sfsize = self.getfSize(fname,self.opts.output_dir)
- if e.lower() == '.pdf' : # compress and make a thumbnail
- thumb = '%s.%s' % (dname,self.thumbformat)
- pdff = os.path.join(self.opts.output_dir,fname)
- retval = self.compressPDF(inpdf=pdff,thumbformat=self.thumbformat)
+ for rownum, fname in enumerate(flist):
+ dname, e = os.path.splitext(fname)
+ sfsize = self.getfSize(fname, self.opts.output_dir)
+ if e.lower() == '.pdf': # compress and make a thumbnail
+ thumb = '%s.%s' % (dname, self.thumbformat)
+ pdff = os.path.join(self.opts.output_dir, fname)
+ retval = self.compressPDF(inpdf=pdff, thumbformat=self.thumbformat)
if retval == 0:
- pdflist.append((fname,thumb))
+ pdflist.append((fname, thumb))
else:
- pdflist.append((fname,fname))
- if (rownum+1) % 2 == 0:
- fhtml.append('
' % (fname,fname,sfsize))
- for logfname in logfiles: # expect at least tlog - if more
- if abspath(logfname) == abspath(self.tlog): # handled later
+ fhtml.append('
' % (fname, fname, sfsize))
+ for logfname in logfiles: # expect at least tlog - if more
+ if abspath(logfname) == abspath(self.tlog): # handled later
sectionname = 'All tool run'
if (len(logfiles) > 1):
sectionname = 'Other'
ourpdfs = pdflist
else:
realname = os.path.basename(logfname)
- sectionname = os.path.splitext(realname)[0].split('_')[0] # break in case _ added to log
+ sectionname = os.path.splitext(realname)[0].split('_')[0] # break in case _ added to log
ourpdfs = [x for x in pdflist if os.path.basename(x[0]).split('_')[0] == sectionname]
- pdflist = [x for x in pdflist if os.path.basename(x[0]).split('_')[0] <> sectionname] # remove
+ pdflist = [x for x in pdflist if os.path.basename(x[0]).split('_')[0] != sectionname] # remove
nacross = 1
npdf = len(ourpdfs)
if npdf > 0:
- nacross = math.sqrt(npdf) ## int(round(math.log(npdf,2)))
+ nacross = math.sqrt(npdf)
if int(nacross)**2 != npdf:
nacross += 1
nacross = int(nacross)
- width = min(400,int(1200/nacross))
+ width = min(400, int(1200 / nacross))
html.append('
%s images and outputs
' % sectionname)
html.append('(Click on a thumbnail image to download the corresponding original PDF image) ')
- ntogo = nacross # counter for table row padding with empty cells
+ ntogo = nacross # counter for table row padding with empty cells
html.append('
\n
')
- for i,paths in enumerate(ourpdfs):
- fname,thumb = paths
- s= """
\n""" % (fname,thumb,fname,width,fname)
- if ((i+1) % nacross == 0):
+ for i, paths in enumerate(ourpdfs):
+ fname, thumb = paths
+ s = """
\n""" % (fname, thumb, fname, width, fname)
+ if ((i + 1) % nacross == 0):
s += '
\n'
ntogo = 0
- if i < (npdf - 1): # more to come
- s += '
'
- ntogo = nacross
+ if i < (npdf - 1): # more to come
+ s += '
\n')
- logt = open(logfname,'r').readlines()
+ logt = open(logfname, 'r').readlines()
logtext = [x for x in logt if x.strip() > '']
html.append('
%s log output
' % sectionname)
if len(logtext) > 1:
@@ -311,44 +292,42 @@
else:
html.append('%s is empty ' % logfname)
if len(fhtml) > 0:
- fhtml.insert(0,'
Output File Name (click to view)
Size
\n')
- fhtml.append('
')
- html.append('
All output files available for downloading
\n')
- html += fhtml # add all non-pdf files to the end of the display
+ fhtml.insert(0, '
Output File Name (click to view)
Size
\n')
+ fhtml.append('
')
+ html.append('
All output files available for downloading
\n')
+ html += fhtml # add all non-pdf files to the end of the display
else:
html.append('
### Error - %s returned no files - please confirm that parameters are sane
' % self.opts.interpreter)
html.append(galhtmlpostfix)
- htmlf = file(self.opts.output_html,'w')
- htmlf.write('\n'.join(html))
- htmlf.write('\n')
- htmlf.close()
+ with open(self.opts.output_html, 'w') as htmlf:
+ htmlf.write('\n'.join(html))
+ htmlf.write('\n')
self.html = html
-
def run(self):
"""
scripts must be small enough not to fill the pipe!
"""
- if self.treatbashSpecial and self.opts.interpreter in ['bash','sh']:
- retval = self.runBash()
+ if self.treatbashSpecial and self.opts.interpreter in ['bash', 'sh']:
+ retval = self.runBash()
else:
if self.opts.output_dir:
- ste = open(self.elog,'w')
- sto = open(self.tlog,'w')
+ ste = open(self.elog, 'w')
+ sto = open(self.tlog, 'w')
sto.write('## Toolfactory generated command line = %s\n' % ' '.join(self.cl))
sto.flush()
- p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=ste,stdin=subprocess.PIPE,cwd=self.opts.output_dir)
+ p = subprocess.Popen(self.cl, shell=False, stdout=sto, stderr=ste, stdin=subprocess.PIPE, cwd=self.opts.output_dir)
else:
- p = subprocess.Popen(self.cl,shell=False,stdin=subprocess.PIPE)
+ p = subprocess.Popen(self.cl, shell=False, stdin=subprocess.PIPE)
p.stdin.write(self.script)
p.stdin.close()
retval = p.wait()
if self.opts.output_dir:
sto.close()
ste.close()
- err = open(self.elog,'r').readlines()
- if retval <> 0 and err: # problem
- print >> sys.stderr,err #same problem, need to capture docker stdin/stdout
+ err = open(self.elog, 'r').readlines()
+ if retval != 0 and err: # problem
+ print(err, end="", file=sys.stderr) # same problem, need to capture docker stdin/stdout
if self.opts.make_HTML:
self.makeHtml()
return retval
@@ -359,19 +338,19 @@
"""
if self.opts.output_dir:
s = '## Toolfactory generated command line = %s\n' % ' '.join(self.cl)
- sto = open(self.tlog,'w')
+ sto = open(self.tlog, 'w')
sto.write(s)
sto.flush()
- p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=sto,cwd=self.opts.output_dir)
+ p = subprocess.Popen(self.cl, shell=False, stdout=sto, stderr=sto, cwd=self.opts.output_dir)
else:
- p = subprocess.Popen(self.cl,shell=False)
+ p = subprocess.Popen(self.cl, shell=False)
retval = p.wait()
if self.opts.output_dir:
sto.close()
if self.opts.make_HTML:
self.makeHtml()
return retval
-
+
def change_user_id(new_uid, new_gid):
"""
@@ -386,42 +365,37 @@
def main():
- u = """
- This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as:
- rgBaseScriptWrapper.py --script_path "$scriptPath" --tool_name "foo" --interpreter "Rscript"
-
- """
op = argparse.ArgumentParser()
a = op.add_argument
- a('--docker_image',default=None)
- a('--script_path',default=None)
- a('--tool_name',default=None)
- a('--interpreter',default=None)
- a('--output_dir',default='./')
- a('--output_html',default=None)
- a('--input_tab',default='None', nargs='*')
- a('--output_tab',default='None')
- a('--user_email',default='Unknown')
- a('--bad_user',default=None)
- a('--make_HTML',default=None)
- a('--new_tool',default=None)
- a('--dockerized',default=0)
- a('--group_id',default=None)
- a('--user_id',default=None)
+ a('--docker_image', default=None)
+ a('--script_path', default=None)
+ a('--tool_name', default=None)
+ a('--interpreter', default=None)
+ a('--output_dir', default='./')
+ a('--output_html', default=None)
+ a('--input_file', default='None', nargs='*')
+ a('--output_file', default='None')
+ a('--user_email', default='Unknown')
+ a('--bad_user', default=None)
+ a('--make_HTML', default=None)
+ a('--new_tool', default=None)
+ a('--dockerized', default=0)
+ a('--group_id', default=None)
+ a('--user_id', default=None)
a('--output_format', default='tabular')
a('--input_format', dest='input_formats', action='append', default=[])
a('--additional_parameters', dest='additional_parameters', action='append', default=[])
opts = op.parse_args()
- assert not opts.bad_user,'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to admin_users in universe_wsgi.ini' % (opts.bad_user,opts.bad_user)
- assert os.path.isfile(opts.script_path),'## Tool Factory wrapper expects a script path - eg --script_path=foo.R'
+ assert not opts.bad_user, 'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to admin_users in universe_wsgi.ini' % (opts.bad_user, opts.bad_user)
+ assert os.path.isfile(opts.script_path), '## Tool Factory wrapper expects a script path - eg --script_path=foo.R'
if opts.output_dir:
try:
os.makedirs(opts.output_dir)
- except:
+ except Exception:
pass
- if opts.dockerized==0:
- switch_to_docker(opts)
- return
+ if opts.dockerized == 0:
+ retcode = switch_to_docker(opts)
+ sys.exit(retcode)
change_user_id(opts.user_id, opts.group_id)
os.setgid(int(opts.group_id))
os.setuid(int(opts.user_id))
@@ -429,7 +403,7 @@
retcode = r.run()
os.unlink(r.sfile)
if retcode:
- sys.exit(retcode) # indicate failure to job runner
+ sys.exit(retcode) # indicate failure to job runner
if __name__ == "__main__":
diff -r 315a7e9ed6eb -r 495946ffc2d6 scriptrunner.xml
--- a/scriptrunner.xml Sat Jul 09 17:00:06 2016 -0400
+++ b/scriptrunner.xml Sun Jul 22 13:38:01 2018 -0400
@@ -1,40 +1,40 @@
-
+Runs scripts using dockermacros.xml
- docker-py
+ docker-py
-
- python "$__tool_directory__/scriptrunner.py"
- --script_path "$runme"
- --interpreter "$interpreter"
- --user_email "$__user_email__"
- #if $generate_simple_output.make_TAB=="yes":
- --output_tab "$tab_file"
- #end if
- #if $make_HTML.value=="yes":
- --output_dir "$html_file.files_path" --output_html "$html_file" --make_HTML "yes"
- #else:
- --output_dir "."
- #end if
- #if $additional_parameters != 'None':
- #for i in $additional_parameters:
- --additional_parameters
- "$i.param_name, $i.param_value"
- #end for
- #end if
- #if $input_files != 'None':
- --input_tab
- #for i in $input_files:
- $i.input
- #end for
- #for i in $input_files:
- --input_format "Any"
- #end for
- #end if
- --docker_image "$docker_image"
+
+python '$__tool_directory__/scriptrunner.py'
+--script_path '$runme'
+--interpreter '$interpreter'
+--user_email '$__user_email__'
+#if $generate_simple_output.make_file=="yes":
+ --output_file "$output_file"
+#end if
+#if $make_HTML.value=="yes":
+ --output_dir "$html_file.files_path" --output_html "$html_file" --make_HTML "yes"
+#else:
+ --output_dir "."
+#end if
+#if $additional_parameters != 'None':
+ #for i in $additional_parameters:
+ --additional_parameters
+ "$i.param_name, $i.param_value"
+ #end for
+#end if
+#if $input_files != 'None':
+ --input_file
+ #for i in $input_files:
+ $i.input
+ #end for
+ #for i in $input_files:
+ --input_format "Any"
+ #end for
+#end if
+--docker_image "$docker_image"
$dynScript
@@ -64,8 +64,8 @@
-
+
@@ -89,7 +89,7 @@
+ help="Script must deal with two command line parameters: Path to input file path (or 'None' if none selected) and path to output tabular history file (or 'None').">
@@ -98,8 +98,8 @@
-
- generate_simple_output['make_TAB'] == "yes"
+
+ generate_simple_output['make_file'] == "yes"
@@ -112,14 +112,14 @@
-
-
-
-
-
+
+
+
+
+
-
-
+
+
diff -r 315a7e9ed6eb -r 495946ffc2d6 test-data/tf2_test.html
--- a/test-data/tf2_test.html Sat Jul 09 17:00:06 2016 -0400
+++ b/test-data/tf2_test.html Sun Jul 22 13:38:01 2018 -0400
@@ -1,25 +1,25 @@
-
-
-
-
-
-
-
-
-
-
-
Galaxy Tool "script" run at 09/07/2016 11:37:54
+
+
+
+
+
+
+
+
+
+
+
Galaxy Tool "script" run at 22/07/2018 17:09:47
script log output
script_error.log is empty
Other log output
-/tmp/tmpG7m9zp/job_working_directory/000/1/dataset_2_files/script_runner.log is empty
+/private/var/folders/df/6xqpqpcd7h73b6jpx9t6cwhw0000gn/T/tmptx2hJF/job_working_directory/000/1/dataset_2_files/script_runner.log is empty