Mercurial > repos > fubar_too > toolfactory
changeset 4:1bdd651a784f draft
Uploaded
author | fubar_too |
---|---|
date | Mon, 24 May 2021 02:37:52 +0000 |
parents | 02c4c16327a0 |
children | 372903c598a8 |
files | toolfactory/.shed.yml toolfactory/ToolFactory.py toolfactory/ToolFactory.xml toolfactory/test-data/output2_sample toolfactory/test-data/pyrevpos.python toolfactory/test-data/pyrevpos_not_tested.toolshed_sample toolfactory/test-data/test1_log.txt toolfactory/test-data/toolfactory_pyrevpos_tgz_sample |
diffstat | 8 files changed, 189 insertions(+), 116 deletions(-) [+] |
line wrap: on
line diff
--- a/toolfactory/.shed.yml Fri May 21 02:05:27 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -name: toolfactory -owner: fubar -description: ToolFactory - tool to make Galaxy tools ready for the toolshed -homepage_url: https://github.com/fubar2/toolfactory -long_description: | - ToolFactory - turn executable packages and R/python/perl/bash scripts into ordinary Galaxy tools - - Creating re-usable tools from scripts: The Galaxy Tool Factory Ross Lazarus; Antony Kaspi; Mark Ziemann; The Galaxy Team - Bioinformatics 2012; doi: 10.1093/bioinformatics/bts573 -remote_repository_url: https://github.com/fubar2/toolfactory -type: tool_dependency_definition -categories: -- Tool Generators
--- a/toolfactory/ToolFactory.py Fri May 21 02:05:27 2021 +0000 +++ b/toolfactory/ToolFactory.py Mon May 24 02:37:52 2021 +0000 @@ -20,6 +20,7 @@ import json import os import re +import rpyc import shlex import shutil import subprocess @@ -70,101 +71,6 @@ citation_tuples.append(("bibtex", citation[len("bibtex") :].strip())) return citation_tuples -class Locker: - """ - multiple instances of the TF may try to update tool_conf.xml so use a simple lockfile - to prevent overwriting mix ups. - """ - def __enter__ (self): - lockfile = "/tmp/.toolfactory_lockfile.lck" - if not os.path.exists(lockfile): - try: - os.utime(lockfile, None) - except OSError: - open(lockfile, 'a').close() - self.fp = open(lockfile) - fcntl.flock(self.fp.fileno(), fcntl.LOCK_EX) - - def __exit__ (self, _type, value, tb): - fcntl.flock(self.fp.fileno(), fcntl.LOCK_UN) - self.fp.close() - - -class Tool_Conf_Updater: - - """# update config/tool_conf.xml with a new tool unpacked in /tools - # requires highly insecure docker settings - like write to tool_conf.xml and to tools ! - # if in a container possibly not so courageous. - # Fine on your own laptop but security red flag for most production instances - Note potential race condition for tool_conf.xml update - uses a file lock. - """ - - def __init__( - self, args, tool_conf_path, new_tool_archive_path, new_tool_name, local_tool_dir - ): - self.args = args - self.tool_conf_path = os.path.join(args.galaxy_root, tool_conf_path) - self.tool_dir = os.path.join(args.galaxy_root, local_tool_dir,'TFtools') - self.out_section = "ToolFactory Generated Tools" - tff = tarfile.open(new_tool_archive_path, "r:*") - flist = tff.getnames() - ourdir = os.path.commonpath(flist) # eg pyrevpos - self.tool_id = ourdir # they are the same for TF tools - ourxml = [x for x in flist if x.lower().endswith(".xml")] - tff.extractall() - tff.close() - try: - self.run_rsync(ourdir, self.tool_dir) - with Locker(): - self.update_toolconf(ourdir, ourxml) - except Exception: - print('Cannot install the new tool. This is only possible in the ToolFactory appliance at https://github.com/fubar2/toolfactory-galaxy-server') - - def run_rsync(self, srcf, dstf): - src = os.path.abspath(srcf) - dst = os.path.abspath(dstf) - if os.path.isdir(src): - cll = ["rsync", "-r", src, dst] - else: - cll = ["rsync", src, dst] - subprocess.run( - cll, - capture_output=False, - encoding="utf8", - shell=False, - ) - - - def update_toolconf(self, ourdir, ourxml): # path is relative to tools - - def sortchildrenby(parent, attr): - parent[:] = sorted(parent, key=lambda child: child.get(attr)) - - localconf = "./local_tool_conf.xml" - self.run_rsync(self.tool_conf_path, localconf) - tree = ET.parse(localconf) - root = tree.getroot() - hasTF = False - TFsection = None - for e in root.findall("section"): - if e.attrib["name"] == self.out_section: - hasTF = True - TFsection = e - if not hasTF: - TFsection = ET.Element("section", {"id":self.out_section, "name":self.out_section}) - root.insert(0, TFsection) # at the top! - our_tools = TFsection.findall("tool") - conf_tools = [x.attrib["file"] for x in our_tools] - for xml in ourxml: # may be > 1 - if xml not in conf_tools: # new - ET.SubElement(TFsection, "tool", {"file": os.path.join('TFtools', xml)}) - sortchildrenby(TFsection,"file") - newconf = f"{self.tool_id}_conf" - tree.write(newconf, pretty_print=True) - self.run_rsync(newconf, self.tool_conf_path) - - - class Tool_Factory: """Wrapper for an arbitrary script @@ -978,13 +884,14 @@ r.makeTool() r.makeToolTar() if args.install: - TCU = Tool_Conf_Updater( - args=args, - local_tool_dir=args.local_tools, - new_tool_archive_path=r.newtarpath, - tool_conf_path=args.tool_conf_path, - new_tool_name=r.tool_name - ) + try: + conn = rpyc.connect("planemo-server", port=9999, config={'sync_request_timeout':1200}) + except ConnectionRefusedError: + print('### no remote rpyc server found on port 9999 - this only works in the ToolFactory Appliance with that server running...') + sys.exit(1) + res = conn.root.tool_updater(galaxy_root=args.galaxy_root, + tool_conf_path=args.tool_conf_path, new_tool_archive_path=os.path.abspath(r.newtarpath), + new_tool_name=r.tool_name, local_tool_dir=args.local_tools) if __name__ == "__main__": main()
--- a/toolfactory/ToolFactory.xml Fri May 21 02:05:27 2021 +0000 +++ b/toolfactory/ToolFactory.xml Mon May 24 02:37:52 2021 +0000 @@ -189,7 +189,7 @@ <requirements> <requirement type="package" version="0.4.14">galaxyxml</requirement> <requirement type="package" version="0.15.0">bioblend</requirement> - <requirement type="package" version="3.2.3">rsync</requirement> + <requirement type="package" version="5.0.1">rpyc</requirement> </requirements> <command detect_errors="exit_code"><![CDATA[
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/toolfactory/test-data/output2_sample Mon May 24 02:37:52 2021 +0000 @@ -0,0 +1,165 @@ +*trats uoy erofeb GNINRAW* + +YLNO yxalaG etavirp a no loot siht llatsnI +ecnatsni noitcudorp ro cilbup a no REVEN esaelP + +troppus noitatic gnidda notlihC nhoJ yb 4102 tsugua detadpU + +keeB ned nav suiraM yb detroper sgub xif ot 4102 8 tsugua detadpU + +ta ecruoser eht etic esaelP +fer=epytyek&JWYdwMrWs1hQzcl=yekji?375stb/tnirper/igc/gro.slanruojdrofxo.scitamrofnioib//:ptth +.krow dehsilbup ruoy ni loot siht esu uoy fi + +**yrotS trohS** + +.sloot yxalaG wen gnitareneg fo elbapac loot yxalaG lausunu na si sihT +gnitpircs suoregnad ylemertxe erofereht dna *detcirtsernu* gnisopxe yb skrow tI +ot meht gniwolla ,revres yxalaG tsoh eht fo srotartsinimda detangised lla ot +,stes atad tupni detceles elpitlum revo lrep dna hs ,nohtyp ,R ni stpircs nur +.tuptuo sa tes atad wen elgnis a gnitirw + +*sretemarap elyts esrapgra ro lanoitisop htiw elbatucexe yna ro tpircs hsab/lrep/nohtyp/r gnikrow a evah uoY* + +.loot yxalaG a gnisu ,setunim ni loot yxalaG yranidro na otni denrut eb nac tI + + +**yxalaG yna otni noitallatsni rof sloot yxalaG wen fo noitareneg detamotuA** + +.ylppus uoy sgnittes retemarap dna stupni atad tset elpmas llams gnisu detareneg si tset A +a dliub ot desu eb nac yeht ,decudorp neeb evah stuptuo esac tset eht ecnO +tnemeriuqer a sa dekab si elbatucexe ro tpircs deilppus ehT .loot yxalaG wen +.xob eht fo tuo elbitapmoc wolfkrow ylluf ,loot yxalaG yranidro ,wen a otni +rotartsinimda na yb dehs loot a aiv dellatsni era sloot detareneG +.sresu ruoy rof sloot yxalaG rehto lla ekil yltcaxe krow dna + +**liateD eroM** + +a otni etsap ot tpircs a deraperp evah dluohs uoy ,yrotcaFlooT eht esu oT +yrotsih ruoy morf tceles ot ydaer elpmaxe tupni tset llams a dna dnim ni egakcap a evah ro ,xob txet +.tpircs wen ruoy tset ot + +em rof skrow ```atad-tset/yrotcafloot/srekam_loot/sloot/yxalag/~ atad_tset-- yxalag/~ toor_yxalag-- lmx.2yrotcaFlooTgr tset omenalp``` + +uoY .mrof yrotcaF looT eht no egaugnal gnitpircs hcae ni elpmaxe na si erehT +thgir eht tceles ot rebmemer - tuo ti yrt ot eseht etsap dna tuc tsuj nac +gnisu tes atad tset llams a etaerc ot deen osla ll'uoY .esaelp reterpretni +.loot atad wen dda yrotsih yxalaG eht + +ni tuptuo loot eht no nottub "oder" eht esu ,wohemos sliaf tpircs eht fI +gub eht xiF .tpircs nekorb htiw etelpmoc mrof eht etaercer ot yrotsih ruoy +.taeper ,hsaw ,esniR .niaga etucexe dna + +tpircs ruoy snur taht loot yxalaG wen a ,yllufssecus snur tpircs eht ecnO +dna txet pleh emos ylppus dna noitpo "etareneg" eht tceleS .detareneg eb nac +epytatad yxalaG wen a fo mrof eht ni detareneg eb lliw loot wen ehT .seman +a ot daolpu ot ydaer evihcra na s'ti ,stseggus eman eht sa - *zg.dehsloot* +.yrotisoper loot wen a sa dehSlooT yxalaG + +revres yxalaG lacol yna otni dellatsni eb nac ti ,dehSlooT a ni s'ti ecnO +.ecafretni evitartsinimda revres eht morf + +tpircs eht ,emit hcae - ti nur nac sresu lacol ,dellatsni si loot wen eht ecnO +nesohc tupni eht htiw detucexe eb lliw tliub saw ti nehw deilppus saw taht +eht htiw etareneg uoy sloot eht ,sdrow rehto nI .yrotsih s'resu eht morf +.emit yreve tpircs ruoy nur tub,loot yxalaG rehto yna ekil tsuj nur yrotcaFlooT + +,tuptuo eno ,tupni enO .stnenopmoc wolfkrow rof tcefrep era sloot yrotcaf looT +.selbairav on + +,loot siht fo *rewop emosewa eht tiolpxe ylefas dna ylluf oT* +siht gnillatsni repoleved a eb dluohs uoy ,dehSlooT eht dna yxalaG +na era uoy erehw ecnatsni lacol hctarcs/lanosrep/etavirp a no loot +ees seceip eht lla peek ot teg uoy ,ti kaerb uoy fi ,nehT .resu_nimda +emoH/ikiw/yrotcaflootyxalag/rabuf/gro.tekcubtib//:sptth + +**noitallatsnI** +eht gnisu yltneinevnoc tsom ti llatsni nac uoY .loot yxalaG a si sihT +niaM yxalaG eht dniF .knil "sdehs loot esworb dna hcraeS" evitartsinimda +yrotcafloot eht rof hcraes dna /ude.usp.xb.2g.dehsloot//:sptth ta dehsloot +.ti llatsni ot noitpo eht tceles dna edoc eht weiver dna ti nepO .yrotisoper + +eb ot deen ereh selif yp dna lmx eht ,yaw taht loot eht teg t'nac uoy fI +sloot wen a otni deipoc +yrtne wen a sdeen lmx.fnoc_loot ruoY yrotcafloot/sloot sa hcus yrotceridbus +lmx eht ot gnitniop +::ekil gnihtemos - elif + +>"sredliubloot"=di "sloot gnidliub looT"=eman noitces< +>/"lmx.yrotcaFlooTgr/yrotcafloot"=elif loot< +>noitces/< + +,ereht ydaerla ton fI +:dda esaelp +"yraniB:yranib.sepytatad.yxalag"=epyt "zg.dehsloot"=noisnetxe epytatad< +>/ "eurT"=ssalcbus "pizg-x/trapitlum"=epytemim +.lmx.fnoc_sepyt_atad lacol ruoy ot + + +**noitucexe detcirtseR** + +- sresu nimda yb YLNO elbasu eb neht lliw flesti loot yrotcaf loot ehT +YLNO .thgir s'taht ,seY** ini.igsw_esrevinu ni sresu_nimda ni sDI htiw elpoep +ot dewolla fI .tnemom a rof ti tuoba knihT **loot siht nur nac sresu_nimda +dluow taht gniht ylno eht ,revres yxalaG ruoy no tpircs yrartibra yna nur +ylbaborp dluow atad yxalaG ruoy lla gniyortsed no tneb tnaercsim a edepmi +.slliks lacinhcet etairporppa fo kcal eb + +**seod ti tahW** + +dna R ,nohtyp ni stpircs elpmis rof yrotcaf loot a si sihT +.taht si looc woH .detareneg yllacitamotua era stset lanoitcnuF .yltnerruc lrep + +nac yllanoitpO .yrotsih eht morf tupni eno daer taht stpircs elpmis ot DETIMIL +stuptuo fo rebmun yna tcelloc yllanoitpo dna ,tesatad yrotsih wen eno etirw +- etagivan ot resu eht rof egap xedni LMTH detarenegotua na no sknil otni +nwohs era stuptuo fdp - selif tuptuo dna segami setirw tpircs eht fi lufesu +dna taht os tpircstsohg htiw knurhs era s'fdp detaolb s'R dna slianbmuht sa +.elbaliava eb ot deen kigamegami + +trats os ,loot yxalaG yna ekil decnahne dna detide eb nac sloot detareneG +a ot pu gel suoires a uoy steg tpircs detareneg a ecnis pu dliub dna llams +.eno xelpmoc erom + +**od uoy tahW** + +dna srorre xatnys eht xif uoy ,tpircs ruoy nur dna etsap uoY +erofeb tpircs eht tide dna nottub oder eht esu nac uoY .snur ti yllautneve +.llew ytterp skrow ti - gubed uoy sa ti nurer ot gniyrt + +elbitapmoc dehsloot a etareneg nac uoy ,atad tset emos no skrow tpircs eht ecnO +ni loot yxalaG yranidro na sa nur ot ydaer tpircs ruoy gniniatnoc elif pizg +detamotua ylegral dna efas snaem tahT .dehsloot lacol ruoy no yrotisoper a +.dehsloot ruoy esu ot derugifnoc yxalaG noitcudorp yna ni noitallatsni + +**ytiruceS loot detareneG** + +tsuj s'ti ,loot detareneg a llatsni uoy ecnO +rieht dna yllamron nur tsuj yehT .efas si tpircs eht gnimussa - loot rehtona +.dehsloot efas ecitcarp ,esaelp tub erucesni yllausunu gnihtyna od tonnac resu +.yracs yllaer si ti - eno siht yllaicepsE .loot yna llatsni uoy erofeb edoc eht daeR + +**edoC dneS** + +?esaelp seussi tekcubtib sa emoclew snoitseggus dna sehctaP + +**noitubirttA** + +yrotcaF looT yxalaG ehT :stpircs morf sloot elbasu-er gnitaerC +maeT yxalaG ehT ;nnameiZ kraM ;ipsaK ynotnA ;surazaL ssoR +375stb/scitamrofnioib/3901.01 :iod ;2102 scitamrofnioiB + +fer=epytyek&JWYdwMrWs1hQzcl=yekji?375stb/tnirper/igc/gro.slanruojdrofxo.scitamrofnioib//:ptth + +**gnisneciL** + +0102 surazaL ssoR thgirypoC +moc doirep liam g ta surazal ssor + +.devreser sthgir llA + +LPGL eht rednu desneciL + +**tohsneercs yrotagilbO** + +gnp.looTtpircScimanyd/segami/989ef2308adf/crs/rekamlootyxalag/rabuf/gro.tekcubtib//:ptth
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/toolfactory/test-data/pyrevpos.python Mon May 24 02:37:52 2021 +0000 @@ -0,0 +1,13 @@ +# reverse order of text by row +import sys +inp = sys.argv[1] +outp = sys.argv[2] +i = open(inp,'r').readlines() +o = open(outp,'w') +for row in i: + rs = row.rstrip() + rs = list(rs) + rs.reverse() + o.write(''.join(rs)) +o.close() +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/toolfactory/test-data/test1_log.txt Mon May 24 02:37:52 2021 +0000 @@ -0,0 +1,1 @@ +## Executing Toolfactory generated command line = python /tmp/pyrevposq5dmcdy1.python /tmp/tmpqrksf8sd/files/5/b/9/dataset_5b952a86-87df-44ad-a415-ea549f3f0cee.dat output2