Mercurial > repos > fubar > tool_factory_2
comparison toolfactory/rgToolFactory2.py @ 75:25dd9364a32a draft
Uploaded
author | fubar |
---|---|
date | Sat, 14 Nov 2020 23:35:27 +0000 |
parents | 3d4324df911b |
children | 46db8143adb7 |
comparison
equal
deleted
inserted
replaced
74:3d4324df911b | 75:25dd9364a32a |
---|---|
22 # one to run the executable with the supplied test data and settings | 22 # one to run the executable with the supplied test data and settings |
23 # Be simpler to write the tool, then run it with planemo and soak up the test outputs. | 23 # Be simpler to write the tool, then run it with planemo and soak up the test outputs. |
24 | 24 |
25 | 25 |
26 import argparse | 26 import argparse |
27 import copy | |
28 import logging | 27 import logging |
29 import os | 28 import os |
30 import re | 29 import re |
31 import shutil | 30 import shutil |
32 import subprocess | 31 import subprocess |
33 import sys | 32 import sys |
34 import tarfile | 33 import tarfile |
35 import tempfile | 34 import tempfile |
36 import time | 35 import time |
37 | 36 |
38 from bioblend import galaxy | 37 |
39 from bioblend import toolshed | 38 from bioblend import toolshed |
40 | 39 |
41 import galaxyxml.tool as gxt | 40 import galaxyxml.tool as gxt |
42 import galaxyxml.tool.parameters as gxtp | 41 import galaxyxml.tool.parameters as gxtp |
43 | 42 |
90 # need this until a PR/version bump to fix galaxyxml prepending the exe even | 89 # need this until a PR/version bump to fix galaxyxml prepending the exe even |
91 # with override. | 90 # with override. |
92 | 91 |
93 | 92 |
94 def timenow(): | 93 def timenow(): |
95 """return current time as a string | 94 """return current time as a string""" |
96 """ | |
97 return time.strftime("%d/%m/%Y %H:%M:%S", time.localtime(time.time())) | 95 return time.strftime("%d/%m/%Y %H:%M:%S", time.localtime(time.time())) |
98 | 96 |
99 | 97 |
100 def quote_non_numeric(s): | 98 def quote_non_numeric(s): |
101 """return a prequoted string for non-numerics | 99 """return a prequoted string for non-numerics |
124 t = t.replace("\\$", "$") | 122 t = t.replace("\\$", "$") |
125 return t | 123 return t |
126 | 124 |
127 | 125 |
128 def parse_citations(citations_text): | 126 def parse_citations(citations_text): |
129 """ | 127 """""" |
130 """ | |
131 citations = [c for c in citations_text.split("**ENTRY**") if c.strip()] | 128 citations = [c for c in citations_text.split("**ENTRY**") if c.strip()] |
132 citation_tuples = [] | 129 citation_tuples = [] |
133 for citation in citations: | 130 for citation in citations: |
134 if citation.startswith("doi"): | 131 if citation.startswith("doi"): |
135 citation_tuples.append(("doi", citation[len("doi") :].strip())) | 132 citation_tuples.append(("doi", citation[len("doi") :].strip())) |
289 | 286 |
290 def cleanuppar(self): | 287 def cleanuppar(self): |
291 """ positional parameters are complicated by their numeric ordinal""" | 288 """ positional parameters are complicated by their numeric ordinal""" |
292 for i, p in enumerate(self.infiles): | 289 for i, p in enumerate(self.infiles): |
293 if self.args.parampass == "positional": | 290 if self.args.parampass == "positional": |
294 assert p[ICLPOS].isdigit(), ( | 291 assert p[ |
295 "Positional parameters must be ordinal integers - got %s for %s" | 292 ICLPOS |
296 % (p[ICLPOS], p[ILABPOS]) | 293 ].isdigit(), "Positional parameters must be ordinal integers - got %s for %s" % ( |
294 p[ICLPOS], | |
295 p[ILABPOS], | |
297 ) | 296 ) |
298 p.append(p[ICLPOS]) | 297 p.append(p[ICLPOS]) |
299 if p[ICLPOS].isdigit() or self.args.parampass == "0": | 298 if p[ICLPOS].isdigit() or self.args.parampass == "0": |
300 scl = "input%d" % (i + 1) | 299 scl = "input%d" % (i + 1) |
301 p[ICLPOS] = scl | 300 p[ICLPOS] = scl |
302 self.infiles[i] = p | 301 self.infiles[i] = p |
303 for i, p in enumerate( | 302 for i, p in enumerate( |
304 self.outfiles | 303 self.outfiles |
305 ): # trying to automagically gather using extensions | 304 ): # trying to automagically gather using extensions |
306 if self.args.parampass == "positional" and p[OCLPOS] != "STDOUT": | 305 if self.args.parampass == "positional" and p[OCLPOS] != "STDOUT": |
307 assert p[OCLPOS].isdigit(), ( | 306 assert p[ |
308 "Positional parameters must be ordinal integers - got %s for %s" | 307 OCLPOS |
309 % (p[OCLPOS], p[ONAMEPOS]) | 308 ].isdigit(), "Positional parameters must be ordinal integers - got %s for %s" % ( |
309 p[OCLPOS], | |
310 p[ONAMEPOS], | |
310 ) | 311 ) |
311 p.append(p[OCLPOS]) | 312 p.append(p[OCLPOS]) |
312 if p[OCLPOS].isdigit() or p[OCLPOS] == "STDOUT": | 313 if p[OCLPOS].isdigit() or p[OCLPOS] == "STDOUT": |
313 scl = p[ONAMEPOS] | 314 scl = p[ONAMEPOS] |
314 p[OCLPOS] = scl | 315 p[OCLPOS] = scl |
315 self.outfiles[i] = p | 316 self.outfiles[i] = p |
316 for i, p in enumerate(self.addpar): | 317 for i, p in enumerate(self.addpar): |
317 if self.args.parampass == "positional": | 318 if self.args.parampass == "positional": |
318 assert p[ACLPOS].isdigit(), ( | 319 assert p[ |
319 "Positional parameters must be ordinal integers - got %s for %s" | 320 ACLPOS |
320 % (p[ACLPOS], p[ANAMEPOS]) | 321 ].isdigit(), "Positional parameters must be ordinal integers - got %s for %s" % ( |
322 p[ACLPOS], | |
323 p[ANAMEPOS], | |
321 ) | 324 ) |
322 p.append(p[ACLPOS]) | 325 p.append(p[ACLPOS]) |
323 if p[ACLPOS].isdigit(): | 326 if p[ACLPOS].isdigit(): |
324 scl = "input%s" % p[ACLPOS] | 327 scl = "input%s" % p[ACLPOS] |
325 p[ACLPOS] = scl | 328 p[ACLPOS] = scl |
326 self.addpar[i] = p | 329 self.addpar[i] = p |
327 | 330 |
328 def clsimple(self): | 331 def clsimple(self): |
329 """ no parameters - uses < and > for i/o | 332 """no parameters - uses < and > for i/o""" |
330 """ | |
331 aCL = self.cl.append | 333 aCL = self.cl.append |
332 aXCL = self.xmlcl.append | 334 aXCL = self.xmlcl.append |
333 | 335 |
334 if len(self.infiles) > 0: | 336 if len(self.infiles) > 0: |
335 aCL("<") | 337 aCL("<") |
356 if self.lastxclredirect: | 358 if self.lastxclredirect: |
357 aXCL(self.lastxclredirect[0]) | 359 aXCL(self.lastxclredirect[0]) |
358 aXCL(self.lastxclredirect[1]) | 360 aXCL(self.lastxclredirect[1]) |
359 | 361 |
360 def clargparse(self): | 362 def clargparse(self): |
361 """ argparse style | 363 """argparse style""" |
362 """ | |
363 aCL = self.cl.append | 364 aCL = self.cl.append |
364 aXCL = self.xmlcl.append | 365 aXCL = self.xmlcl.append |
365 # inputs then params in argparse named form | 366 # inputs then params in argparse named form |
366 for (o_v, k, v, koverride) in self.xclsuffix: | 367 for (o_v, k, v, koverride) in self.xclsuffix: |
367 if koverride > "": | 368 if koverride > "": |
518 newfmt = self.outfiles[0][OFMTPOS] | 519 newfmt = self.outfiles[0][OFMTPOS] |
519 anout = gxtp.OutputData(newname, format=newfmt, num_dashes=0) | 520 anout = gxtp.OutputData(newname, format=newfmt, num_dashes=0) |
520 anout.command_line_override = "> $%s" % newname | 521 anout.command_line_override = "> $%s" % newname |
521 anout.positional = self.is_positional | 522 anout.positional = self.is_positional |
522 self.toutputs.append(anout) | 523 self.toutputs.append(anout) |
523 tp = gxtp.TestOutput(name=newname, value="%s_sample" % newname, format=newfmt) | 524 tp = gxtp.TestOutput( |
525 name=newname, value="%s_sample" % newname, format=newfmt | |
526 ) | |
524 self.testparam.append(tp) | 527 self.testparam.append(tp) |
525 | 528 |
526 def makeXML(self): | 529 def makeXML(self): |
527 """ | 530 """ |
528 Create a Galaxy xml tool wrapper for the new script | 531 Create a Galaxy xml tool wrapper for the new script |
535 self.newtool.command_override = self.xmlcl | 538 self.newtool.command_override = self.xmlcl |
536 if self.args.help_text: | 539 if self.args.help_text: |
537 helptext = open(self.args.help_text, "r").readlines() | 540 helptext = open(self.args.help_text, "r").readlines() |
538 safertext = [html_escape(x) for x in helptext] | 541 safertext = [html_escape(x) for x in helptext] |
539 if False and self.args.script_path: | 542 if False and self.args.script_path: |
540 scrp = self.script.split('\n') | 543 scrp = self.script.split("\n") |
541 scrpt = [' %s' % x for x in scrp] # try to stop templating | 544 scrpt = [" %s" % x for x in scrp] # try to stop templating |
542 scrpt.insert(0,"```\n") | 545 scrpt.insert(0, "```\n") |
543 if len(scrpt) > 300: | 546 if len(scrpt) > 300: |
544 safertext = safertext + scrpt[:100] + ['>500 lines - stuff deleted','......'] + scrpt[-100:] | 547 safertext = ( |
548 safertext + scrpt[:100] + \ | |
549 [">500 lines - stuff deleted", "......"] + scrpt[-100:] | |
550 ) | |
545 else: | 551 else: |
546 safertext = safertext + scrpt | 552 safertext = safertext + scrpt |
547 safertext.append("\n```") | 553 safertext.append("\n```") |
548 self.newtool.help = "\n".join([x for x in safertext]) | 554 self.newtool.help = "\n".join([x for x in safertext]) |
549 else: | 555 else: |
626 if os.path.exists(self.tlog): | 632 if os.path.exists(self.tlog): |
627 sto = open(self.tlog, "a") | 633 sto = open(self.tlog, "a") |
628 else: | 634 else: |
629 sto = open(self.tlog, "w") | 635 sto = open(self.tlog, "w") |
630 sto.write( | 636 sto.write( |
631 "## Executing Toolfactory generated command line = %s\n" % scl | 637 "## Executing Toolfactory generated command line = %s\n" % scl |
632 ) | 638 ) |
633 sto.flush() | 639 sto.flush() |
634 p = subprocess.run(self.cl, shell=False, stdout=sto, stderr=ste) | 640 p = subprocess.run(self.cl, shell=False, stdout=sto, stderr=ste) |
635 sto.close() | 641 sto.close() |
636 ste.close() | 642 ste.close() |
643 if len(self.outfiles) > 0: | 649 if len(self.outfiles) > 0: |
644 sto = open(self.outfiles[0][ONAMEPOS], "wb") | 650 sto = open(self.outfiles[0][ONAMEPOS], "wb") |
645 else: | 651 else: |
646 sto = sys.stdout | 652 sto = sys.stdout |
647 p = subprocess.run(self.cl, shell=False, stdout=sto, stdin=sti) | 653 p = subprocess.run(self.cl, shell=False, stdout=sto, stdin=sti) |
648 sto.write( | 654 sto.write("## Executing Toolfactory generated command line = %s\n" % scl) |
649 "## Executing Toolfactory generated command line = %s\n" % scl | |
650 ) | |
651 retval = p.returncode | 655 retval = p.returncode |
652 sto.close() | 656 sto.close() |
653 sti.close() | 657 sti.close() |
654 if os.path.isfile(self.tlog) and os.stat(self.tlog).st_size == 0: | 658 if os.path.isfile(self.tlog) and os.stat(self.tlog).st_size == 0: |
655 os.unlink(self.tlog) | 659 os.unlink(self.tlog) |
658 if retval != 0 and err: # problem | 662 if retval != 0 and err: # problem |
659 sys.stderr.write(err) | 663 sys.stderr.write(err) |
660 logging.debug("run done") | 664 logging.debug("run done") |
661 return retval | 665 return retval |
662 | 666 |
663 | |
664 def shedLoad(self): | 667 def shedLoad(self): |
665 """ | 668 """ |
666 {'deleted': False, | 669 {'deleted': False, |
667 'description': 'Tools for manipulating data', | 670 'description': 'Tools for manipulating data', |
668 'id': '175812cd7caaf439', | 671 'id': '175812cd7caaf439', |
675 if os.path.exists(self.tlog): | 678 if os.path.exists(self.tlog): |
676 sto = open(self.tlog, "a") | 679 sto = open(self.tlog, "a") |
677 else: | 680 else: |
678 sto = open(self.tlog, "w") | 681 sto = open(self.tlog, "w") |
679 | 682 |
680 ts = toolshed.ToolShedInstance(url=self.args.toolshed_url,key=self.args.toolshed_api_key,verify=False) | 683 ts = toolshed.ToolShedInstance( |
684 url=self.args.toolshed_url, key=self.args.toolshed_api_key, verify=False | |
685 ) | |
681 repos = ts.repositories.get_repositories() | 686 repos = ts.repositories.get_repositories() |
682 rnames = [x.get('name','?') for x in repos] | 687 rnames = [x.get("name", "?") for x in repos] |
683 rids = [x.get('id','?') for x in repos] | 688 rids = [x.get("id", "?") for x in repos] |
684 sto.write(f'############names={rnames} rids={rids}') | 689 sto.write(f"############names={rnames} rids={rids}") |
685 cat = 'ToolFactory generated tools' | 690 cat = "ToolFactory generated tools" |
686 if self.args.tool_name not in rnames: | 691 if self.args.tool_name not in rnames: |
687 tscat = ts.categories.get_categories() | 692 tscat = ts.categories.get_categories() |
688 cnames = [x.get('name','?') for x in tscat] | 693 cnames = [x.get("name", "?") for x in tscat] |
689 cids = [x.get('id','?') for x in tscat] | 694 cids = [x.get("id", "?") for x in tscat] |
690 catID = None | 695 catID = None |
691 if cat in cnames: | 696 if cat in cnames: |
692 ci = cnames.index(cat) | 697 ci = cnames.index(cat) |
693 catID = cids[ci] | 698 catID = cids[ci] |
694 res = ts.repositories.create_repository(name=self.args.tool_name, synopsis='Synopsis:%s' % self.args.tool_desc, description=self.args.tool_desc, | 699 res = ts.repositories.create_repository( |
695 type='unrestricted', remote_repository_url=self.args.toolshed_url, | 700 name=self.args.tool_name, |
696 homepage_url=None, category_ids=catID) | 701 synopsis="Synopsis:%s" % self.args.tool_desc, |
697 tid = res.get('id',None) | 702 description=self.args.tool_desc, |
698 sto.write(f'##########create res={res}') | 703 type="unrestricted", |
699 else: | 704 remote_repository_url=self.args.toolshed_url, |
700 i = rnames.index(self.args.tool_name) | 705 homepage_url=None, |
701 tid = rids[i] | 706 category_ids=catID, |
702 res = ts.repositories.update_repository(id=tid, tar_ball_path=self.newtarpath, commit_message=None) | 707 ) |
703 sto.write(f'#####update res={res}') | 708 tid = res.get("id", None) |
709 sto.write(f"##########create res={res}") | |
710 else: | |
711 i = rnames.index(self.args.tool_name) | |
712 tid = rids[i] | |
713 res = ts.repositories.update_repository( | |
714 id=tid, tar_ball_path=self.newtarpath, commit_message=None | |
715 ) | |
716 sto.write(f"#####update res={res}") | |
704 sto.close() | 717 sto.close() |
705 | 718 |
706 | |
707 def eph_galaxy_load(self): | 719 def eph_galaxy_load(self): |
708 """load the new tool from the local toolshed after planemo uploads it | 720 """load the new tool from the local toolshed after planemo uploads it""" |
709 """ | |
710 if os.path.exists(self.tlog): | 721 if os.path.exists(self.tlog): |
711 tout = open(self.tlog, "a") | 722 tout = open(self.tlog, "a") |
712 else: | 723 else: |
713 tout = open(self.tlog, "w") | 724 tout = open(self.tlog, "w") |
714 cll = [ | 725 cll = [ |
723 self.args.tool_name, | 734 self.args.tool_name, |
724 "--owner", | 735 "--owner", |
725 "fubar", | 736 "fubar", |
726 "--toolshed", | 737 "--toolshed", |
727 self.args.toolshed_url, | 738 self.args.toolshed_url, |
728 "--section_label", | 739 "--section_label", |
729 "ToolFactory", | 740 "ToolFactory", |
730 | |
731 ] | 741 ] |
732 tout.write("running\n%s\n" % " ".join(cll)) | 742 tout.write("running\n%s\n" % " ".join(cll)) |
733 p = subprocess.run(cll, shell=False, stderr=tout, stdout=tout) | 743 p = subprocess.run(cll, shell=False, stderr=tout, stdout=tout) |
734 tout.write("installed %s - got retcode %d\n" % (self.args.tool_name,p.returncode)) | 744 tout.write( |
745 "installed %s - got retcode %d\n" % (self.args.tool_name, p.returncode) | |
746 ) | |
735 tout.close() | 747 tout.close() |
736 return p.returncode | 748 return p.returncode |
737 | |
738 | 749 |
739 def planemo_shedload(self): | 750 def planemo_shedload(self): |
740 """ | 751 """ |
741 planemo shed_create --shed_target testtoolshed | 752 planemo shed_create --shed_target testtoolshed |
742 planemo shed_init --name=<name> | 753 planemo shed_init --name=<name> |
752 """ | 763 """ |
753 if os.path.exists(self.tlog): | 764 if os.path.exists(self.tlog): |
754 tout = open(self.tlog, "a") | 765 tout = open(self.tlog, "a") |
755 else: | 766 else: |
756 tout = open(self.tlog, "w") | 767 tout = open(self.tlog, "w") |
757 ts = toolshed.ToolShedInstance(url=self.args.toolshed_url,key=self.args.toolshed_api_key,verify=False) | 768 ts = toolshed.ToolShedInstance( |
769 url=self.args.toolshed_url, key=self.args.toolshed_api_key, verify=False | |
770 ) | |
758 repos = ts.repositories.get_repositories() | 771 repos = ts.repositories.get_repositories() |
759 rnames = [x.get('name','?') for x in repos] | 772 rnames = [x.get("name", "?") for x in repos] |
760 rids = [x.get('id','?') for x in repos] | 773 rids = [x.get("id", "?") for x in repos] |
761 tout.write(f'############names={rnames} rids={rids}') | 774 tout.write(f"############names={rnames} rids={rids}") |
762 cat = 'ToolFactory generated tools' | 775 #cat = "ToolFactory generated tools" |
763 if self.args.tool_name not in rnames: | 776 if self.args.tool_name not in rnames: |
764 cll = ["planemo", "shed_create", "--shed_target", "local", | 777 cll = [ |
765 "--owner","fubar","--name", | 778 "planemo", |
766 self.args.tool_name,"--shed_key", | 779 "shed_create", |
767 self.args.toolshed_api_key,] | 780 "--shed_target", |
781 "local", | |
782 "--owner", | |
783 "fubar", | |
784 "--name", | |
785 self.args.tool_name, | |
786 "--shed_key", | |
787 self.args.toolshed_api_key, | |
788 ] | |
768 try: | 789 try: |
769 p = subprocess.run( | 790 p = subprocess.run( |
770 cll, shell=False, cwd=self.tooloutdir, stdout=tout, stderr=tout | 791 cll, shell=False, cwd=self.tooloutdir, stdout=tout, stderr=tout |
771 ) | 792 ) |
772 except: | 793 except: |
773 pass | 794 pass |
774 if p.returncode != 0: | 795 if p.returncode != 0: |
775 tout.write("Repository %s exists" % self.args.tool_name) | 796 tout.write("Repository %s exists" % self.args.tool_name) |
776 else: | 797 else: |
777 tout.write("initiated %s" % self.args.tool_name) | 798 tout.write("initiated %s" % self.args.tool_name) |
778 cll = [ | 799 cll = [ |
779 "planemo", | 800 "planemo", |
780 "shed_upload", | 801 "shed_upload", |
788 self.args.toolshed_api_key, | 809 self.args.toolshed_api_key, |
789 "--tar", | 810 "--tar", |
790 self.newtarpath, | 811 self.newtarpath, |
791 ] | 812 ] |
792 p = subprocess.run(cll, shell=False, stdout=tout, stderr=tout) | 813 p = subprocess.run(cll, shell=False, stdout=tout, stderr=tout) |
793 tout.write("Ran %s got %d" % (" ".join(cll), p.returncode)) | 814 tout.write("Ran %s got %d" % (" ".join(cll), p.returncode)) |
794 tout.close() | 815 tout.close() |
795 return p.returncode | 816 return p.returncode |
796 | 817 |
797 | |
798 def eph_test(self): | 818 def eph_test(self): |
799 """ | 819 """""" |
800 """ | 820 if os.path.exists(self.tlog): |
801 if os.path.exists(self.tlog): | 821 tout = open(self.tlog, "a") |
802 tout = open(self.tlog, "a") | 822 else: |
803 else: | 823 tout = open(self.tlog, "w") |
804 tout = open(self.tlog, "w") | 824 cll = [ |
805 cll = [ | 825 "shed-tools", |
806 "shed-tools", | 826 "test", |
807 "test", | 827 "-g", |
808 "-g", | 828 self.args.galaxy_url, |
809 self.args.galaxy_url, | 829 "-a", |
810 "-a", | 830 self.args.galaxy_api_key, |
811 self.args.galaxy_api_key, | 831 "--name", |
812 "--name", | 832 self.args.tool_name, |
813 self.args.tool_name, | 833 "--owner", |
814 "--owner", | 834 "fubar", |
815 "fubar", | 835 ] |
816 ] | 836 p = subprocess.run( |
817 p = subprocess.run( | 837 cll, shell=False, cwd=self.tooloutdir, stderr=tout, stdout=tout |
818 cll, shell=False, cwd=self.tooloutdir, stderr=tout, stdout=tout | 838 ) |
819 ) | 839 tout.write("eph_test Ran %s got %d" % (" ".join(cll), p.returncode)) |
820 tout.write("eph_test Ran %s got %d" % (" ".join(cll), p.returncode)) | 840 tout.close() |
821 tout.close() | 841 return p.returncode |
822 return p.returncode | |
823 | 842 |
824 def planemo_test(self, genoutputs=True): | 843 def planemo_test(self, genoutputs=True): |
825 """planemo is a requirement so is available for testing | 844 """planemo is a requirement so is available for testing |
826 and for generating test outputs if command or test overrides are supplied | 845 and for generating test outputs if command or test overrides are supplied |
827 test outputs are sent to repdir for display | 846 test outputs are sent to repdir for display |
831 if os.path.exists(self.tlog): | 850 if os.path.exists(self.tlog): |
832 tout = open(self.tlog, "a") | 851 tout = open(self.tlog, "a") |
833 else: | 852 else: |
834 tout = open(self.tlog, "w") | 853 tout = open(self.tlog, "w") |
835 if genoutputs: | 854 if genoutputs: |
836 dummy,tfile = tempfile.mkstemp() | 855 dummy, tfile = tempfile.mkstemp() |
837 cll = [ | 856 cll = [ |
838 "planemo", | 857 "planemo", |
839 "test", | 858 "test", |
840 "--galaxy_root", | 859 "--galaxy_root", |
841 self.args.galaxy_root, | 860 self.args.galaxy_root, |
842 "--update_test_data", | 861 "--update_test_data", |
843 xreal, | 862 xreal, |
844 ] | 863 ] |
845 p = subprocess.run( | 864 p = subprocess.run( |
846 cll, shell=False, cwd=self.tooloutdir, stderr=dummy, stdout=dummy, | 865 cll, |
847 ) | 866 shell=False, |
848 else: | 867 cwd=self.tooloutdir, |
849 cll = ["planemo", "test", "--galaxy_root", | 868 stderr=dummy, |
869 stdout=dummy, | |
870 ) | |
871 else: | |
872 cll = [ | |
873 "planemo", | |
874 "test", | |
875 "--galaxy_root", | |
850 self.args.galaxy_root, | 876 self.args.galaxy_root, |
851 xreal,] | 877 xreal, |
878 ] | |
852 p = subprocess.run( | 879 p = subprocess.run( |
853 cll, shell=False, cwd=self.tooloutdir, stderr=tout, stdout=tout | 880 cll, shell=False, cwd=self.tooloutdir, stderr=tout, stdout=tout |
854 ) | 881 ) |
855 tout.close() | 882 tout.close() |
856 return p.returncode | 883 return p.returncode |
857 | 884 |
858 | |
859 | |
860 def writeShedyml(self): | 885 def writeShedyml(self): |
861 """for planemo | 886 """for planemo""" |
862 """ | |
863 yuser = self.args.user_email.split("@")[0] | 887 yuser = self.args.user_email.split("@")[0] |
864 yfname = os.path.join(self.tooloutdir, ".shed.yml") | 888 yfname = os.path.join(self.tooloutdir, ".shed.yml") |
865 yamlf = open(yfname, "w") | 889 yamlf = open(yfname, "w") |
866 odict = { | 890 odict = { |
867 "name": self.tool_name, | 891 "name": self.tool_name, |
873 } | 897 } |
874 yaml.dump(odict, yamlf, allow_unicode=True) | 898 yaml.dump(odict, yamlf, allow_unicode=True) |
875 yamlf.close() | 899 yamlf.close() |
876 | 900 |
877 def makeTool(self): | 901 def makeTool(self): |
878 """write xmls and input samples into place | 902 """write xmls and input samples into place""" |
879 """ | |
880 self.makeXML() | 903 self.makeXML() |
881 if self.args.script_path: | 904 if self.args.script_path: |
882 stname = os.path.join(self.tooloutdir, "%s" % (self.sfile)) | 905 stname = os.path.join(self.tooloutdir, "%s" % (self.sfile)) |
883 if not os.path.exists(stname): | 906 if not os.path.exists(stname): |
884 shutil.copyfile(self.sfile, stname) | 907 shutil.copyfile(self.sfile, stname) |
891 shutil.copyfile(pth, dest) | 914 shutil.copyfile(pth, dest) |
892 dest = os.path.join(self.repdir, "%s.%s" % (p[ICLPOS], p[IFMTPOS])) | 915 dest = os.path.join(self.repdir, "%s.%s" % (p[ICLPOS], p[IFMTPOS])) |
893 shutil.copyfile(pth, dest) | 916 shutil.copyfile(pth, dest) |
894 | 917 |
895 def makeToolTar(self): | 918 def makeToolTar(self): |
896 """ move outputs into test-data and prepare the tarball | 919 """move outputs into test-data and prepare the tarball""" |
897 """ | |
898 excludeme = "tool_test_output" | 920 excludeme = "tool_test_output" |
921 | |
899 def exclude_function(tarinfo): | 922 def exclude_function(tarinfo): |
900 filename = tarinfo.name | 923 filename = tarinfo.name |
901 return None if filename.startswith(excludeme) or os.path.splitext(filename)[1].startswith(excludeme) else tarinfo | 924 return ( |
925 None | |
926 if filename.startswith(excludeme) or \ | |
927 os.path.splitext(filename)[1].startswith(excludeme) | |
928 else tarinfo | |
929 ) | |
902 | 930 |
903 for p in self.outfiles: | 931 for p in self.outfiles: |
904 src = p[ONAMEPOS] | 932 src = p[ONAMEPOS] |
905 if os.path.isfile(src): | 933 if os.path.isfile(src): |
906 dest = os.path.join(self.testdir, "%s_sample" % src) | 934 dest = os.path.join(self.testdir, "%s_sample" % src) |
917 tf.add(name=self.tooloutdir, arcname=self.tool_name, filter=exclude_function) | 945 tf.add(name=self.tooloutdir, arcname=self.tool_name, filter=exclude_function) |
918 tf.close() | 946 tf.close() |
919 shutil.copyfile(self.newtarpath, self.args.new_tool) | 947 shutil.copyfile(self.newtarpath, self.args.new_tool) |
920 | 948 |
921 def moveRunOutputs(self): | 949 def moveRunOutputs(self): |
922 """need to move planemo or run outputs into toolfactory collection | 950 """need to move planemo or run outputs into toolfactory collection""" |
923 """ | |
924 with os.scandir(self.tooloutdir) as outs: | 951 with os.scandir(self.tooloutdir) as outs: |
925 for entry in outs: | 952 for entry in outs: |
926 if not entry.is_file() or entry.name.startswith("."): | 953 if not entry.is_file() or entry.name.startswith("."): |
927 continue | 954 continue |
928 if "." in entry.name: | 955 if "." in entry.name: |
966 a("--edit_additional_parameters", action="store_true", default=False) | 993 a("--edit_additional_parameters", action="store_true", default=False) |
967 a("--parampass", default="positional") | 994 a("--parampass", default="positional") |
968 a("--tfout", default="./tfout") | 995 a("--tfout", default="./tfout") |
969 a("--new_tool", default="new_tool") | 996 a("--new_tool", default="new_tool") |
970 a("--galaxy_url", default="http://localhost:8080") | 997 a("--galaxy_url", default="http://localhost:8080") |
971 a("--toolshed_url", default="http://localhost:9009") # make sure this is NOT 127.0.0.1 - it won't work if tool_sheds_conf.xml has localhost | 998 a( |
972 #a("--galaxy_api_key", default="1e62ddad74fe9bf112859f4e9efea48b") | 999 "--toolshed_url", default="http://localhost:9009" |
973 #a("--toolshed_api_key", default="9154c91f2a162bf12fda15764f43846c") | 1000 ) # make sure this is NOT 127.0.0.1 - it won't work if tool_sheds_conf.xml has localhost |
1001 # a("--galaxy_api_key", default="1e62ddad74fe9bf112859f4e9efea48b") | |
1002 # a("--toolshed_api_key", default="9154c91f2a162bf12fda15764f43846c") | |
974 | 1003 |
975 a("--toolshed_api_key", default="fakekey") | 1004 a("--toolshed_api_key", default="fakekey") |
976 a("--galaxy_api_key", default="fakekey") | 1005 a("--galaxy_api_key", default="fakekey") |
977 a("--galaxy_root", default="/galaxy-central") | 1006 a("--galaxy_root", default="/galaxy-central") |
978 | |
979 | 1007 |
980 args = parser.parse_args() | 1008 args = parser.parse_args() |
981 assert not args.bad_user, ( | 1009 assert not args.bad_user, ( |
982 'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to "admin_users" in the Galaxy configuration file' | 1010 'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to "admin_users" in the Galaxy configuration file' |
983 % (args.bad_user, args.bad_user) | 1011 % (args.bad_user, args.bad_user) |
1002 r.moveRunOutputs() | 1030 r.moveRunOutputs() |
1003 r.makeToolTar() | 1031 r.makeToolTar() |
1004 retcode = r.planemo_test(genoutputs=False) | 1032 retcode = r.planemo_test(genoutputs=False) |
1005 r.moveRunOutputs() | 1033 r.moveRunOutputs() |
1006 if args.make_Tool == "gentestinstall": | 1034 if args.make_Tool == "gentestinstall": |
1007 retcode = r.planemo_shedload() #r.shedLoad() | 1035 retcode = r.planemo_shedload() # r.shedLoad() |
1008 print(f'planemo_shedload returned {retcode}') | 1036 print(f"planemo_shedload returned {retcode}") |
1009 r.eph_galaxy_load() | 1037 r.eph_galaxy_load() |
1010 | |
1011 | 1038 |
1012 | 1039 |
1013 if __name__ == "__main__": | 1040 if __name__ == "__main__": |
1014 main() | 1041 main() |