# HG changeset patch # User fubar # Date 1421325306 18000 # Node ID 8de2b7571d98c5ebfd49a12e1554f14a29d46ab7 # Parent ce5ec1d989fd72777342944add7ae18f8d64362e Uploaded diff -r ce5ec1d989fd -r 8de2b7571d98 rgToolFactory2.py --- a/rgToolFactory2.py Wed Jan 14 19:17:11 2015 -0500 +++ b/rgToolFactory2.py Thu Jan 15 07:35:06 2015 -0500 @@ -7,6 +7,11 @@ # Licensed under the LGPL # suggestions for improvement and bug fixes welcome at https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home # +# January 2015 +# in the process of building a complex tool +# added ability to choose one of the current toolshed package_r or package_perl or package_python dependencies and source that package +# need to add that package to tool_dependencies +# # sept 2014 added additional params from # https://bitbucket.org/mvdbeek/dockertoolfactory/src/d4863bcf7b521532c7e8c61b6333840ba5393f73/DockerToolFactory.py?at=default # passing them is complex @@ -107,32 +112,6 @@ # if we do html we need these dependencies specified in a tool_dependencies.xml file and referred to in the generated # tool xml -toolhtmldepskel = """ - - - - - - - - - %s - - -""" - -emptytoolhtmldepskel = """ - - - %s - - -""" - -protorequirements = """ - ghostscript - graphicsmagick - """ def timenow(): """return current time as a string @@ -188,13 +167,141 @@ class ScriptRunner: """class is a wrapper for an arbitrary script + note funky templating. this should all be done proper. + Problem is, this kludge developed quite naturally and seems to work ok with + little overhead... + """ + def __init__(self,opts=None,treatbashSpecial=True): """ cleanup inputs, setup some outputs """ + + self.toolhtmldepinterpskel = """ + + + + + + + + + + + + + %(readme)s + + + """ + + self.toolhtmldepskel = """ + + + + + + + + + %(readme)s + + + """ + + self.emptytoolhtmldepskel = """ + + + %(readme)s + + + """ + + self.protorequirements = """ + ghostscript + graphicsmagick + """ + + self.protorequirements_interpreter = """ + ghostscript + graphicsmagick + %(interpreter_name)s + """ + + + self.newCommand=""" + %(toolname)s.py --script_path "$runMe" --interpreter "%(interpreter)s" + --tool_name "%(toolname)s" + %(command_inputs)s + %(command_outputs)s + """ + + self.tooltestsTabOnly = """ + + %(test1Inputs)s + + + + %(additionalParams)s + + """ + + self.tooltestsHTMLOnly = """ + + %(test1Inputs)s + + + %(additionalParams)s + + + """ + + self.tooltestsBoth = """ + + %(test1Inputs)s + + + %(additionalParams)s + + + + """ + + self.newXML=""" +%(tooldesc)s +%(requirements)s + +%(command)s + + +%(inputs)s +%(additionalInputs)s + + +%(outputs)s + + + +%(script)s + + + +%(tooltests)s + + + +%(help)s + + + + %(citations)s + 10.1093/bioinformatics/bts573 + +""" + self.useGM = cmd_exists('gm') self.useIM = cmd_exists('convert') self.useGS = cmd_exists('gs') @@ -315,8 +422,20 @@ else: a('%s=%s' % (param,value)) self.cl.insert(4+i,'%s=%s' % (param,value)) - - + self.interp_owner = None + self.interp_pack = None + self.interp_revision = None + self.interp_version = None + if opts.envshpath <> 'system': # need to parse out details for our tool_dependency + try: + packdetails = opts.envshpath.split(os.path.sep)[-4:-1] # eg ['fubar', 'package_r_3_1_1', '63cdb9b2234c'] + self.interpreter_owner = packdetails[0] + self.interpreter_pack = packdetails[1] + self.interpreter_revision = packdetails[2] + self.interpreter_version = '.'.join(self.interpreter_pack.split('_')[2:]) + # hope our naming convention as at jan 2015 = package_[interp]_v0_v1_v2... = version v0.v1.v2.. is in play + except: + pass self.outFormats = opts.output_format self.inputFormats = opts.input_formats self.test1Output = '%s_test1_output.xls' % self.toolname @@ -371,74 +490,9 @@ """ - newXML=""" -%(tooldesc)s -%(requirements)s - -%(command)s - - -%(inputs)s -%(additionalInputs)s - - -%(outputs)s - - - -%(script)s - - - -%(tooltests)s - - - -%(help)s - - - - %(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 - newCommand=""" - %(toolname)s.py --script_path "$runMe" --interpreter "%(interpreter)s" - --tool_name "%(toolname)s" - %(command_inputs)s - %(command_outputs)s - """ - # may NOT be an input or htmlout - appended later - tooltestsTabOnly = """ - - %(test1Inputs)s - - - - %(additionalParams)s - - """ - tooltestsHTMLOnly = """ - - %(test1Inputs)s - - - %(additionalParams)s - - - """ - tooltestsBoth = """ - - %(test1Inputs)s - - - %(additionalParams)s - - - - """ + # these templates need a dict with the right keys to match the parameters - outputs, help, code... + xdict = {} xdict['additionalParams'] = '' xdict['additionalInputs'] = '' @@ -446,21 +500,26 @@ 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['additionalParams'] = '\n'.join(['' % (x.split(',')[0],html_escape(x.split(',')[1])) 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['interpreter_owner'] = self.interpreter_owner + xdict['interpreter_version'] = self.interpreter_version + xdict['interpreter_name'] = self.interpreter_pack xdict['requirements'] = '' - if self.opts.make_HTML: - if self.opts.include_dependencies == "yes": - xdict['requirements'] = protorequirements + if self.opts.include_dependencies == "yes": + if self.opts.envshpath <> 'system': + xdict['requirements'] = self.protorequirements_interpreter % xdict + else: + xdict['requirements'] = self.protorequirements xdict['tool_version'] = self.opts.tool_version xdict['test1HTML'] = self.test1HTML xdict['test1Output'] = self.test1Output xdict['test1Inputs'] = self.test1Inputs if self.opts.make_HTML and self.opts.output_tab: - xdict['tooltests'] = tooltestsBoth % xdict + xdict['tooltests'] = self.tooltestsBoth % xdict elif self.opts.make_HTML: - xdict['tooltests'] = tooltestsHTMLOnly % xdict + xdict['tooltests'] = self.tooltestsHTMLOnly % xdict else: - xdict['tooltests'] = tooltestsTabOnly % xdict + xdict['tooltests'] = self.tooltestsTabOnly % xdict xdict['script'] = self.escapedScript # configfile is least painful way to embed script to avoid external dependencies # but requires escaping of <, > and $ to avoid Mako parsing @@ -520,7 +579,7 @@ if self.opts.output_tab: xdict['command_outputs'] += ' --output_tab "$output1"' xdict['outputs'] += ' \n' % self.outFormats - xdict['command'] = newCommand % xdict + xdict['command'] = self.newCommand % xdict if self.opts.citations: citationstext = open(self.opts.citations,'r').read() citation_tuples = parse_citations(citationstext) @@ -531,7 +590,7 @@ xdict['citations'] = citations_xml else: xdict['citations'] = "" - xmls = newXML % xdict + xmls = self.newXML % xdict xf = open(self.xmlfile,'w') xf.write(xmls) xf.write('\n') @@ -555,10 +614,15 @@ hlp = open(self.opts.help_text,'r').read() else: hlp = 'Please ask the tool author for help as none was supplied at tool generation\n' + readme_dict = {'readme':hlp,'interpreter':self.opts.interpreter,'interpreter_version':self.interpreter_version,'interpreter_name':self.interpreter_pack, + 'interpreter_owner':self.interpreter_owner} if self.opts.include_dependencies == "yes": - tooldepcontent = toolhtmldepskel % hlp + if self.opts.envshpath == 'system': + tooldepcontent = self.toolhtmldepskel % readme_dict + else: + tooldepcontent = self.toolhtmldepinterpskel % readme_dict else: - tooldepcontent = emptytoolhtmldepskel % hlp + tooldepcontent = self.emptytoolhtmldepskel % readme_dictls -l depf = open(os.path.join(tdir,'tool_dependencies.xml'),'w') depf.write(tooldepcontent) depf.write('\n')