# HG changeset patch # User fubar # Date 1421281031 18000 # Node ID ce5ec1d989fd72777342944add7ae18f8d64362e # Parent 9d58cc32a12dca7cc617382e20af6fd5d42c185a Uploaded diff -r 9d58cc32a12d -r ce5ec1d989fd getlocalrpackages.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getlocalrpackages.py Wed Jan 14 19:17:11 2015 -0500 @@ -0,0 +1,31 @@ +import os +import subprocess + +def find_packages(prefix="package_r_"): + """ + """ + #locate env.sh | grep -i package_r_ + #/data/extended/galaxyJune14_2014/tool_dependency/readline/6.2/devteam/package_r_2_15_0/8ab0d08a3da1/env.sh + #/data/home/rlazarus/galaxy/tool_dependency_dir/R_3_1_1/3.1.1/fubar/package_r_3_1_1/5f1b8d22140a/env.sh + #/data/home/rlazarus/galaxy/tool_dependency_dir/R_3_1_1/3.1.1/fubar/package_r_3_1_1/d9964efbfbe3/env.sh + #/data/home/rlazarus/galtest/tool_dependency_dir/R_3_1_1/3.1.1/fubar/package_r_3_1_1/63cdb9b2234c/env.sh + eprefix = prefix + if prefix.find('/') <> -1: + eprefix = prefix.replace('/','\/') # for grep + cl = ['locate env.sh | grep -i %s' % eprefix,] + p = subprocess.Popen(cl, stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True) + out, err = p.communicate() + fpaths = out.split('\n') + fpaths = [x for x in fpaths if len(x) > 1] + fver = [x.split(os.path.sep)[-4:-1] for x in fpaths] + # >>> foo.split(os.path.sep)[-4:-1] + # ['fubar', 'package_r_3_1_1', '63cdb9b2234c'] + res = [['%s rev %s owner %s' % (x[1],x[2],x[0]),fpaths[i],False] for i,x in enumerate(fver)] + res.insert(0,['Use default (system) interpreter','system',False]) + if len(res) > 1: + res[1][2] = True # selected if more than one + # return a triplet - user_sees,value,selected - all unselected if False + return res + +if __name__ == "__main__": + print find_packages() diff -r 9d58cc32a12d -r ce5ec1d989fd rgToolFactory2.py --- a/rgToolFactory2.py Mon Jan 12 05:27:52 2015 -0500 +++ b/rgToolFactory2.py Wed Jan 14 19:17:11 2015 -0500 @@ -172,7 +172,20 @@ citation_tuples.append( ("bibtex", citation[len("bibtex"):].strip() ) ) return citation_tuples - +def shell_source(script): + """need a way to source a Galaxy tool interpreter env.sh so we can use that dependency + package + see http://pythonwise.blogspot.fr/2010/04/sourcing-shell-script.html + Sometime you want to emulate the action of "source" in bash, + settings some environment variables. Here is a way to do it. + Note that we have to finesse the automagic exports using nulls as newlines for env""" + pipe = subprocess.Popen("env -i ; . %s ; env -0" % script, stdout=subprocess.PIPE, shell=True) + output = pipe.communicate()[0] + outl = output.split('\0') + outl = [x for x in outl if len(x.split("=")) == 2] + newenv = dict((line.split("=", 1) for line in outl)) + os.environ.update(newenv) + class ScriptRunner: """class is a wrapper for an arbitrary script """ @@ -218,10 +231,7 @@ self.test1Inputs = [] # now a list a = self.cl.append a(opts.interpreter) - if self.treatbashSpecial and opts.interpreter in ['bash','sh']: - a(self.sfile) - else: - a('-') # stdin + a(self.sfile) # if multiple inputs - positional or need to distinguish them with cl params if opts.input_tab: tests = [] @@ -391,7 +401,8 @@ %(citations)s 10.1093/bioinformatics/bts573 -""" # needs a dict with toolname, toolid, interpreter, scriptname, command, inputs as a multi line string ready to write, outputs ditto, help ditto +""" +# needs a dict with toolname, toolid, interpreter, scriptname, command, inputs as a multi line string ready to write, outputs ditto, help ditto newCommand=""" %(toolname)s.py --script_path "$runMe" --interpreter "%(interpreter)s" @@ -433,8 +444,8 @@ xdict['additionalInputs'] = '' if self.opts.additional_parameters: if self.opts.edit_additional_parameters: # add to new tool form with default value set to original value - xdict['additionalInputs'] = '\n'.join(['' % (x.split(',')[0],html_escape(x.split(',')[1]),html_escape(x.split(',')[2]), - html_escape(x.split(',')[3]), x.split(',')[4]) for x in self.opts.additional_parameters]) + xdict['additionalInputs'] = '\n'.join(['' % \ + (x.split(',')[0],html_escape(x.split(',')[1]),html_escape(x.split(',')[2]),html_escape(x.split(',')[3]), x.split(',')[4]) for x in self.opts.additional_parameters]) xdict['additionalParams'] = '\n'.join(['' % (x.split(',')[0],html_escape(x.split(',')[1])) for x in self.opts.additional_parameters]) xdict['requirements'] = '' if self.opts.make_HTML: @@ -774,10 +785,13 @@ self.html = html + def run(self): """ scripts must be small enough not to fill the pipe! """ + if self.opts.envshpath <> 'system': + shell_source(self.opts.envshpath) if self.treatbashSpecial and self.opts.interpreter in ['bash','sh']: retval = self.runBash() else: @@ -786,11 +800,9 @@ sto = open(self.tlog,'w') sto.write('## Toolfactory generated command line = %s\n' % ' '.join(self.cl)) sto.flush() - p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=ste,stdin=subprocess.PIPE,cwd=self.opts.output_dir) + p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=ste,cwd=self.opts.output_dir) else: - p = subprocess.Popen(self.cl,shell=False,stdin=subprocess.PIPE) - p.stdin.write(self.script) - p.stdin.close() + p = subprocess.Popen(self.cl,shell=False) retval = p.wait() if self.opts.output_dir: sto.close() @@ -851,6 +863,7 @@ a('--citations',default=None) a('--additional_parameters', dest='additional_parameters', action='append', default=[]) a('--edit_additional_parameters', action="store_true", default=False) + a('--envshpath',default="system") opts, args = op.parse_args() assert not opts.bad_user,'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to admin_users in universe_wsgi.ini' % (opts.bad_user,opts.bad_user) assert opts.tool_name,'## Tool Factory expects a tool name - eg --tool_name=DESeq' diff -r 9d58cc32a12d -r ce5ec1d989fd rgToolFactory2.xml --- a/rgToolFactory2.xml Mon Jan 12 05:27:52 2015 -0500 +++ b/rgToolFactory2.xml Wed Jan 14 19:17:11 2015 -0500 @@ -1,15 +1,17 @@ - + Scripts into tools ghostscript graphicsmagick + #if ( $__user_email__ not in $__admin_users__ ): rgToolFactory2.py --bad_user $__user_email__ #else: - rgToolFactory2.py --script_path "$runme" --interpreter "$interpreter" + rgToolFactory2.py --script_path "$runme" --interpreter "$interp.interpreter" --tool_name "$tool_name" --user_email "$__user_email__" --citations "$citeme" + --envshpath "$interp.envpath" #if $make_TAB.value=="yes": --output_tab "$output1" @@ -96,7 +98,7 @@ + help="Supply a DOI (e.g. doi: 10.1111/j.1740-9713.2007.00258.x) that should be cited when this tool is used in published research." /> + @@ -142,6 +145,19 @@ + + + + + + + + + + @@ -244,6 +260,7 @@ + @@ -418,7 +435,7 @@ - doi: 10.1093/bioinformatics/bts573 + 10.1093/bioinformatics/bts573 diff -r 9d58cc32a12d -r ce5ec1d989fd test-data/tf2_test.html --- a/test-data/tf2_test.html Mon Jan 12 05:27:52 2015 -0500 +++ b/test-data/tf2_test.html Wed Jan 14 19:17:11 2015 -0500 @@ -8,18 +8,18 @@
-
Galaxy Tool "tf2_test" run at 02/01/2015 11:50:01

+
Galaxy Tool "tf2_test" run at 15/01/2015 11:06:33

tf2 log output
tf2_test_error.log is empty
Other log output
-/tmp/tmpsyPOyw/job_working_directory/000/2/dataset_3_files/tf2_test_runner.log is empty
+/tmp/tmp5bLHi4/job_working_directory/000/2/dataset_3_files/tf2_test_runner.log is empty
All output files available for downloading
- +
Output File Name (click to view)Size
tf2_test.python0 B
tf2_test_error.log0 B
tf2_test_runner.log177 B
tf2_test_runner.log216 B

diff -r 9d58cc32a12d -r ce5ec1d989fd test-data/tf2_test.toolshed.gz Binary file test-data/tf2_test.toolshed.gz has changed