Mercurial > repos > fubar > tool_factory_2
comparison toolfactory/rgToolFactory2.py @ 80:f423a77bc669 draft
Uploaded
author | fubar |
---|---|
date | Tue, 17 Nov 2020 09:04:25 +0000 |
parents | 89aca6c67405 |
children | 6395be766c2e |
comparison
equal
deleted
inserted
replaced
79:2d0272e730d1 | 80:f423a77bc669 |
---|---|
687 url=self.args.toolshed_url, key=self.args.toolshed_api_key, verify=False | 687 url=self.args.toolshed_url, key=self.args.toolshed_api_key, verify=False |
688 ) | 688 ) |
689 repos = ts.repositories.get_repositories() | 689 repos = ts.repositories.get_repositories() |
690 rnames = [x.get("name", "?") for x in repos] | 690 rnames = [x.get("name", "?") for x in repos] |
691 rids = [x.get("id", "?") for x in repos] | 691 rids = [x.get("id", "?") for x in repos] |
692 sto.write(f"############names={rnames} rids={rids}") | 692 sto.write(f"############names={rnames} rids={rids}\n") |
693 cat = "ToolFactory generated tools" | 693 cat = "ToolFactory generated tools" |
694 if self.args.tool_name not in rnames: | 694 if self.args.tool_name not in rnames: |
695 tscat = ts.categories.get_categories() | 695 tscat = ts.categories.get_categories() |
696 cnames = [x.get("name", "?") for x in tscat] | 696 cnames = [x.get("name", "?") for x in tscat] |
697 cids = [x.get("id", "?") for x in tscat] | 697 cids = [x.get("id", "?") for x in tscat] |
707 remote_repository_url=self.args.toolshed_url, | 707 remote_repository_url=self.args.toolshed_url, |
708 homepage_url=None, | 708 homepage_url=None, |
709 category_ids=catID, | 709 category_ids=catID, |
710 ) | 710 ) |
711 tid = res.get("id", None) | 711 tid = res.get("id", None) |
712 sto.write(f"##########create res={res}") | 712 sto.write(f"##########create res={res}\n") |
713 else: | 713 else: |
714 i = rnames.index(self.args.tool_name) | 714 i = rnames.index(self.args.tool_name) |
715 tid = rids[i] | 715 tid = rids[i] |
716 res = ts.repositories.update_repository( | 716 res = ts.repositories.update_repository( |
717 id=tid, tar_ball_path=self.newtarpath, commit_message=None | 717 id=tid, tar_ball_path=self.newtarpath, commit_message=None |
718 ) | 718 ) |
719 sto.write(f"#####update res={res}") | 719 sto.write(f"#####update res={res}\n") |
720 sto.close() | 720 sto.close() |
721 | 721 |
722 def eph_galaxy_load(self): | 722 def eph_galaxy_load(self): |
723 """load the new tool from the local toolshed after planemo uploads it""" | 723 """load the new tool from the local toolshed after planemo uploads it""" |
724 if os.path.exists(self.tlog): | 724 if os.path.exists(self.tlog): |
772 url=self.args.toolshed_url, key=self.args.toolshed_api_key, verify=False | 772 url=self.args.toolshed_url, key=self.args.toolshed_api_key, verify=False |
773 ) | 773 ) |
774 repos = ts.repositories.get_repositories() | 774 repos = ts.repositories.get_repositories() |
775 rnames = [x.get("name", "?") for x in repos] | 775 rnames = [x.get("name", "?") for x in repos] |
776 rids = [x.get("id", "?") for x in repos] | 776 rids = [x.get("id", "?") for x in repos] |
777 tout.write(f"############names={rnames} rids={rids}") | |
778 #cat = "ToolFactory generated tools" | 777 #cat = "ToolFactory generated tools" |
779 if self.args.tool_name not in rnames: | 778 if self.args.tool_name not in rnames: |
780 cll = [ | 779 cll = [ |
781 "planemo", | 780 "planemo", |
782 "shed_create", | 781 "shed_create", |
794 cll, shell=False, cwd=self.tooloutdir, stdout=tout, stderr=tout | 793 cll, shell=False, cwd=self.tooloutdir, stdout=tout, stderr=tout |
795 ) | 794 ) |
796 except: | 795 except: |
797 pass | 796 pass |
798 if p.returncode != 0: | 797 if p.returncode != 0: |
799 tout.write("Repository %s exists" % self.args.tool_name) | 798 tout.write("Repository %s exists\n" % self.args.tool_name) |
800 else: | 799 else: |
801 tout.write("initiated %s" % self.args.tool_name) | 800 tout.write("initiated %s\n" % self.args.tool_name) |
802 cll = [ | 801 cll = [ |
803 "planemo", | 802 "planemo", |
804 "shed_upload", | 803 "shed_upload", |
805 "--shed_target", | 804 "--shed_target", |
806 "local", | 805 "local", |
812 self.args.toolshed_api_key, | 811 self.args.toolshed_api_key, |
813 "--tar", | 812 "--tar", |
814 self.newtarpath, | 813 self.newtarpath, |
815 ] | 814 ] |
816 p = subprocess.run(cll, shell=False, stdout=tout, stderr=tout) | 815 p = subprocess.run(cll, shell=False, stdout=tout, stderr=tout) |
817 tout.write("Ran %s got %d" % (" ".join(cll), p.returncode)) | 816 tout.write("Ran %s got %d\n" % (" ".join(cll), p.returncode)) |
818 tout.close() | 817 tout.close() |
819 return p.returncode | 818 return p.returncode |
820 | 819 |
821 def eph_test(self, genoutputs=True): | 820 def eph_test(self, genoutputs=True): |
822 """problem getting jobid - ephemeris upload is the job before the one we want - but depends on how many inputs | 821 """problem getting jobid - ephemeris upload is the job before the one we want - but depends on how many inputs |
890 if genoutputs: | 889 if genoutputs: |
891 dummy, tfile = tempfile.mkstemp() | 890 dummy, tfile = tempfile.mkstemp() |
892 cll = [ | 891 cll = [ |
893 "planemo", | 892 "planemo", |
894 "test", | 893 "test", |
895 "--test_output_xunit",os.path.join(self.repdir,f"{self.tool_name}_xunit.xml") | |
896 "--test_data", os.path.abspath(self.testdir), | 894 "--test_data", os.path.abspath(self.testdir), |
897 "--test_output", os.path.abspath(tool_test_path), | 895 "--test_output", os.path.abspath(tool_test_path), |
898 "--galaxy_root", | 896 "--galaxy_root", |
899 self.args.galaxy_root, | 897 self.args.galaxy_root, |
900 "--update_test_data", | 898 "--update_test_data", |
902 ] | 900 ] |
903 p = subprocess.run( | 901 p = subprocess.run( |
904 cll, | 902 cll, |
905 shell=False, | 903 shell=False, |
906 cwd=self.tooloutdir, | 904 cwd=self.tooloutdir, |
907 stderr=tout, | 905 stderr=dummy, |
908 stdout=tout, | 906 stdout=dummy, |
909 ) | 907 ) |
908 | |
910 else: | 909 else: |
911 cll = [ | 910 cll = [ |
912 "planemo", | 911 "planemo", |
913 "test", | 912 "test", |
914 "--test_data", self.testdir, | 913 "--test_data", os.path.abspath(self.testdir), |
915 "--test_output", tool_test_path, | 914 "--test_output", os.path.abspath(tool_test_path), |
916 "--galaxy_root", | 915 "--galaxy_root", |
917 self.args.galaxy_root, | 916 self.args.galaxy_root, |
918 os.path.abspath(xreal), | 917 os.path.abspath(xreal), |
919 ] | 918 ] |
920 p = subprocess.run( | 919 p = subprocess.run( |
951 shutil.copyfile(xreal, xout) | 950 shutil.copyfile(xreal, xout) |
952 for p in self.infiles: | 951 for p in self.infiles: |
953 pth = p[IPATHPOS] | 952 pth = p[IPATHPOS] |
954 dest = os.path.join(self.testdir, "%s_sample" % p[ICLPOS]) | 953 dest = os.path.join(self.testdir, "%s_sample" % p[ICLPOS]) |
955 shutil.copyfile(pth, dest) | 954 shutil.copyfile(pth, dest) |
956 dest = os.path.join(self.repdir, "%s.%s" % (p[ICLPOS], p[IFMTPOS])) | |
957 shutil.copyfile(pth, dest) | |
958 | 955 |
959 def makeToolTar(self): | 956 def makeToolTar(self): |
960 """move outputs into test-data and prepare the tarball""" | 957 """move outputs into test-data and prepare the tarball""" |
961 excludeme = "tool_test_output" | 958 excludeme = "tool_test_output" |
962 | 959 |
963 def exclude_function(tarinfo): | 960 def exclude_function(tarinfo): |
964 filename = tarinfo.name | 961 filename = tarinfo.name |
965 return ( | 962 return ( |
966 None | 963 None |
967 if filename.startswith(excludeme) or \ | 964 if filename.startswith(excludeme) |
968 os.path.splitext(filename)[1].startswith(excludeme) | |
969 else tarinfo | 965 else tarinfo |
970 ) | 966 ) |
971 | 967 |
972 for p in self.outfiles: | 968 for p in self.outfiles: |
973 src = p[ONAMEPOS] | 969 src = p[ONAMEPOS] |
988 | 984 |
989 def moveRunOutputs(self): | 985 def moveRunOutputs(self): |
990 """need to move planemo or run outputs into toolfactory collection""" | 986 """need to move planemo or run outputs into toolfactory collection""" |
991 with os.scandir(self.tooloutdir) as outs: | 987 with os.scandir(self.tooloutdir) as outs: |
992 for entry in outs: | 988 for entry in outs: |
993 if not entry.is_file() or entry.name.startswith("."): | 989 if not entry.is_file(): |
990 continue | |
991 if "." in entry.name: | |
992 nayme, ext = os.path.splitext(entry.name) | |
993 if ext in ['.yml','.xml','.json','.yaml']: | |
994 ext = f'{ext}.txt' | |
995 else: | |
996 ext = ".txt" | |
997 ofn = "%s%s" % (entry.name.replace(".", "_"), ext) | |
998 dest = os.path.join(self.repdir, ofn) | |
999 src = os.path.join(self.tooloutdir, entry.name) | |
1000 shutil.copyfile(src, dest) | |
1001 with os.scandir(self.testdir) as outs: | |
1002 for entry in outs: | |
1003 if not entry.is_file(): | |
994 continue | 1004 continue |
995 if "." in entry.name: | 1005 if "." in entry.name: |
996 nayme, ext = os.path.splitext(entry.name) | 1006 nayme, ext = os.path.splitext(entry.name) |
997 else: | 1007 else: |
998 ext = ".txt" | 1008 ext = ".txt" |
999 ofn = "%s%s" % (entry.name.replace(".", "_"), ext) | 1009 newname = f"{entry.name}{ext}" |
1000 dest = os.path.join(self.repdir, ofn) | 1010 dest = os.path.join(self.repdir, newname) |
1001 src = os.path.join(self.tooloutdir, entry.name) | 1011 src = os.path.join(self.testdir, entry.name) |
1002 shutil.copyfile(src, dest) | 1012 shutil.copyfile(src, dest) |
1003 | 1013 |
1004 | 1014 |
1005 | 1015 |
1006 def main(): | 1016 def main(): |
1066 retcode = r.planemo_test(genoutputs=True) # this fails :( - see PR | 1076 retcode = r.planemo_test(genoutputs=True) # this fails :( - see PR |
1067 r.moveRunOutputs() | 1077 r.moveRunOutputs() |
1068 r.makeToolTar() | 1078 r.makeToolTar() |
1069 retcode = r.planemo_test(genoutputs=False) | 1079 retcode = r.planemo_test(genoutputs=False) |
1070 r.moveRunOutputs() | 1080 r.moveRunOutputs() |
1081 r.makeToolTar() | |
1071 print(f"second planemo_test returned {retcode}") | 1082 print(f"second planemo_test returned {retcode}") |
1072 if args.make_Tool == "gentestinstall": | 1083 if args.make_Tool == "gentestinstall": |
1084 r.shedLoad() | |
1073 r.eph_galaxy_load() | 1085 r.eph_galaxy_load() |
1074 | 1086 |
1075 | 1087 |
1076 if __name__ == "__main__": | 1088 if __name__ == "__main__": |
1077 main() | 1089 main() |