|
| 1 | +#!/usr/bin/env python |
| 2 | +'''Tool to install tool dependencies on a Galaxy instance.''' |
| 3 | +import argparse |
| 4 | +import os |
| 5 | +import xml.etree.ElementTree as ET |
| 6 | + |
| 7 | +import yaml |
| 8 | +from bioblend.galaxy.tools import ToolClient |
| 9 | + |
| 10 | +from ephemeris import get_galaxy_connection |
| 11 | +from ephemeris.common_parser import get_common_args |
| 12 | + |
| 13 | + |
| 14 | +def _parser(): |
| 15 | + parent = get_common_args() |
| 16 | + parser = argparse.ArgumentParser(parents=[parent]) |
| 17 | + parser.add_argument("-t", "--tool", help='Path to a tool file, tool_conf file, or yaml file containing sequence of tool ids', nargs='*') |
| 18 | + parser.add_argument("-i", "--id", help='Comma seperated list of tool ids', nargs='*') |
| 19 | + |
| 20 | + return parser |
| 21 | + |
| 22 | + |
| 23 | +def main(): |
| 24 | + """ |
| 25 | + This script uses bioblend to trigger dependencies installations for the provided tools |
| 26 | + """ |
| 27 | + args = _parser().parse_args() |
| 28 | + gi = get_galaxy_connection(args) |
| 29 | + tool_client = ToolClient(gi) |
| 30 | + |
| 31 | + for tool_conf_path in args.tool: # type: str |
| 32 | + _, ext = os.path.splitext(tool_conf_path) |
| 33 | + if (ext == '.xml'): |
| 34 | + # install all |
| 35 | + root = ET.ElementTree(file=tool_conf_path).getroot() |
| 36 | + if root.tag == "toolbox": |
| 37 | + # Install all from tool_conf |
| 38 | + tool_path = root.get('tool_path', '') |
| 39 | + tool_path.replace('${tool_conf_dir}', os.path.abspath(args.tool)) |
| 40 | + for tool in root.findall("tool[@file]"): |
| 41 | + tool_id = ET.ElementTree(file=tool.get('file')).getroot().get('id') |
| 42 | + if tool_id: |
| 43 | + tool_client.install_dependencies(tool_id) |
| 44 | + elif root.tag == "tool" and root.get('id'): |
| 45 | + # Install from single tool file |
| 46 | + tool_client.install_dependencies(root.get('id')) |
| 47 | + else: |
| 48 | + for tool_id in yaml.safe_load(tool_conf_path): |
| 49 | + # Install from yaml file |
| 50 | + tool_client.install_dependencies(tool_id) |
| 51 | + |
| 52 | + for tool_id in args.id: # type: str |
| 53 | + tool_client.install_dependencies(tool_id.strip()) |
| 54 | + |
| 55 | + |
| 56 | +if __name__ == '__main__': |
| 57 | + main() |
0 commit comments