Beispiel #1
0
def handle_tool_dependencies( app, tool_shed_repository, tool_dependencies_config, tool_dependencies ):
    """
    Install and build tool dependencies defined in the tool_dependencies_config.  This config's tag sets can currently refer to installation
    methods in Galaxy's tool_dependencies module.  In the future, proprietary fabric scripts contained in the repository will be supported.
    Future enhancements to handling tool dependencies may provide installation processes in addition to fabric based processes.  The dependencies
    will be installed in:
    ~/<app.config.tool_dependency_dir>/<package_name>/<package_version>/<repo_owner>/<repo_name>/<repo_installed_changeset_revision>
    """
    sa_session = app.model.context.current
    installed_tool_dependencies = []
    # Parse the tool_dependencies.xml config.
    tree, error_message = xml_util.parse_xml( tool_dependencies_config )
    if tree is None:
        return installed_tool_dependencies
    root = tree.getroot()
    fabric_version_checked = False
    for elem in root:
        if elem.tag == 'package':
            # Only install the tool_dependency if it is not already installed.
            package_name = elem.get( 'name', None )
            package_version = elem.get( 'version', None )
            if package_name and package_version:
                for tool_dependency in tool_dependencies:
                    if tool_dependency.name==package_name and tool_dependency.version==package_version:
                        break
                if tool_dependency.can_install:
                    try:
                        tool_dependency = install_package( app, elem, tool_shed_repository, tool_dependencies=tool_dependencies )
                    except Exception, e:
                        error_message = "Error installing tool dependency %s version %s: %s" % ( str( package_name ), str( package_version ), str( e ) )
                        log.debug( error_message )
                        if tool_dependency:
                            tool_dependency.status = app.model.ToolDependency.installation_status.ERROR
                            tool_dependency.error_message = error_message
                            sa_session.add( tool_dependency )
                            sa_session.flush()
                    if tool_dependency and tool_dependency.status in [ app.model.ToolDependency.installation_status.INSTALLED,
                                                                       app.model.ToolDependency.installation_status.ERROR ]:
                        installed_tool_dependencies.append( tool_dependency )
        elif elem.tag == 'set_environment':
            try:
                tool_dependency = set_environment( app, elem, tool_shed_repository )
            except Exception, e:
                error_message = "Error setting environment for tool dependency: %s" % str( e )
                log.debug( error_message )
                if tool_dependency:
                    tool_dependency.status = app.model.ToolDependency.installation_status.ERROR
                    tool_dependency.error_message = error_message
                    sa_session.add( tool_dependency )
                    sa_session.flush()
                                # be left False here.
                                tool_dependency = tool_dependency_util.handle_tool_dependency_installation_error( app, 
                                                                                                                  tool_dependency, 
                                                                                                                  error_message, 
                                                                                                                  remove_installation_path=False )
                        if tool_dependency and tool_dependency.status in [ app.install_model.ToolDependency.installation_status.INSTALLED,
                                                                           app.install_model.ToolDependency.installation_status.ERROR ]:
                            installed_tool_dependencies.append( tool_dependency )
                            # Add the tool_dependency to the in-memory dictionaries in the installed_repository_manager.
                            app.installed_repository_manager.handle_tool_dependency_install( tool_shed_repository, tool_dependency )
        elif elem.tag == 'set_environment':
            # <set_environment version="1.0">
            #    <environment_variable name="R_SCRIPT_PATH"action="set_to">$REPOSITORY_INSTALL_DIR</environment_variable>
            # </set_environment>
            try:
                tool_dependency = set_environment( app, elem, tool_shed_repository, attr_tups_of_dependencies_for_install )
            except Exception, e:
                error_message = "Error setting environment for tool dependency: %s" % str( e )
                log.debug( error_message )
                if tool_dependency:
                    # Since there was an installation error, update the tool dependency status to Error. The remove_installation_path option must
                    # be left False here.
                    tool_dependency = tool_dependency_util.handle_tool_dependency_installation_error( app, 
                                                                                                      tool_dependency, 
                                                                                                      error_message, 
                                                                                                      remove_installation_path=False )
            if tool_dependency and tool_dependency.status in [ app.install_model.ToolDependency.installation_status.INSTALLED,
                                                               app.install_model.ToolDependency.installation_status.ERROR ]:
                installed_tool_dependencies.append( tool_dependency )
    return installed_tool_dependencies