Mercurial > repos > fubar > toolfactory
annotate rgToolFactory.py @ 20:812871c1eaec draft
Uploaded
author | fubar |
---|---|
date | Sun, 23 Mar 2014 07:55:37 -0400 |
parents | 4bfe405f76ed |
children | abeec897b2d7 |
rev | line source |
---|---|
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
1 # rgToolFactory.py |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
2 # see https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
3 # |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
4 # copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
5 # |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
6 # all rights reserved |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
7 # Licensed under the LGPL |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
8 # suggestions for improvement and bug fixes welcome at https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
9 # |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
10 # march 2014 |
18 | 11 # had to remove dependencies because cross toolshed dependencies are not possible - can't pre-specify a toolshed url for graphicsmagick and ghostscript |
12 # grrrrr - night before a demo | |
11 | 13 # added dependencies to a tool_dependencies.xml if html page generated so generated tool is properly portable |
14 # | |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
15 # added ghostscript and graphicsmagick as dependencies |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
16 # fixed a wierd problem where gs was trying to use the new_files_path from universe (database/tmp) as ./database/tmp |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
17 # errors ensued |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
18 # |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
19 # august 2013 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
20 # found a problem with GS if $TMP or $TEMP missing - now inject /tmp and warn |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
21 # |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
22 # july 2013 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
23 # added ability to combine images and individual log files into html output |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
24 # just make sure there's a log file foo.log and it will be output |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
25 # together with all images named like "foo_*.pdf |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
26 # otherwise old format for html |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
27 # |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
28 # January 2013 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
29 # problem pointed out by Carlos Borroto |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
30 # added escaping for <>$ - thought I did that ages ago... |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
31 # |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
32 # August 11 2012 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
33 # changed to use shell=False and cl as a sequence |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
34 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
35 # This is a Galaxy tool factory for simple scripts in python, R or whatever ails ye. |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
36 # It also serves as the wrapper for the new tool. |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
37 # |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
38 # you paste and run your script |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
39 # Only works for simple scripts that read one input from the history. |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
40 # Optionally can write one new history dataset, |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
41 # and optionally collect any number of outputs into links on an autogenerated HTML page. |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
42 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
43 # DO NOT install on a public or important site - please. |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
44 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
45 # installed generated tools are fine if the script is safe. |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
46 # They just run normally and their user cannot do anything unusually insecure |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
47 # but please, practice safe toolshed. |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
48 # Read the fucking code before you install any tool |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
49 # especially this one |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
50 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
51 # After you get the script working on some test data, you can |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
52 # optionally generate a toolshed compatible gzip file |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
53 # containing your script safely wrapped as an ordinary Galaxy script in your local toolshed for |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
54 # safe and largely automated installation in a production Galaxy. |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
55 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
56 # If you opt for an HTML output, you get all the script outputs arranged |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
57 # as a single Html history item - all output files are linked, thumbnails for all the pdfs. |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
58 # Ugly but really inexpensive. |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
59 # |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
60 # Patches appreciated please. |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
61 # |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
62 # |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
63 # long route to June 2012 product |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
64 # Behold the awesome power of Galaxy and the toolshed with the tool factory to bind them |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
65 # derived from an integrated script model |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
66 # called rgBaseScriptWrapper.py |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
67 # Note to the unwary: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
68 # This tool allows arbitrary scripting on your Galaxy as the Galaxy user |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
69 # There is nothing stopping a malicious user doing whatever they choose |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
70 # Extremely dangerous!! |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
71 # Totally insecure. So, trusted users only |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
72 # |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
73 # preferred model is a developer using their throw away workstation instance - ie a private site. |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
74 # no real risk. The universe_wsgi.ini admin_users string is checked - only admin users are permitted to run this tool. |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
75 # |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
76 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
77 import sys |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
78 import shutil |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
79 import subprocess |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
80 import os |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
81 import time |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
82 import tempfile |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
83 import optparse |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
84 import tarfile |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
85 import re |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
86 import shutil |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
87 import math |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
88 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
89 progname = os.path.split(sys.argv[0])[1] |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
90 myversion = 'V001.1 March 2014' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
91 verbose = False |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
92 debug = False |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
93 toolFactoryURL = 'https://bitbucket.org/fubar/galaxytoolfactory' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
94 |
15 | 95 # if we do html we need these dependencies specified in a tool_dependencies.xml file and referred to in the generated |
96 # tool xml | |
14 | 97 toolhtmldepskel = """<?xml version="1.0"?> |
11 | 98 <tool_dependency> |
99 <package name="ghostscript" version="9.10"> | |
18 | 100 <repository name="package_ghostscript_9_10" owner="devteam" prior_installation_required="True" /> |
11 | 101 </package> |
102 <package name="graphicsmagick" version="1.3.18"> | |
18 | 103 <repository name="package_graphicsmagick_1_3" owner="iuc" prior_installation_required="True" /> |
11 | 104 </package> |
105 <readme> | |
106 %s | |
107 </readme> | |
108 </tool_dependency> | |
109 """ | |
110 | |
15 | 111 protorequirements = """<requirements> |
112 <requirement type="package" version="9.10">ghostscript</requirement> | |
113 <requirement type="package" version="1.3.18">graphicsmagick</requirement> | |
114 </requirements>""" | |
115 | |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
116 def timenow(): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
117 """return current time as a string |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
118 """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
119 return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time())) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
120 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
121 html_escape_table = { |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
122 "&": "&", |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
123 ">": ">", |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
124 "<": "<", |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
125 "$": "\$" |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
126 } |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
127 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
128 def html_escape(text): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
129 """Produce entities within text.""" |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
130 return "".join(html_escape_table.get(c,c) for c in text) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
131 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
132 def cmd_exists(cmd): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
133 return subprocess.call("type " + cmd, shell=True, |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
134 stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
135 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
136 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
137 class ScriptRunner: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
138 """class is a wrapper for an arbitrary script |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
139 """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
140 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
141 def __init__(self,opts=None,treatbashSpecial=True): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
142 """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
143 cleanup inputs, setup some outputs |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
144 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
145 """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
146 self.useGM = cmd_exists('gm') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
147 self.useIM = cmd_exists('convert') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
148 self.useGS = cmd_exists('gs') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
149 self.temp_warned = False # we want only one warning if $TMP not set |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
150 self.treatbashSpecial = treatbashSpecial |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
151 if opts.output_dir: # simplify for the tool tarball |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
152 os.chdir(opts.output_dir) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
153 self.thumbformat = 'png' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
154 self.opts = opts |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
155 self.toolname = re.sub('[^a-zA-Z0-9_]+', '', opts.tool_name) # a sanitizer now does this but.. |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
156 self.toolid = self.toolname |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
157 self.myname = sys.argv[0] # get our name because we write ourselves out as a tool later |
11 | 158 self.pyfile = self.myname # crude but efficient - the cruft won't hurt muchself.tooldepfile) |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
159 self.xmlfile = '%s.xml' % self.toolname |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
160 s = open(self.opts.script_path,'r').readlines() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
161 s = [x.rstrip() for x in s] # remove pesky dos line endings if needed |
17 | 162 s = [x.lstrip() for x in s] # and left padding |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
163 self.script = '\n'.join(s) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
164 fhandle,self.sfile = tempfile.mkstemp(prefix=self.toolname,suffix=".%s" % (opts.interpreter)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
165 tscript = open(self.sfile,'w') # use self.sfile as script source for Popen |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
166 tscript.write(self.script) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
167 tscript.close() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
168 self.indentedScript = '\n'.join([' %s' % x for x in s]) # for restructured text in help |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
169 self.escapedScript = '\n'.join([html_escape(x) for x in s]) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
170 self.elog = os.path.join(self.opts.output_dir,"%s_error.log" % self.toolname) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
171 if opts.output_dir: # may not want these complexities |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
172 self.tlog = os.path.join(self.opts.output_dir,"%s_runner.log" % self.toolname) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
173 art = '%s.%s' % (self.toolname,opts.interpreter) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
174 artpath = os.path.join(self.opts.output_dir,art) # need full path |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
175 artifact = open(artpath,'w') # use self.sfile as script source for Popen |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
176 artifact.write(self.script) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
177 artifact.close() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
178 self.cl = [] |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
179 self.html = [] |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
180 a = self.cl.append |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
181 a(opts.interpreter) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
182 if self.treatbashSpecial and opts.interpreter in ['bash','sh']: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
183 a(self.sfile) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
184 else: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
185 a('-') # stdin |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
186 a(opts.input_tab) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
187 a(opts.output_tab) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
188 self.outFormats = 'tabular' # TODO make this an option at tool generation time |
20 | 189 self.inputFormats = 'tabular,txt' # TODO make this an option at tool generation time |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
190 self.test1Input = '%s_test1_input.xls' % self.toolname |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
191 self.test1Output = '%s_test1_output.xls' % self.toolname |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
192 self.test1HTML = '%s_test1_output.html' % self.toolname |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
193 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
194 def makeXML(self): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
195 """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
196 Create a Galaxy xml tool wrapper for the new script as a string to write out |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
197 fixme - use templating or something less fugly than this example of what we produce |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
198 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
199 <tool id="reverse" name="reverse" version="0.01"> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
200 <description>a tabular file</description> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
201 <command interpreter="python"> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
202 reverse.py --script_path "$runMe" --interpreter "python" |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
203 --tool_name "reverse" --input_tab "$input1" --output_tab "$tab_file" |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
204 </command> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
205 <inputs> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
206 <param name="input1" type="data" format="tabular" label="Select a suitable input file from your history"/><param name="job_name" type="text" label="Supply a name for the outputs to remind you what they contain" value="reverse"/> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
207 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
208 </inputs> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
209 <outputs> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
210 <data format="tabular" name="tab_file" label="${job_name}"/> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
211 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
212 </outputs> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
213 <help> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
214 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
215 **What it Does** |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
216 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
217 Reverse the columns in a tabular file |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
218 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
219 </help> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
220 <configfiles> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
221 <configfile name="runMe"> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
222 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
223 # reverse order of columns in a tabular file |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
224 import sys |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
225 inp = sys.argv[1] |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
226 outp = sys.argv[2] |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
227 i = open(inp,'r') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
228 o = open(outp,'w') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
229 for row in i: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
230 rs = row.rstrip().split('\t') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
231 rs.reverse() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
232 o.write('\t'.join(rs)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
233 o.write('\n') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
234 i.close() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
235 o.close() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
236 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
237 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
238 </configfile> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
239 </configfiles> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
240 </tool> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
241 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
242 """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
243 newXML="""<tool id="%(toolid)s" name="%(toolname)s" version="%(tool_version)s"> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
244 %(tooldesc)s |
15 | 245 %(requirements)s |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
246 %(command)s |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
247 <inputs> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
248 %(inputs)s |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
249 </inputs> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
250 <outputs> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
251 %(outputs)s |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
252 </outputs> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
253 <configfiles> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
254 <configfile name="runMe"> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
255 %(script)s |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
256 </configfile> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
257 </configfiles> |
19 | 258 |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
259 %(tooltests)s |
19 | 260 |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
261 <help> |
17 | 262 |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
263 %(help)s |
17 | 264 |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
265 </help> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
266 </tool>""" # needs a dict with toolname, toolid, interpreter, scriptname, command, inputs as a multi line string ready to write, outputs ditto, help ditto |
11 | 267 |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
268 newCommand="""<command interpreter="python"> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
269 %(toolname)s.py --script_path "$runMe" --interpreter "%(interpreter)s" |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
270 --tool_name "%(toolname)s" %(command_inputs)s %(command_outputs)s |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
271 </command>""" # may NOT be an input or htmlout |
19 | 272 tooltestsTabOnly = """ |
273 <tests> | |
274 <test> | |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
275 <param name="input1" value="%(test1Input)s" ftype="tabular"/> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
276 <param name="job_name" value="test1"/> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
277 <param name="runMe" value="$runMe"/> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
278 <output name="tab_file" file="%(test1Output)s" ftype="tabular"/> |
19 | 279 </test> |
280 </tests> | |
281 """ | |
282 tooltestsHTMLOnly = """ | |
283 <tests> | |
284 <test> | |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
285 <param name="input1" value="%(test1Input)s" ftype="tabular"/> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
286 <param name="job_name" value="test1"/> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
287 <param name="runMe" value="$runMe"/> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
288 <output name="html_file" file="%(test1HTML)s" ftype="html" lines_diff="5"/> |
19 | 289 </test> |
290 </tests> | |
291 """ | |
292 tooltestsBoth = """<tests> | |
293 <test> | |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
294 <param name="input1" value="%(test1Input)s" ftype="tabular"/> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
295 <param name="job_name" value="test1"/> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
296 <param name="runMe" value="$runMe"/> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
297 <output name="tab_file" file="%(test1Output)s" ftype="tabular" /> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
298 <output name="html_file" file="%(test1HTML)s" ftype="html" lines_diff="10"/> |
19 | 299 </test> |
300 </tests> | |
301 """ | |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
302 xdict = {} |
15 | 303 xdict['requirements'] = '' |
304 if self.opts.make_HTML: | |
305 xdict['requirements'] = protorequirements | |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
306 xdict['tool_version'] = self.opts.tool_version |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
307 xdict['test1Input'] = self.test1Input |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
308 xdict['test1HTML'] = self.test1HTML |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
309 xdict['test1Output'] = self.test1Output |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
310 if self.opts.make_HTML and self.opts.output_tab <> 'None': |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
311 xdict['tooltests'] = tooltestsBoth % xdict |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
312 elif self.opts.make_HTML: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
313 xdict['tooltests'] = tooltestsHTMLOnly % xdict |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
314 else: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
315 xdict['tooltests'] = tooltestsTabOnly % xdict |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
316 xdict['script'] = self.escapedScript |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
317 # configfile is least painful way to embed script to avoid external dependencies |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
318 # but requires escaping of <, > and $ to avoid Mako parsing |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
319 if self.opts.help_text: |
19 | 320 xdict['help'] = open(self.opts.help_text,'r').readlines() |
321 xdict['help'] = ''.join([x.lstrip(x) for x in xdict['help']]) | |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
322 else: |
17 | 323 xdict['help'] = 'Please ask the tool author for help as none was supplied at tool generation\n' |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
324 coda = ['**Script**','Pressing execute will run the following code over your input file and generate some outputs in your history::'] |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
325 coda.append(self.indentedScript) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
326 coda.append('**Attribution** This Galaxy tool was created by %s at %s\nusing the Galaxy Tool Factory.' % (self.opts.user_email,timenow())) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
327 coda.append('See %s for details of that project' % (toolFactoryURL)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
328 coda.append('Please cite: Creating re-usable tools from scripts: The Galaxy Tool Factory. Ross Lazarus; Antony Kaspi; Mark Ziemann; The Galaxy Team. ') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
329 coda.append('Bioinformatics 2012; doi: 10.1093/bioinformatics/bts573') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
330 xdict['help'] = '%s\n%s' % (xdict['help'],'\n'.join(coda)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
331 if self.opts.tool_desc: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
332 xdict['tooldesc'] = '<description>%s</description>' % self.opts.tool_desc |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
333 else: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
334 xdict['tooldesc'] = '' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
335 xdict['command_outputs'] = '' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
336 xdict['outputs'] = '' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
337 if self.opts.input_tab <> 'None': |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
338 xdict['command_inputs'] = '--input_tab "$input1" ' # the space may matter a lot if we append something |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
339 xdict['inputs'] = '<param name="input1" type="data" format="%s" label="Select a suitable input file from your history"/> \n' % self.inputFormats |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
340 else: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
341 xdict['command_inputs'] = '' # assume no input - eg a random data generator |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
342 xdict['inputs'] = '' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
343 xdict['inputs'] += '<param name="job_name" type="text" label="Supply a name for the outputs to remind you what they contain" value="%s"/> \n' % self.toolname |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
344 xdict['toolname'] = self.toolname |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
345 xdict['toolid'] = self.toolid |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
346 xdict['interpreter'] = self.opts.interpreter |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
347 xdict['scriptname'] = self.sfile |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
348 if self.opts.make_HTML: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
349 xdict['command_outputs'] += ' --output_dir "$html_file.files_path" --output_html "$html_file" --make_HTML "yes" ' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
350 xdict['outputs'] += ' <data format="html" name="html_file" label="${job_name}.html"/>\n' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
351 if self.opts.output_tab <> 'None': |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
352 xdict['command_outputs'] += ' --output_tab "$tab_file"' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
353 xdict['outputs'] += ' <data format="%s" name="tab_file" label="${job_name}"/>\n' % self.outFormats |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
354 xdict['command'] = newCommand % xdict |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
355 xmls = newXML % xdict |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
356 xf = open(self.xmlfile,'w') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
357 xf.write(xmls) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
358 xf.write('\n') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
359 xf.close() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
360 # ready for the tarball |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
361 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
362 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
363 def makeTooltar(self): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
364 """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
365 a tool is a gz tarball with eg |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
366 /toolname/tool.xml /toolname/tool.py /toolname/test-data/test1_in.foo ... |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
367 """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
368 retval = self.run() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
369 if retval: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
370 print >> sys.stderr,'## Run failed. Cannot build yet. Please fix and retry' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
371 sys.exit(1) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
372 tdir = self.toolname |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
373 os.mkdir(tdir) |
11 | 374 self.makeXML() |
375 if self.opts.make_HTML: | |
376 if self.opts.help_text: | |
377 hlp = open(self.opts.help_text,'r').read() | |
378 else: | |
379 hlp = 'Please ask the tool author for help as none was supplied at tool generation\n' | |
18 | 380 if self.opts.include_dependencies: |
381 tooldepcontent = toolhtmldepskel % hlp | |
382 depf = open(os.path.join(tdir,'tool_dependencies.xml'),'w') | |
383 depf.write(tooldepcontent) | |
384 depf.write('\n') | |
385 depf.close() | |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
386 if self.opts.input_tab <> 'None': # no reproducible test otherwise? TODO: maybe.. |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
387 testdir = os.path.join(tdir,'test-data') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
388 os.mkdir(testdir) # make tests directory |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
389 shutil.copyfile(self.opts.input_tab,os.path.join(testdir,self.test1Input)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
390 if self.opts.output_tab <> 'None': |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
391 shutil.copyfile(self.opts.output_tab,os.path.join(testdir,self.test1Output)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
392 if self.opts.make_HTML: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
393 shutil.copyfile(self.opts.output_html,os.path.join(testdir,self.test1HTML)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
394 if self.opts.output_dir: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
395 shutil.copyfile(self.tlog,os.path.join(testdir,'test1_out.log')) |
12 | 396 outpif = '%s.py' % self.toolname # new name |
397 outpiname = os.path.join(tdir,outpif) # path for the tool tarball | |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
398 pyin = os.path.basename(self.pyfile) # our name - we rewrite ourselves (TM) |
13 | 399 notes = ['# %s - a self annotated version of %s generated by running %s\n' % (outpiname,pyin,pyin),] |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
400 notes.append('# to make a new Galaxy tool called %s\n' % self.toolname) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
401 notes.append('# User %s at %s\n' % (self.opts.user_email,timenow())) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
402 pi = open(self.pyfile,'r').readlines() # our code becomes new tool wrapper (!) - first Galaxy worm |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
403 notes += pi |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
404 outpi = open(outpiname,'w') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
405 outpi.write(''.join(notes)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
406 outpi.write('\n') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
407 outpi.close() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
408 stname = os.path.join(tdir,self.sfile) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
409 if not os.path.exists(stname): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
410 shutil.copyfile(self.sfile, stname) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
411 xtname = os.path.join(tdir,self.xmlfile) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
412 if not os.path.exists(xtname): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
413 shutil.copyfile(self.xmlfile,xtname) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
414 tarpath = "%s.gz" % self.toolname |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
415 tar = tarfile.open(tarpath, "w:gz") |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
416 tar.add(tdir,arcname=self.toolname) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
417 tar.close() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
418 shutil.copyfile(tarpath,self.opts.new_tool) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
419 shutil.rmtree(tdir) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
420 ## TODO: replace with optional direct upload to local toolshed? |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
421 return retval |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
422 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
423 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
424 def compressPDF(self,inpdf=None,thumbformat='png'): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
425 """need absolute path to pdf |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
426 note that GS gets confoozled if no $TMP or $TEMP |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
427 so we set it |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
428 """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
429 assert os.path.isfile(inpdf), "## Input %s supplied to %s compressPDF not found" % (inpdf,self.myName) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
430 hlog = os.path.join(self.opts.output_dir,"compress_%s.txt" % os.path.basename(inpdf)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
431 sto = open(hlog,'a') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
432 our_env = os.environ.copy() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
433 our_tmp = our_env.get('TMP',None) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
434 if not our_tmp: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
435 our_tmp = our_env.get('TEMP',None) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
436 if not (our_tmp and os.path.exists(our_tmp)): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
437 newtmp = os.path.join(self.opts.output_dir,'tmp') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
438 try: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
439 os.mkdir(newtmp) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
440 except: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
441 sto.write('## WARNING - cannot make %s - it may exist or permissions need fixing\n' % newtmp) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
442 our_env['TEMP'] = newtmp |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
443 if not self.temp_warned: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
444 sto.write('## WARNING - no $TMP or $TEMP!!! Please fix - using %s temporarily\n' % newtmp) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
445 self.temp_warned = True |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
446 outpdf = '%s_compressed' % inpdf |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
447 cl = ["gs", "-sDEVICE=pdfwrite", "-dNOPAUSE", "-dUseCIEColor", "-dBATCH","-dPDFSETTINGS=/printer", "-sOutputFile=%s" % outpdf,inpdf] |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
448 x = subprocess.Popen(cl,stdout=sto,stderr=sto,cwd=self.opts.output_dir,env=our_env) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
449 retval1 = x.wait() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
450 sto.close() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
451 if retval1 == 0: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
452 os.unlink(inpdf) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
453 shutil.move(outpdf,inpdf) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
454 os.unlink(hlog) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
455 hlog = os.path.join(self.opts.output_dir,"thumbnail_%s.txt" % os.path.basename(inpdf)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
456 sto = open(hlog,'w') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
457 outpng = '%s.%s' % (os.path.splitext(inpdf)[0],thumbformat) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
458 if self.useGM: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
459 cl2 = ['gm', 'convert', inpdf, outpng] |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
460 else: # assume imagemagick |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
461 cl2 = ['convert', inpdf, outpng] |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
462 x = subprocess.Popen(cl2,stdout=sto,stderr=sto,cwd=self.opts.output_dir,env=our_env) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
463 retval2 = x.wait() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
464 sto.close() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
465 if retval2 == 0: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
466 os.unlink(hlog) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
467 retval = retval1 or retval2 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
468 return retval |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
469 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
470 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
471 def getfSize(self,fpath,outpath): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
472 """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
473 format a nice file size string |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
474 """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
475 size = '' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
476 fp = os.path.join(outpath,fpath) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
477 if os.path.isfile(fp): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
478 size = '0 B' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
479 n = float(os.path.getsize(fp)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
480 if n > 2**20: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
481 size = '%1.1f MB' % (n/2**20) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
482 elif n > 2**10: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
483 size = '%1.1f KB' % (n/2**10) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
484 elif n > 0: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
485 size = '%d B' % (int(n)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
486 return size |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
487 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
488 def makeHtml(self): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
489 """ Create an HTML file content to list all the artifacts found in the output_dir |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
490 """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
491 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
492 galhtmlprefix = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
493 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
494 <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
495 <meta name="generator" content="Galaxy %s tool output - see http://g2.trac.bx.psu.edu/" /> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
496 <title></title> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
497 <link rel="stylesheet" href="/static/style/base.css" type="text/css" /> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
498 </head> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
499 <body> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
500 <div class="toolFormBody"> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
501 """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
502 galhtmlattr = """<hr/><div class="infomessage">This tool (%s) was generated by the <a href="https://bitbucket.org/fubar/galaxytoolfactory/overview">Galaxy Tool Factory</a></div><br/>""" |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
503 galhtmlpostfix = """</div></body></html>\n""" |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
504 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
505 flist = os.listdir(self.opts.output_dir) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
506 flist = [x for x in flist if x <> 'Rplots.pdf'] |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
507 flist.sort() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
508 html = [] |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
509 html.append(galhtmlprefix % progname) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
510 html.append('<div class="infomessage">Galaxy Tool "%s" run at %s</div><br/>' % (self.toolname,timenow())) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
511 fhtml = [] |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
512 if len(flist) > 0: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
513 logfiles = [x for x in flist if x.lower().endswith('.log')] # log file names determine sections |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
514 logfiles.sort() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
515 logfiles = [x for x in logfiles if os.path.abspath(x) <> os.path.abspath(self.tlog)] |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
516 logfiles.append(os.path.abspath(self.tlog)) # make it the last one |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
517 pdflist = [] |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
518 npdf = len([x for x in flist if os.path.splitext(x)[-1].lower() == '.pdf']) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
519 for rownum,fname in enumerate(flist): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
520 dname,e = os.path.splitext(fname) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
521 sfsize = self.getfSize(fname,self.opts.output_dir) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
522 if e.lower() == '.pdf' : # compress and make a thumbnail |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
523 thumb = '%s.%s' % (dname,self.thumbformat) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
524 pdff = os.path.join(self.opts.output_dir,fname) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
525 retval = self.compressPDF(inpdf=pdff,thumbformat=self.thumbformat) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
526 if retval == 0: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
527 pdflist.append((fname,thumb)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
528 else: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
529 pdflist.append((fname,fname)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
530 if (rownum+1) % 2 == 0: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
531 fhtml.append('<tr class="odd_row"><td><a href="%s">%s</a></td><td>%s</td></tr>' % (fname,fname,sfsize)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
532 else: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
533 fhtml.append('<tr><td><a href="%s">%s</a></td><td>%s</td></tr>' % (fname,fname,sfsize)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
534 for logfname in logfiles: # expect at least tlog - if more |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
535 if os.path.abspath(logfname) == os.path.abspath(self.tlog): # handled later |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
536 sectionname = 'All tool run' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
537 if (len(logfiles) > 1): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
538 sectionname = 'Other' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
539 ourpdfs = pdflist |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
540 else: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
541 realname = os.path.basename(logfname) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
542 sectionname = os.path.splitext(realname)[0].split('_')[0] # break in case _ added to log |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
543 ourpdfs = [x for x in pdflist if os.path.basename(x[0]).split('_')[0] == sectionname] |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
544 pdflist = [x for x in pdflist if os.path.basename(x[0]).split('_')[0] <> sectionname] # remove |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
545 nacross = 1 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
546 npdf = len(ourpdfs) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
547 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
548 if npdf > 0: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
549 nacross = math.sqrt(npdf) ## int(round(math.log(npdf,2))) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
550 if int(nacross)**2 != npdf: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
551 nacross += 1 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
552 nacross = int(nacross) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
553 width = min(400,int(1200/nacross)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
554 html.append('<div class="toolFormTitle">%s images and outputs</div>' % sectionname) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
555 html.append('(Click on a thumbnail image to download the corresponding original PDF image)<br/>') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
556 ntogo = nacross # counter for table row padding with empty cells |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
557 html.append('<div><table class="simple" cellpadding="2" cellspacing="2">\n<tr>') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
558 for i,paths in enumerate(ourpdfs): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
559 fname,thumb = paths |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
560 s= """<td><a href="%s"><img src="%s" title="Click to download a PDF of %s" hspace="5" width="%d" |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
561 alt="Image called %s"/></a></td>\n""" % (fname,thumb,fname,width,fname) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
562 if ((i+1) % nacross == 0): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
563 s += '</tr>\n' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
564 ntogo = 0 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
565 if i < (npdf - 1): # more to come |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
566 s += '<tr>' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
567 ntogo = nacross |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
568 else: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
569 ntogo -= 1 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
570 html.append(s) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
571 if html[-1].strip().endswith('</tr>'): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
572 html.append('</table></div>\n') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
573 else: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
574 if ntogo > 0: # pad |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
575 html.append('<td> </td>'*ntogo) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
576 html.append('</tr></table></div>\n') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
577 logt = open(logfname,'r').readlines() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
578 logtext = [x for x in logt if x.strip() > ''] |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
579 html.append('<div class="toolFormTitle">%s log output</div>' % sectionname) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
580 if len(logtext) > 1: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
581 html.append('\n<pre>\n') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
582 html += logtext |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
583 html.append('\n</pre>\n') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
584 else: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
585 html.append('%s is empty<br/>' % logfname) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
586 if len(fhtml) > 0: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
587 fhtml.insert(0,'<div><table class="colored" cellpadding="3" cellspacing="3"><tr><th>Output File Name (click to view)</th><th>Size</th></tr>\n') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
588 fhtml.append('</table></div><br/>') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
589 html.append('<div class="toolFormTitle">All output files available for downloading</div>\n') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
590 html += fhtml # add all non-pdf files to the end of the display |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
591 else: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
592 html.append('<div class="warningmessagelarge">### Error - %s returned no files - please confirm that parameters are sane</div>' % self.opts.interpreter) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
593 html.append(galhtmlpostfix) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
594 htmlf = file(self.opts.output_html,'w') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
595 htmlf.write('\n'.join(html)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
596 htmlf.write('\n') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
597 htmlf.close() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
598 self.html = html |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
599 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
600 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
601 def run(self): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
602 """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
603 scripts must be small enough not to fill the pipe! |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
604 """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
605 if self.treatbashSpecial and self.opts.interpreter in ['bash','sh']: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
606 retval = self.runBash() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
607 else: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
608 if self.opts.output_dir: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
609 ste = open(self.elog,'w') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
610 sto = open(self.tlog,'w') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
611 sto.write('## Toolfactory generated command line = %s\n' % ' '.join(self.cl)) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
612 sto.flush() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
613 p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=ste,stdin=subprocess.PIPE,cwd=self.opts.output_dir) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
614 else: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
615 p = subprocess.Popen(self.cl,shell=False,stdin=subprocess.PIPE) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
616 p.stdin.write(self.script) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
617 p.stdin.close() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
618 retval = p.wait() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
619 if self.opts.output_dir: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
620 sto.close() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
621 ste.close() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
622 err = open(self.elog,'r').readlines() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
623 if retval <> 0 and err: # problem |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
624 print >> sys.stderr,err |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
625 if self.opts.make_HTML: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
626 self.makeHtml() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
627 return retval |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
628 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
629 def runBash(self): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
630 """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
631 cannot use - for bash so use self.sfile |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
632 """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
633 if self.opts.output_dir: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
634 s = '## Toolfactory generated command line = %s\n' % ' '.join(self.cl) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
635 sto = open(self.tlog,'w') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
636 sto.write(s) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
637 sto.flush() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
638 p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=sto,cwd=self.opts.output_dir) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
639 else: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
640 p = subprocess.Popen(self.cl,shell=False) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
641 retval = p.wait() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
642 if self.opts.output_dir: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
643 sto.close() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
644 if self.opts.make_HTML: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
645 self.makeHtml() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
646 return retval |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
647 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
648 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
649 def main(): |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
650 u = """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
651 This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
652 <command interpreter="python">rgBaseScriptWrapper.py --script_path "$scriptPath" --tool_name "foo" --interpreter "Rscript" |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
653 </command> |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
654 """ |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
655 op = optparse.OptionParser() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
656 a = op.add_option |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
657 a('--script_path',default=None) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
658 a('--tool_name',default=None) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
659 a('--interpreter',default=None) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
660 a('--output_dir',default=None) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
661 a('--output_html',default=None) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
662 a('--input_tab',default="None") |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
663 a('--output_tab',default="None") |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
664 a('--user_email',default='Unknown') |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
665 a('--bad_user',default=None) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
666 a('--make_Tool',default=None) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
667 a('--make_HTML',default=None) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
668 a('--help_text',default=None) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
669 a('--tool_desc',default=None) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
670 a('--new_tool',default=None) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
671 a('--tool_version',default=None) |
18 | 672 a('--include_dependencies',default=None) |
7
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
673 opts, args = op.parse_args() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
674 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) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
675 assert opts.tool_name,'## Tool Factory expects a tool name - eg --tool_name=DESeq' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
676 assert opts.interpreter,'## Tool Factory wrapper expects an interpreter - eg --interpreter=Rscript' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
677 assert os.path.isfile(opts.script_path),'## Tool Factory wrapper expects a script path - eg --script_path=foo.R' |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
678 if opts.output_dir: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
679 try: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
680 os.makedirs(opts.output_dir) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
681 except: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
682 pass |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
683 r = ScriptRunner(opts) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
684 if opts.make_Tool: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
685 retcode = r.makeTooltar() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
686 else: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
687 retcode = r.run() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
688 os.unlink(r.sfile) |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
689 if retcode: |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
690 sys.exit(retcode) # indicate failure to job runner |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
691 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
692 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
693 if __name__ == "__main__": |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
694 main() |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
695 |
1fcf3fda325f
major fixes with GS and graphicsmagick dependencies included
fubar
parents:
diff
changeset
|
696 |