annotate rgToolFactory.py @ 29:bff4c9bfabc7 draft

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