Mercurial > repos > fubar > tool_factory_2
comparison toolfactory/rgToolFactory2.py @ 76:46db8143adb7 draft
Uploaded
author | fubar |
---|---|
date | Mon, 16 Nov 2020 02:42:49 +0000 |
parents | 25dd9364a32a |
children | 89aca6c67405 |
comparison
equal
deleted
inserted
replaced
75:25dd9364a32a | 76:46db8143adb7 |
---|---|
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 datetime | |
28 import json | |
27 import logging | 29 import logging |
28 import os | 30 import os |
29 import re | 31 import re |
30 import shutil | 32 import shutil |
31 import subprocess | 33 import subprocess |
177 self.tool_id, | 179 self.tool_id, |
178 self.args.tool_version, | 180 self.args.tool_version, |
179 self.args.tool_desc, | 181 self.args.tool_desc, |
180 FAKEEXE, | 182 FAKEEXE, |
181 ) | 183 ) |
184 self.newtarpath = "toolfactory_%s.tgz" % self.tool_name | |
182 self.tooloutdir = "tfout" | 185 self.tooloutdir = "tfout" |
183 self.repdir = "TF_run_report_tempdir" | 186 self.repdir = "TF_run_report_tempdir" |
184 self.testdir = os.path.join(self.tooloutdir, "test-data") | 187 self.testdir = os.path.join(self.tooloutdir, "test-data") |
185 if not os.path.exists(self.tooloutdir): | 188 if not os.path.exists(self.tooloutdir): |
186 os.mkdir(self.tooloutdir) | 189 os.mkdir(self.tooloutdir) |
813 p = subprocess.run(cll, shell=False, stdout=tout, stderr=tout) | 816 p = subprocess.run(cll, shell=False, stdout=tout, stderr=tout) |
814 tout.write("Ran %s got %d" % (" ".join(cll), p.returncode)) | 817 tout.write("Ran %s got %d" % (" ".join(cll), p.returncode)) |
815 tout.close() | 818 tout.close() |
816 return p.returncode | 819 return p.returncode |
817 | 820 |
818 def eph_test(self): | 821 def eph_test(self, genoutputs=True): |
819 """""" | 822 """problem getting jobid - ephemeris upload is the job before the one we want - but depends on how many inputs |
823 """ | |
820 if os.path.exists(self.tlog): | 824 if os.path.exists(self.tlog): |
821 tout = open(self.tlog, "a") | 825 tout = open(self.tlog, "a") |
822 else: | 826 else: |
823 tout = open(self.tlog, "w") | 827 tout = open(self.tlog, "w") |
824 cll = [ | 828 cll = [ |
831 "--name", | 835 "--name", |
832 self.args.tool_name, | 836 self.args.tool_name, |
833 "--owner", | 837 "--owner", |
834 "fubar", | 838 "fubar", |
835 ] | 839 ] |
836 p = subprocess.run( | 840 if genoutputs: |
837 cll, shell=False, cwd=self.tooloutdir, stderr=tout, stdout=tout | 841 dummy, tfile = tempfile.mkstemp() |
838 ) | 842 p = subprocess.run( |
839 tout.write("eph_test Ran %s got %d" % (" ".join(cll), p.returncode)) | 843 cll, shell=False, stderr=dummy, stdout=dummy |
844 ) | |
845 | |
846 with open('tool_test_output.json','rb') as f: | |
847 s = json.loads(f.read()) | |
848 print('read %s' % s) | |
849 cl = s['tests'][0]['data']['job']['command_line'].split() | |
850 n = cl.index('--script_path') | |
851 jobdir = cl[n+1] | |
852 jobdir = jobdir.replace('"','') | |
853 jobdir = jobdir.split('/configs')[0] | |
854 print('jobdir=%s' % jobdir) | |
855 | |
856 #"/home/ross/galthrow/database/jobs_directory/000/649/configs/tmptfxu51gs\" | |
857 src = os.path.join(jobdir,'working',self.newtarpath) | |
858 if os.path.exists(src): | |
859 dest = os.path.join(self.testdir, self.newtarpath) | |
860 shutil.copyfile(src, dest) | |
861 else: | |
862 tout.write('No toolshed archive found after first ephemeris test - not a good sign') | |
863 ephouts = os.path.join(jobdir,'working','tfout','test-data') | |
864 with os.scandir(ephouts) as outs: | |
865 for entry in outs: | |
866 if not entry.is_file(): | |
867 continue | |
868 dest = os.path.join(self.tooloutdir, entry.name) | |
869 src = os.path.join(ephouts, entry.name) | |
870 shutil.copyfile(src, dest) | |
871 else: | |
872 p = subprocess.run( | |
873 cll, shell=False, stderr=tout, stdout=tout) | |
874 tout.write("eph_test Ran %s got %d" % (" ".join(cll), p.returncode)) | |
840 tout.close() | 875 tout.close() |
841 return p.returncode | 876 return p.returncode |
842 | 877 |
843 def planemo_test(self, genoutputs=True): | 878 def planemo_test(self, genoutputs=True): |
844 """planemo is a requirement so is available for testing | 879 """planemo is a requirement so is available for testing |
938 else: | 973 else: |
939 print( | 974 print( |
940 "### problem - output file %s not found in tooloutdir %s" | 975 "### problem - output file %s not found in tooloutdir %s" |
941 % (src, self.tooloutdir) | 976 % (src, self.tooloutdir) |
942 ) | 977 ) |
943 self.newtarpath = "toolfactory_%s.tgz" % self.tool_name | |
944 tf = tarfile.open(self.newtarpath, "w:gz") | 978 tf = tarfile.open(self.newtarpath, "w:gz") |
945 tf.add(name=self.tooloutdir, arcname=self.tool_name, filter=exclude_function) | 979 tf.add(name=self.tooloutdir, arcname=self.tool_name, filter=exclude_function) |
946 tf.close() | 980 tf.close() |
947 shutil.copyfile(self.newtarpath, self.args.new_tool) | 981 shutil.copyfile(self.newtarpath, self.args.new_tool) |
948 | 982 |
960 dest = os.path.join(self.repdir, ofn) | 994 dest = os.path.join(self.repdir, ofn) |
961 src = os.path.join(self.tooloutdir, entry.name) | 995 src = os.path.join(self.tooloutdir, entry.name) |
962 shutil.copyfile(src, dest) | 996 shutil.copyfile(src, dest) |
963 | 997 |
964 | 998 |
999 | |
965 def main(): | 1000 def main(): |
966 """ | 1001 """ |
967 This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as: | 1002 This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as: |
968 <command interpreter="python">rgBaseScriptWrapper.py --script_path "$scriptPath" | 1003 <command interpreter="python">rgBaseScriptWrapper.py --script_path "$scriptPath" |
969 --tool_name "foo" --interpreter "Rscript" | 1004 --tool_name "foo" --interpreter "Rscript" |
974 a("--script_path", default=None) | 1009 a("--script_path", default=None) |
975 a("--history_test", default=None) | 1010 a("--history_test", default=None) |
976 a("--cl_prefix", default=None) | 1011 a("--cl_prefix", default=None) |
977 a("--sysexe", default=None) | 1012 a("--sysexe", default=None) |
978 a("--packages", default=None) | 1013 a("--packages", default=None) |
979 a("--tool_name", default=None) | 1014 a("--tool_name", default="newtool") |
980 a("--tool_dir", default=None) | 1015 a("--tool_dir", default=None) |
981 a("--input_files", default=[], action="append") | 1016 a("--input_files", default=[], action="append") |
982 a("--output_files", default=[], action="append") | 1017 a("--output_files", default=[], action="append") |
983 a("--user_email", default="Unknown") | 1018 a("--user_email", default="Unknown") |
984 a("--bad_user", default=None) | 1019 a("--bad_user", default=None) |
994 a("--parampass", default="positional") | 1029 a("--parampass", default="positional") |
995 a("--tfout", default="./tfout") | 1030 a("--tfout", default="./tfout") |
996 a("--new_tool", default="new_tool") | 1031 a("--new_tool", default="new_tool") |
997 a("--galaxy_url", default="http://localhost:8080") | 1032 a("--galaxy_url", default="http://localhost:8080") |
998 a( | 1033 a( |
999 "--toolshed_url", default="http://localhost:9009" | 1034 "--toolshed_url", default="http://localhost:9009") |
1000 ) # make sure this is NOT 127.0.0.1 - it won't work if tool_sheds_conf.xml has localhost | 1035 # make sure this is identical to tool_sheds_conf.xml localhost != 127.0.0.1 so validation fails |
1001 # a("--galaxy_api_key", default="1e62ddad74fe9bf112859f4e9efea48b") | |
1002 # a("--toolshed_api_key", default="9154c91f2a162bf12fda15764f43846c") | |
1003 | |
1004 a("--toolshed_api_key", default="fakekey") | 1036 a("--toolshed_api_key", default="fakekey") |
1005 a("--galaxy_api_key", default="fakekey") | 1037 a("--galaxy_api_key", default="fakekey") |
1006 a("--galaxy_root", default="/galaxy-central") | 1038 a("--galaxy_root", default="/galaxy-central") |
1007 | |
1008 args = parser.parse_args() | 1039 args = parser.parse_args() |
1009 assert not args.bad_user, ( | 1040 assert not args.bad_user, ( |
1010 'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to "admin_users" in the Galaxy configuration file' | 1041 'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to "admin_users" in the Galaxy configuration file' |
1011 % (args.bad_user, args.bad_user) | 1042 % (args.bad_user, args.bad_user) |
1012 ) | 1043 ) |
1029 retcode = r.planemo_test(genoutputs=True) # this fails :( - see PR | 1060 retcode = r.planemo_test(genoutputs=True) # this fails :( - see PR |
1030 r.moveRunOutputs() | 1061 r.moveRunOutputs() |
1031 r.makeToolTar() | 1062 r.makeToolTar() |
1032 retcode = r.planemo_test(genoutputs=False) | 1063 retcode = r.planemo_test(genoutputs=False) |
1033 r.moveRunOutputs() | 1064 r.moveRunOutputs() |
1065 print(f"second planemo_test returned {retcode}") | |
1034 if args.make_Tool == "gentestinstall": | 1066 if args.make_Tool == "gentestinstall": |
1035 retcode = r.planemo_shedload() # r.shedLoad() | |
1036 print(f"planemo_shedload returned {retcode}") | |
1037 r.eph_galaxy_load() | 1067 r.eph_galaxy_load() |
1038 | 1068 |
1039 | 1069 |
1040 if __name__ == "__main__": | 1070 if __name__ == "__main__": |
1041 main() | 1071 main() |