comparison toolfactory/rgToolFactory2.py @ 56:68fbdbe35f08 draft

Uploaded
author fubar
date Tue, 20 Oct 2020 03:20:32 +0000
parents 4b71b252eacb
children d21517a36db8
comparison
equal deleted inserted replaced
55:dcf59d4e4515 56:68fbdbe35f08
206 clp = self.args.cl_prefix.split(" ") 206 clp = self.args.cl_prefix.split(" ")
207 for c in clp: 207 for c in clp:
208 aCL(c) 208 aCL(c)
209 aXCL(c) 209 aXCL(c)
210 else: 210 else:
211 if self.args.runmode == "Executable": 211 if self.args.script_path:
212 if self.args.script_path: 212 aCL(self.executeme)
213 aCL(self.executeme) 213 aCL(self.sfile)
214 aCL(self.sfile) 214 aXCL(self.executeme)
215 aXCL(self.executeme) 215 aXCL("$runme")
216 aXCL("$runme")
217 else:
218 aCL(self.executeme) # this little CL will just run
219 aXCL(self.executeme)
220 else: 216 else:
221 if self.args.script_path: 217 aCL(self.executeme) # this little CL will just run
222 aCL(self.executeme) 218 aXCL(self.executeme)
223 aCL(self.sfile)
224 aXCL(self.executeme)
225 aXCL("$runme")
226 else:
227 aCL(self.executeme) # this little CL will just run
228 aXCL(self.executeme)
229 self.elog = os.path.join(self.repdir, "%s_error_log.txt" % self.tool_name) 219 self.elog = os.path.join(self.repdir, "%s_error_log.txt" % self.tool_name)
230 self.tlog = os.path.join(self.repdir, "%s_runner_log.txt" % self.tool_name) 220 self.tlog = os.path.join(self.repdir, "%s_runner_log.txt" % self.tool_name)
231 221
232 if self.args.parampass == "0": 222 if self.args.parampass == "0":
233 self.clsimple() 223 self.clsimple()
529 Create a Galaxy xml tool wrapper for the new script 519 Create a Galaxy xml tool wrapper for the new script
530 Uses galaxyhtml 520 Uses galaxyhtml
531 Hmmm. How to get the command line into correct order... 521 Hmmm. How to get the command line into correct order...
532 """ 522 """
533 if self.command_override: 523 if self.command_override:
534 self.newtool.command_line_override = self.command_override # config file 524 self.newtool.command_override = self.command_override # config file
535 else: 525 else:
536 self.newtool.command_line_override = self.xmlcl 526 self.newtool.command_override = self.xmlcl
537 if self.args.help_text: 527 if self.args.help_text:
538 helptext = open(self.args.help_text, "r").readlines() 528 helptext = open(self.args.help_text, "r").readlines()
539 safertext = [html_escape(x) for x in helptext] 529 safertext = [html_escape(x) for x in helptext]
540 if self.args.script_path: 530 if self.args.script_path:
541 scrpt = self.script.split('\n') 531 scrpt = self.script.split('\n')
606 # ready for the tarball 596 # ready for the tarball
607 597
608 def run(self): 598 def run(self):
609 """ 599 """
610 generate test outputs by running a command line 600 generate test outputs by running a command line
611 won't work if command or test override in play - planemo is the 601 won't work if command or test override in play - planemo is the
612 easiest way to generate test outputs for that case so is 602 easiest way to generate test outputs for that case so is
613 automagically selected 603 automagically selected
614 """ 604 """
615 s = "run cl=%s" % str(self.cl) 605 s = "run cl=%s" % str(self.cl)
616 logging.debug(s) 606 logging.debug(s)
617 scl = " ".join(self.cl) 607 scl = " ".join(self.cl)
618 err = None 608 err = None
619 if self.args.parampass != "0": 609 if self.args.parampass != "0":
620 ste = open(self.elog, "wb") 610 if os.path.exists(self.elog):
611 ste = open(self.elog, "a")
612 else:
613 ste = open(self.elog, "w")
621 if self.lastclredirect: 614 if self.lastclredirect:
622 sto = open(self.lastclredirect[1], "wb") # is name of an output file 615 sto = open(self.lastclredirect[1], "wb") # is name of an output file
623 else: 616 else:
624 sto = open(self.tlog, "wb") 617 if os.path.exists(self.tlog):
618 sto = open(self.tlog, "a")
619 else:
620 sto = open(self.tlog, "w")
625 sto.write( 621 sto.write(
626 bytes( 622 "## Executing Toolfactory generated command line = %s\n" % scl
627 "## Executing Toolfactory generated command line = %s\n" % scl,
628 "utf8",
629 )
630 ) 623 )
631 sto.flush() 624 sto.flush()
632 p = subprocess.run(self.cl, shell=False, stdout=sto, stderr=ste) 625 p = subprocess.run(self.cl, shell=False, stdout=sto, stderr=ste)
633 sto.close() 626 sto.close()
634 ste.close() 627 ste.close()
635 tmp_stderr = open(self.elog, "rb")
636 err = ""
637 buffsize = 1048576
638 try:
639 while True:
640 err += str(tmp_stderr.read(buffsize))
641 if not err or len(err) % buffsize != 0:
642 break
643 except OverflowError:
644 pass
645 tmp_stderr.close()
646 retval = p.returncode 628 retval = p.returncode
647 else: # work around special case - stdin and write to stdout 629 else: # work around special case - stdin and write to stdout
648 sti = open(self.infiles[0][IPATHPOS], "rb") 630 sti = open(self.infiles[0][IPATHPOS], "rb")
649 sto = open(self.outfiles[0][ONAMEPOS], "wb") 631 sto = open(self.outfiles[0][ONAMEPOS], "wb")
650 # must use shell to redirect 632 # must use shell to redirect
693 "--shed_key", 675 "--shed_key",
694 self.args.toolshed_api_key, 676 self.args.toolshed_api_key,
695 "--tar", 677 "--tar",
696 self.newtarpath, 678 self.newtarpath,
697 ] 679 ]
698 p = subprocess.run(cll, shell=True) 680 p = subprocess.run(cll, shell=False)
699 print("Ran", " ".join(cll), "got", p.returncode) 681 print("Ran", " ".join(cll), "got", p.returncode)
700 tout.close() 682 tout.close()
701 return p.returncode 683 return p.returncode
702 684
703 def planemo_test(self, genoutputs=True): 685 def planemo_test(self, genoutputs=True):
715 "planemo", 697 "planemo",
716 "test", 698 "test",
717 "--galaxy_root", 699 "--galaxy_root",
718 self.args.galaxy_root, 700 self.args.galaxy_root,
719 "--update_test_data", 701 "--update_test_data",
720 "--galaxy_python_version",
721 "3.6",
722 xreal, 702 xreal,
723 ] 703 ]
724 else: 704 else:
725 cll = ["planemo", "test", "--galaxy_python_version", 705 cll = ["planemo", "test", "--galaxy_root",
726 "3.6", "--galaxy_root",
727 self.args.galaxy_root, 706 self.args.galaxy_root,
728 xreal,] 707 xreal,]
729 p = subprocess.run( 708 p = subprocess.run(
730 cll, shell=True, cwd=self.tooloutdir, stderr=tout, stdout=tout 709 cll, shell=False, cwd=self.tooloutdir, stderr=tout, stdout=tout
731 ) 710 )
732 if genoutputs: 711 if genoutputs:
733 with os.scandir(self.testdir) as outs: 712 with os.scandir(self.testdir) as outs:
734 for entry in outs: 713 for entry in outs:
735 if entry.is_file(): 714 if entry.is_file():
813 shutil.copyfile(pth, dest) 792 shutil.copyfile(pth, dest)
814 dest = os.path.join(self.repdir, "%s.%s" % (p[ICLPOS], p[IFMTPOS])) 793 dest = os.path.join(self.repdir, "%s.%s" % (p[ICLPOS], p[IFMTPOS]))
815 shutil.copyfile(pth, dest) 794 shutil.copyfile(pth, dest)
816 795
817 def makeToolTar(self): 796 def makeToolTar(self):
818 """ move outputs into test-data and prepare the tarball 797 """ move outputs into test-data and prepare the tarball
819 """ 798 """
820 for p in self.outfiles: 799 for p in self.outfiles:
821 src = p[ONAMEPOS] 800 src = p[ONAMEPOS]
822 if os.path.isfile(src): 801 if os.path.isfile(src):
823 dest = os.path.join(self.testdir, "%s_sample" % src) 802 dest = os.path.join(self.testdir, "%s_sample" % src)
881 a("--additional_parameters", action="append", default=[]) 860 a("--additional_parameters", action="append", default=[])
882 a("--edit_additional_parameters", action="store_true", default=False) 861 a("--edit_additional_parameters", action="store_true", default=False)
883 a("--parampass", default="positional") 862 a("--parampass", default="positional")
884 a("--tfout", default="./tfout") 863 a("--tfout", default="./tfout")
885 a("--new_tool", default="new_tool") 864 a("--new_tool", default="new_tool")
886 a("--runmode", default=None)
887 a("--galaxy_url", default="http://localhost:8080") 865 a("--galaxy_url", default="http://localhost:8080")
888 a("--galaxy_api_key", default="fakekey") 866 a("--galaxy_api_key", default="fakekey")
889 a("--toolshed_url", default="http://localhost:9009") 867 a("--toolshed_url", default="http://localhost:9009")
890 a("--toolshed_api_key", default="fakekey") 868 a("--toolshed_api_key", default="fakekey")
891 a("--galaxy_root", default="/galaxy-central") 869 a("--galaxy_root", default="/galaxy-central")