Exemple #1
0
def list_tool_panel(context,galaxy,name,list_tools):
    """
    List tool panel contents.

    Prints details of tool panel sections including the
    displayed text and the internal section id, and any
    tools available outside of any section.
    """
    # Get a Galaxy instance
    gi = context.galaxy_instance(galaxy)
    if gi is None:
        logger.critical("Failed to connect to Galaxy instance")
        return 1
    # List tool panel contents
    tools.list_tool_panel(gi,name=name,
                          list_tools=list_tools)
Exemple #2
0
def manage_tools(args=None):
    """
    Implements the 'manage_tools' utility

    """
    deprecation_warning()
    if args is None:
        args = sys.argv[1:]

    p = base_parser(usage=\
                    "\n\t%prog list GALAXY_URL [options]"
                    "\n\t%prog installed GALAXY_URL [options]"
                    "\n\t%prog tool_panel GALAXY_URL [options]"
                    "\n\t%prog install GALAXY_URL [options] SHED OWNER TOOL [REVISION]"
                    "\n\t%prog update GALAXY_URL [options] SHED OWNER TOOL",
                    description="Manage and install tools in a Galaxy "
                    "instance")
    
    commands = ['list','installed','tool_panel','install','update']

    # Get compulsory arguments
    if len(args) == 1:
        if args[0] == '-h' or args[0] == '--help':
            p.print_usage()
        elif args[0] == '--version':
            p.print_version()
        sys.exit(0)
    if len(args) < 2:
        p.error("need to supply a command and a Galaxy URL/alias")
    command = args[0]
    galaxy_url = args[1]

    # Setup additional command line options
    if command not in commands:
        p.error("unrecognised command: '%s'" % command)
    elif command == 'list':
        p.set_usage("%prog list GALAXY_URL [options]")
        p.add_option('--name',action='store',dest='name',default=None,
                     help="specific tool name(s) to list")
        p.add_option('--installed',action='store_true',
                     dest='installed_only',default=False,
                     help="only list tools installed from a toolshed")
    elif command == 'installed':
        p.set_usage("%prog installed GALAXY_URL [options]")
        p.add_option('--name',action='store',dest='name',default=None,
                     help="specific tool repository/ies to list")
        p.add_option('--toolshed',action='store',dest='toolshed',default=None,
                     help="only list repositories from TOOLSHED")
        p.add_option('--owner',action='store',dest='owner',default=None,
                     help="only list repositories owned by OWNER")
        p.add_option('--list-tools',action='store_true',dest='list_tools',
                     default=None,
                     help="list the associated tools for each repository")
        p.add_option('--updateable',action='store_true',dest='updateable',
                     default=None,
                     help="only show repositories with uninstalled updates "
                     "or upgrades")
    elif command == 'tool_panel':
        p.set_usage("%prog tool_panel GALAXY_URL [options]")
        p.add_option('--name',action='store',dest='name',default=None,
                     help="specific tool panel section(s) to list")
        p.add_option('--list-tools',action='store_true',dest='list_tools',
                     default=None,
                     help="list the associated tools for each section")
    elif command == 'install':
        p.set_usage("%prog install GALAXY_URL [options] SHED OWNER TOOL "
                    "[REVISION]")
        p.add_option('--tool-panel-section',action='store',
                     dest='tool_panel_section',default=None,
                     help="tool panel section name or id to install the "
                     "tool under")
    elif command == 'update':
        p.set_usage("%prog update GALAXY_URL [options] SHED OWNER TOOL")

    # Process remaining arguments on command line
    if args[1] in ('-h','--help','--version'):
        args = args[1:]
    else:
        args = args[2:]
    options,args = p.parse_args(args)
    handle_debug(debug=options.debug)
    handle_suppress_warnings(suppress_warnings=options.suppress_warnings)
    handle_ssl_warnings(verify=(not options.no_verify))

    # Handle password if required
    email,password = handle_credentials(options.username,
                                        options.galaxy_password,
                                        prompt="Password for %s: " % galaxy_url)

    # Get a Galaxy instance
    gi = get_galaxy_instance(galaxy_url,api_key=options.api_key,
                             email=email,password=password,
                             verify_ssl=(not options.no_verify))
    if gi is None:
        logger.critical("Failed to connect to Galaxy instance")
        sys.exit(1)

    # Execute command
    if command == 'list':
        tools.list_tools(gi,name=options.name,
                         installed_only=options.installed_only)
    elif command == 'installed':
        tools.list_installed_repositories(gi,name=options.name,
                                          toolshed=options.toolshed,
                                          owner=options.owner,
                                          list_tools=options.list_tools,
                                          only_updateable=options.updateable)
    elif command == 'tool_panel':
        tools.list_tool_panel(gi,name=options.name,
                              list_tools=options.list_tools)
    elif command == 'install':
        if len(args) < 3:
            p.error("Need to supply toolshed, owner, repo and optional "
                    "revision")
        toolshed,owner,repo = args[:3]
        if len(args) == 4:
            revision = args[3]
        else:
            revision = None
        status = tools.install_tool(
            gi,toolshed,repo,owner,revision=revision,
            tool_panel_section=options.tool_panel_section)
        sys.exit(status)
    elif command == 'update':
        if len(args) != 3:
            p.error("Need to supply toolshed, owner and repo")
        toolshed,owner,repo = args[:3]
        status = tools.update_tool(gi,toolshed,repo,owner)
        sys.exit(status)