Mercurial > repos > fubar > brokenandnotdeletablebyowneroradmin
annotate rgDynamicScriptWrapper.py @ 2:d95513e50c92
Add README.txt for bitbucket
author | ross lazarus ross.lazarus@gmail.com |
---|---|
date | Thu, 31 May 2012 09:35:18 +1000 |
parents | 0133b97e477e |
children |
rev | line source |
---|---|
0
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
1 # rgDynamicScriptWrapper.py |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
2 # derived from |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
3 # rgBaseScriptWrapper.py |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
4 # to run some user supplied code |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
5 # extremely dangerous |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
6 # trusted users only - private site only |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
7 # a list in the xml is searched - only users in the list can run this tool. |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
8 # |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
9 # copyright ross lazarus (ross.lazarus@gmail.com) May 2012 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
10 # |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
11 # all rights reserved |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
12 # Licensed under the LGPL for your pleasure |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
13 # Derived from rgDGE.py in May 2012 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
14 # generalized to run required interpreter |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
15 # to make your own tools based on a given script and interpreter such as perl or python |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
16 # clone this and the corresponding xml wrapper |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
17 # replace the parameters/inputs/outputs and the configfile contents with your script |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
18 # Use the $foo syntax to place your parameter values inside the script to assign them - at run time, the script will be used as a template |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
19 # and returned as part of the output to the user - with the right values for all the parameters. |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
20 # Note that this assumes you want all the outputs arranged as a single Html file output |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
21 # after this generic script runner runs your script with the specified interpreter, |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
22 # it will collect all output files into the specified output_html, making thumbnails for all the pdfs it finds and making links for all the other files. |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
23 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
24 import sys |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
25 import shutil |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
26 import subprocess |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
27 import os |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
28 import time |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
29 import tempfile |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
30 import optparse |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
31 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
32 progname = os.path.split(sys.argv[0])[1] |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
33 myversion = 'V000.1 May 2012' |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
34 verbose = False |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
35 debug = False |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
36 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
37 # characters that are allowed but need to be escaped |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
38 # also a test sandboxing of any R system commands |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
39 # ultimately futile - we need to generate a new tool |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
40 # which will have no new security problems! |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
41 mapped_chars = { '>' :'__gt__', |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
42 '<' :'__lt__', |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
43 "'" :'__sq__', |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
44 '"' :'__dq__', |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
45 '{' :'__oc__', |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
46 '}' :'__cc__', |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
47 '@' : '__at__', |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
48 '\n' : '__cn__', |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
49 '\r' : '__cr__', |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
50 '\t' : '__tc__', |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
51 '#' : '__pd__', |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
52 '[' :'__ob__', |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
53 ']' :'__cb__', |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
54 '\t' : 'Xt', |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
55 'systemCallsAreNotAllowed' : 'system' |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
56 } |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
57 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
58 galhtmlprefix = """<?xml version="1.0" encoding="utf-8" ?> |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
59 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
60 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
61 <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
62 <meta name="generator" content="Galaxy %s tool output - see http://g2.trac.bx.psu.edu/" /> |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
63 <title></title> |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
64 <link rel="stylesheet" href="/static/style/base.css" type="text/css" /> |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
65 </head> |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
66 <body> |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
67 <div class="document"> |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
68 """ |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
69 galhtmlattr = """<b><a href="http://rgenetics.org">Galaxy Rgenetics Base Script Wrapper based </a> tool output %s run at %s</b><br/>""" |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
70 galhtmlpostfix = """</div></body></html>\n""" |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
71 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
72 def timenow(): |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
73 """return current time as a string |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
74 """ |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
75 return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time())) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
76 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
77 def restore_text(text): |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
78 """Restores sanitized text""" |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
79 if not text: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
80 return text |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
81 for key, value in mapped_chars.items(): |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
82 text = text.replace(value, key) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
83 return text |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
84 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
85 class ScriptRunner: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
86 """class is a wrapper for an arbitrary script |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
87 """ |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
88 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
89 def __init__(self,opts=None): |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
90 """ |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
91 run the script |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
92 cheetah/galaxy will provide an escaped string so |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
93 __pd__ your script goes here |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
94 __cr____cn__ourargs __lt__- commandArgs(TRUE) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
95 __cr____cn__inf = ourargs[1] |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
96 __cr____cn__outf = ourargs[2] |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
97 __cr____cn__inp = read.table(inf,head=T,rownames=F,sep=__sq__Xt__sq__) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
98 __cr____cn__ write.table(inp,outf, quote=FALSE, sep=__dq__Xt__dq__,row.names=F) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
99 __cr____cn__sessionInfo() |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
100 __cr____cn__ |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
101 """ |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
102 self.thumbformat = 'jpg' |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
103 self.opts = opts |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
104 self.toolname = opts.tool_name.replace(' ','_') |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
105 s = open(self.opts.script_path,'r').read() |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
106 self.script = restore_text(s) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
107 if opts.output_dir: # may not want these complexities if a simple script |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
108 self.tlog = os.path.join(opts.output_dir,"%s_runner.log" % self.toolname) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
109 artifactpath = os.path.join(opts.output_dir,'%s_run.script' % self.toolname) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
110 artifact = open(artifactpath,'w') |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
111 artifact.write(self.script) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
112 artifact.write('\n') |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
113 artifact.close() |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
114 self.cl = [] |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
115 a = self.cl.append |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
116 a(opts.interpreter) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
117 a('-') # use stdin |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
118 a(opts.input_tab) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
119 a(opts.output_tab) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
120 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
121 def compressPDF(self,inpdf=None,thumbformat='png'): |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
122 """need absolute path to pdf |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
123 """ |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
124 assert os.path.isfile(inpdf), "## Input %s supplied to %s compressPDF not found" % (inpdf,self.myName) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
125 hf,hlog = tempfile.mkstemp(suffix="%s.log" % self.toolname) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
126 sto = open(hlog,'w') |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
127 outpdf = '%s_compressed' % inpdf |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
128 cl = ["gs", "-sDEVICE=pdfwrite", "-dNOPAUSE", "-dBATCH", "-sOutputFile=%s" % outpdf,inpdf] |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
129 x = subprocess.Popen(cl,stdout=sto,stderr=sto,cwd=self.opts.output_dir) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
130 retval1 = x.wait() |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
131 if retval1 == 0: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
132 os.unlink(inpdf) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
133 shutil.move(outpdf,inpdf) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
134 outpng = '%s.%s' % (os.path.splitext(inpdf)[0],thumbformat) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
135 cl2 = ['convert', inpdf, outpng] |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
136 x = subprocess.Popen(cl2,stdout=sto,stderr=sto,cwd=self.opts.output_dir) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
137 retval2 = x.wait() |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
138 sto.close() |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
139 retval = retval1 or retval2 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
140 return retval |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
141 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
142 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
143 def getfSize(self,fpath,outpath): |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
144 """ |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
145 format a nice file size string |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
146 """ |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
147 size = '' |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
148 fp = os.path.join(outpath,fpath) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
149 if os.path.isfile(fp): |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
150 n = float(os.path.getsize(fp)) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
151 if n > 2**20: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
152 size = ' (%1.1f MB)' % (n/2**20) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
153 elif n > 2**10: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
154 size = ' (%1.1f KB)' % (n/2**10) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
155 elif n > 0: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
156 size = ' (%d B)' % (int(n)) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
157 return size |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
158 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
159 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
160 def run(self): |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
161 """ |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
162 """ |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
163 if self.opts.output_dir: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
164 sto = open(self.tlog,'w') |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
165 p = subprocess.Popen(' '.join(self.cl),shell=True,stdout=sto,stderr=sto,stdin=subprocess.PIPE,cwd=self.opts.output_dir) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
166 else: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
167 p = subprocess.Popen(' '.join(self.cl),shell=True,stdin=subprocess.PIPE) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
168 p.stdin.write(self.script) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
169 p.stdin.close() |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
170 retval = p.wait() |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
171 if self.opts.output_dir: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
172 sto.close() |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
173 flist = os.listdir(self.opts.output_dir) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
174 flist = [x for x in flist if x <> 'Rplots.pdf'] |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
175 flist.sort() |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
176 html = [galhtmlprefix % progname,] |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
177 html.append('<h2>Galaxy %s outputs run at %s</h2></br>Click on a thumbnail below to download the original PDF</br>\n' % (self.toolname,timenow())) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
178 fhtml = [] |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
179 if len(flist) > 0: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
180 html.append('<table cellpadding="3" cellspacing="3">\n') |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
181 for fname in flist: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
182 dname,e = os.path.splitext(fname) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
183 sfsize = self.getfSize(fname,self.opts.output_dir) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
184 if e.lower() == '.pdf' : # compress and make a thumbnail |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
185 thumb = '%s.%s' % (dname,self.thumbformat) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
186 pdff = os.path.join(self.opts.output_dir,fname) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
187 retval = self.compressPDF(inpdf=pdff,thumbformat=self.thumbformat) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
188 if retval == 0: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
189 s= '<tr><td><a href="%s"><img src="%s" title="Click to download a PDF of %s" hspace="10" width="600"></a></td></tr>\n' % (fname,thumb,fname) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
190 html.append(s) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
191 fhtml.append('<li><a href="%s">%s %s</a></li>' % (fname,fname,sfsize)) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
192 else: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
193 fhtml.append('<li><a href="%s">%s %s</a></li>' % (fname,fname,sfsize)) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
194 html.append('</table>\n') |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
195 if len(fhtml) > 0: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
196 fhtml.insert(0,'<ul>') |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
197 fhtml.append('</ul>') |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
198 html += fhtml # add all non-pdf files to the end of the display |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
199 else: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
200 html.append('<h2>### Error - %s returned no files - please confirm that parameters are sane</h1>' % self.opts.interpreter) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
201 html.append('<h3>%s log follows below</h3><hr><pre>\n' % self.opts.interpreter) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
202 rlog = open(self.tlog,'r').readlines() |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
203 html += rlog |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
204 html.append('%s CL = %s</br>\n' % (self.toolname,' '.join(sys.argv))) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
205 html.append('CL = %s</br>\n' % (' '.join(self.cl))) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
206 html.append('</pre>\n') |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
207 html.append(galhtmlattr % (progname,timenow())) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
208 html.append(galhtmlpostfix) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
209 htmlf = file(self.opts.output_html,'w') |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
210 htmlf.write('\n'.join(html)) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
211 htmlf.write('\n') |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
212 htmlf.close() |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
213 return retval |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
214 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
215 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
216 def main(): |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
217 u = """ |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
218 This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
219 <command interpreter="python">rgBaseScriptWrapper.py --script_path "$scriptPath" --tool_name "foo" --interpreter "Rscript" |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
220 </command> |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
221 """ |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
222 permitted_users = ['rlazarus@bakeridi.edu.au','akaspi@bakeridi.edu.au','mziemann@bakeridi.edu.edu'] |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
223 op = optparse.OptionParser() |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
224 a = op.add_option |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
225 a('--script_path',default=None) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
226 a('--tool_name',default=None) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
227 a('--interpreter',default=None) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
228 a('--output_dir',default=None) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
229 a('--output_html',default=None) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
230 a('--input_tab',default='NONE') |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
231 a('--output_tab',default='NONE') |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
232 a('--user_email',default=None) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
233 a('--bad_user',default=None) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
234 opts, args = op.parse_args() |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
235 assert not opts.bad_user,'%s is NOT authorized to use this tool. Please ask your friendly admin' % opts.bad_user |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
236 assert opts.tool_name,'## Dynamic script wrapper expects a tool name - eg --tool_name=DESeq' |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
237 assert opts.interpreter,'## Dynamic script wrapper expects an interpreter - eg --interpreter=Rscript' |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
238 assert os.path.isfile(opts.script_path),'## Dynamic script wrapper expects a script path - eg --script_path=foo.R' |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
239 if opts.output_dir: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
240 try: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
241 os.makedirs(opts.output_dir) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
242 except: |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
243 pass |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
244 r = ScriptRunner(opts) |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
245 retcode = r.run() |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
246 if retcode: |
1
0133b97e477e
Write to stderr to force job runner to realise that the tool failed - it ignores return codes :(
ross lazarus ross.lazarus@gmail.com
parents:
0
diff
changeset
|
247 print >> sys.stderr,'Executing your script %s failed - return code was %d' % (opts.tool_name,retcode) |
0
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
248 sys.exit(retcode) # indicate failure to job runner |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
249 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
250 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
251 if __name__ == "__main__": |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
252 main() |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
253 |
fda8032fe989
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
ross lazarus ross.lazarus@gmail.com
parents:
diff
changeset
|
254 |