Mercurial > repos > fubar > toolfactory
comparison rgToolFactory.py @ 11:704ccaade924 draft
Uploaded
| author | fubar |
|---|---|
| date | Thu, 20 Mar 2014 05:50:38 -0400 |
| parents | 1fcf3fda325f |
| children | a898ba82496e |
comparison
equal
deleted
inserted
replaced
| 10:59bce2efadfe | 11:704ccaade924 |
|---|---|
| 6 # all rights reserved | 6 # all rights reserved |
| 7 # Licensed under the LGPL | 7 # Licensed under the LGPL |
| 8 # suggestions for improvement and bug fixes welcome at https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home | 8 # suggestions for improvement and bug fixes welcome at https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home |
| 9 # | 9 # |
| 10 # march 2014 | 10 # march 2014 |
| 11 # added dependencies to a tool_dependencies.xml if html page generated so generated tool is properly portable | |
| 12 # | |
| 11 # added ghostscript and graphicsmagick as dependencies | 13 # added ghostscript and graphicsmagick as dependencies |
| 12 # fixed a wierd problem where gs was trying to use the new_files_path from universe (database/tmp) as ./database/tmp | 14 # fixed a wierd problem where gs was trying to use the new_files_path from universe (database/tmp) as ./database/tmp |
| 13 # errors ensued | 15 # errors ensued |
| 14 # | 16 # |
| 15 # august 2013 | 17 # august 2013 |
| 85 progname = os.path.split(sys.argv[0])[1] | 87 progname = os.path.split(sys.argv[0])[1] |
| 86 myversion = 'V001.1 March 2014' | 88 myversion = 'V001.1 March 2014' |
| 87 verbose = False | 89 verbose = False |
| 88 debug = False | 90 debug = False |
| 89 toolFactoryURL = 'https://bitbucket.org/fubar/galaxytoolfactory' | 91 toolFactoryURL = 'https://bitbucket.org/fubar/galaxytoolfactory' |
| 92 | |
| 93 # if we do html we need these dependencies | |
| 94 toolhtmldep = """<?xml version="1.0"?> | |
| 95 <tool_dependency> | |
| 96 <package name="ghostscript" version="9.10"> | |
| 97 <repository name="package_ghostscript_9_10" owner="devteam" prior_installation_required="True" toolshed="http://toolshed.g2.bx.psu.edu/" /> | |
| 98 </package> | |
| 99 <package name="graphicsmagick" version="1.3.18"> | |
| 100 <repository name="package_graphicsmagick_1_3" owner="iuc" prior_installation_required="True" toolshed="http://toolshed.g2.bx.psu.edu/" /> | |
| 101 </package> | |
| 102 <readme> | |
| 103 %s | |
| 104 </readme> | |
| 105 </tool_dependency> | |
| 106 """ | |
| 90 | 107 |
| 91 def timenow(): | 108 def timenow(): |
| 92 """return current time as a string | 109 """return current time as a string |
| 93 """ | 110 """ |
| 94 return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time())) | 111 return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time())) |
| 128 self.thumbformat = 'png' | 145 self.thumbformat = 'png' |
| 129 self.opts = opts | 146 self.opts = opts |
| 130 self.toolname = re.sub('[^a-zA-Z0-9_]+', '', opts.tool_name) # a sanitizer now does this but.. | 147 self.toolname = re.sub('[^a-zA-Z0-9_]+', '', opts.tool_name) # a sanitizer now does this but.. |
| 131 self.toolid = self.toolname | 148 self.toolid = self.toolname |
| 132 self.myname = sys.argv[0] # get our name because we write ourselves out as a tool later | 149 self.myname = sys.argv[0] # get our name because we write ourselves out as a tool later |
| 133 self.pyfile = self.myname # crude but efficient - the cruft won't hurt much | 150 self.pyfile = self.myname # crude but efficient - the cruft won't hurt muchself.tooldepfile) |
| 134 self.xmlfile = '%s.xml' % self.toolname | 151 self.xmlfile = '%s.xml' % self.toolname |
| 135 s = open(self.opts.script_path,'r').readlines() | 152 s = open(self.opts.script_path,'r').readlines() |
| 136 s = [x.rstrip() for x in s] # remove pesky dos line endings if needed | 153 s = [x.rstrip() for x in s] # remove pesky dos line endings if needed |
| 137 self.script = '\n'.join(s) | 154 self.script = '\n'.join(s) |
| 138 fhandle,self.sfile = tempfile.mkstemp(prefix=self.toolname,suffix=".%s" % (opts.interpreter)) | 155 fhandle,self.sfile = tempfile.mkstemp(prefix=self.toolname,suffix=".%s" % (opts.interpreter)) |
| 231 %(tooltests)s | 248 %(tooltests)s |
| 232 <help> | 249 <help> |
| 233 %(help)s | 250 %(help)s |
| 234 </help> | 251 </help> |
| 235 </tool>""" # needs a dict with toolname, toolid, interpreter, scriptname, command, inputs as a multi line string ready to write, outputs ditto, help ditto | 252 </tool>""" # needs a dict with toolname, toolid, interpreter, scriptname, command, inputs as a multi line string ready to write, outputs ditto, help ditto |
| 236 | 253 |
| 237 newCommand="""<command interpreter="python"> | 254 newCommand="""<command interpreter="python"> |
| 238 %(toolname)s.py --script_path "$runMe" --interpreter "%(interpreter)s" | 255 %(toolname)s.py --script_path "$runMe" --interpreter "%(interpreter)s" |
| 239 --tool_name "%(toolname)s" %(command_inputs)s %(command_outputs)s | 256 --tool_name "%(toolname)s" %(command_inputs)s %(command_outputs)s |
| 240 </command>""" # may NOT be an input or htmlout | 257 </command>""" # may NOT be an input or htmlout |
| 241 tooltestsTabOnly = """<tests><test> | 258 tooltestsTabOnly = """<tests><test> |
| 321 """ | 338 """ |
| 322 retval = self.run() | 339 retval = self.run() |
| 323 if retval: | 340 if retval: |
| 324 print >> sys.stderr,'## Run failed. Cannot build yet. Please fix and retry' | 341 print >> sys.stderr,'## Run failed. Cannot build yet. Please fix and retry' |
| 325 sys.exit(1) | 342 sys.exit(1) |
| 326 self.makeXML() | |
| 327 tdir = self.toolname | 343 tdir = self.toolname |
| 328 os.mkdir(tdir) | 344 os.mkdir(tdir) |
| 345 self.makeXML() | |
| 346 if self.opts.make_HTML: | |
| 347 if self.opts.help_text: | |
| 348 hlp = open(self.opts.help_text,'r').read() | |
| 349 else: | |
| 350 hlp = 'Please ask the tool author for help as none was supplied at tool generation\n' | |
| 351 tooldeps = toolhtmldep % hlp | |
| 352 depf = open('tool_dependencies.xml','w') | |
| 353 depf.write(hlp) | |
| 354 depf.write('\n') | |
| 355 depf.close() | |
| 329 if self.opts.input_tab <> 'None': # no reproducible test otherwise? TODO: maybe.. | 356 if self.opts.input_tab <> 'None': # no reproducible test otherwise? TODO: maybe.. |
| 330 testdir = os.path.join(tdir,'test-data') | 357 testdir = os.path.join(tdir,'test-data') |
| 331 os.mkdir(testdir) # make tests directory | 358 os.mkdir(testdir) # make tests directory |
| 332 shutil.copyfile(self.opts.input_tab,os.path.join(testdir,self.test1Input)) | 359 shutil.copyfile(self.opts.input_tab,os.path.join(testdir,self.test1Input)) |
| 333 if self.opts.output_tab <> 'None': | 360 if self.opts.output_tab <> 'None': |
