def get_latest_installable_revision( self, trans, payload, **kwd ):
        """
        POST /api/tool_shed_repositories/get_latest_installable_revision
        Get the latest installable revision of a specified repository from a specified Tool Shed.

        :param key: the current Galaxy admin user's API key

        The following parameters are included in the payload.
        :param tool_shed_url (required): the base URL of the Tool Shed from which to retrieve the Repository revision.
        :param name (required): the name of the Repository
        :param owner (required): the owner of the Repository
        """
        # Get the information about the repository to be installed from the payload.
        tool_shed_url, name, owner = self.__parse_repository_from_payload( payload )
        # Make sure the current user's API key proves he is an admin user in this Galaxy instance.
        if not trans.user_is_admin():
            raise exceptions.AdminRequiredException( 'You are not authorized to request the latest installable revision for a repository in this Galaxy instance.' )
        params = dict(name=name, owner=owner)
        pathspec = ['api', 'repositories', 'get_ordered_installable_revisions']
        try:
            raw_text = common_util.tool_shed_get( trans.app, tool_shed_url, pathspec, params )
        except Exception, e:
            message = "Error attempting to retrieve the latest installable revision from tool shed %s for repository %s owned by %s: %s" % \
                ( str( tool_shed_url ), str( name ), str( owner ), str( e ) )
            log.debug( message )
            return dict( status='error', error=message )
示例#2
0
文件: admin.py 项目: mvollger/galaxy
 def check_for_tool_dependencies( self, trans, migration_stage ):
     # Get the 000x_tools.xml file associated with migration_stage.
     tools_xml_file_path = os.path.abspath( os.path.join( trans.app.config.root, 'scripts', 'migrate_tools', '%04d_tools.xml' % migration_stage ) )
     tree = galaxy.util.parse_xml( tools_xml_file_path )
     root = tree.getroot()
     tool_shed = root.get( 'name' )
     tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( trans.app, tool_shed )
     repo_name_dependency_tups = []
     if tool_shed_url:
         for elem in root:
             if elem.tag == 'repository':
                 tool_dependencies = []
                 tool_dependencies_dict = {}
                 repository_name = elem.get( 'name' )
                 changeset_revision = elem.get( 'changeset_revision' )
                 url = '%s/repository/get_tool_dependencies?name=%s&owner=devteam&changeset_revision=%s' % \
                     ( tool_shed_url, repository_name, changeset_revision )
                 text = common_util.tool_shed_get( trans.app, tool_shed_url, url )
                 if text:
                     tool_dependencies_dict = encoding_util.tool_shed_decode( text )
                     for dependency_key, requirements_dict in tool_dependencies_dict.items():
                         tool_dependency_name = requirements_dict[ 'name' ]
                         tool_dependency_version = requirements_dict[ 'version' ]
                         tool_dependency_type = requirements_dict[ 'type' ]
                         tool_dependency_readme = requirements_dict.get( 'readme', '' )
                         tool_dependencies.append( ( tool_dependency_name, tool_dependency_version, tool_dependency_type, tool_dependency_readme ) )
                 repo_name_dependency_tups.append( ( repository_name, tool_dependencies ) )
     return repo_name_dependency_tups
示例#3
0
 def create_temporary_tool_dependencies_config( self, tool_shed_url, name, owner, changeset_revision ):
     """Make a call to the tool shed to get the required repository's tool_dependencies.xml file."""
     tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( self.app, tool_shed_url )
     if tool_shed_url is None or name is None or owner is None or changeset_revision is None:
         message = "Unable to retrieve required tool_dependencies.xml file from the Tool Shed because one or more of the "
         message += "following required parameters is None: tool_shed_url: %s, name: %s, owner: %s, changeset_revision: %s " % \
             ( str( tool_shed_url ), str( name ), str( owner ), str( changeset_revision ) )
         raise Exception( message )
     params = dict( name=name,
                    owner=owner,
                    changeset_revision=changeset_revision )
     pathspec = [ 'repository', 'get_tool_dependencies_config_contents' ]
     text = common_util.tool_shed_get( self.app, tool_shed_url, pathspec=pathspec, params=params )
     if text:
         # Write the contents to a temporary file on disk so it can be reloaded and parsed.
         fh = tempfile.NamedTemporaryFile( 'wb', prefix="tmp-toolshed-cttdc"  )
         tmp_filename = fh.name
         fh.close()
         fh = open( tmp_filename, 'wb' )
         fh.write( text )
         fh.close()
         return tmp_filename
     else:
         message = "Unable to retrieve required tool_dependencies.xml file from the Tool Shed for revision "
         message += "%s of installed repository %s owned by %s." % ( str( changeset_revision ), str( name ), str( owner ) )
         raise Exception( message )
         return None
示例#4
0
 def create_temporary_tool_dependencies_config(self, tool_shed_url, name,
                                               owner, changeset_revision):
     """Make a call to the tool shed to get the required repository's tool_dependencies.xml file."""
     tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(
         self.app, tool_shed_url)
     if tool_shed_url is None or name is None or owner is None or changeset_revision is None:
         message = "Unable to retrieve required tool_dependencies.xml file from the Tool Shed because one or more of the "
         message += "following required parameters is None: tool_shed_url: %s, name: %s, owner: %s, changeset_revision: %s " % \
             ( str( tool_shed_url ), str( name ), str( owner ), str( changeset_revision ) )
         raise Exception(message)
     params = dict(name=name,
                   owner=owner,
                   changeset_revision=changeset_revision)
     pathspec = ['repository', 'get_tool_dependencies_config_contents']
     text = common_util.tool_shed_get(self.app,
                                      tool_shed_url,
                                      pathspec=pathspec,
                                      params=params)
     if text:
         # Write the contents to a temporary file on disk so it can be reloaded and parsed.
         fh = tempfile.NamedTemporaryFile('wb', prefix="tmp-toolshed-cttdc")
         tmp_filename = fh.name
         fh.close()
         fh = open(tmp_filename, 'wb')
         fh.write(text)
         fh.close()
         return tmp_filename
     else:
         message = "Unable to retrieve required tool_dependencies.xml file from the Tool Shed for revision "
         message += "%s of installed repository %s owned by %s." % (
             str(changeset_revision), str(name), str(owner))
         raise Exception(message)
         return None
    def get_latest_installable_revision(self, trans, payload, **kwd):
        """
        POST /api/tool_shed_repositories/get_latest_installable_revision
        Get the latest installable revision of a specified repository from a specified Tool Shed.

        :param key: the current Galaxy admin user's API key

        The following parameters are included in the payload.
        :param tool_shed_url (required): the base URL of the Tool Shed from which to retrieve the Repository revision.
        :param name (required): the name of the Repository
        :param owner (required): the owner of the Repository
        """
        # Get the information about the repository to be installed from the payload.
        tool_shed_url, name, owner = self.__parse_repository_from_payload(
            payload)
        # Make sure the current user's API key proves he is an admin user in this Galaxy instance.
        if not trans.user_is_admin():
            raise exceptions.AdminRequiredException(
                'You are not authorized to request the latest installable revision for a repository in this Galaxy instance.'
            )
        params = '?name=%s&owner=%s' % (name, owner)
        url = common_util.url_join(
            tool_shed_url,
            'api/repositories/get_ordered_installable_revisions%s' % params)
        try:
            raw_text = common_util.tool_shed_get(trans.app, tool_shed_url, url)
        except Exception, e:
            message = "Error attempting to retrieve the latest installable revision from tool shed %s for repository %s owned by %s: %s" % \
                ( str( tool_shed_url ), str( name ), str( owner ), str( e ) )
            log.debug(message)
            return dict(status='error', error=message)
 def check_for_tool_dependencies( self, trans, migration_stage ):
     # Get the 000x_tools.xml file associated with migration_stage.
     tools_xml_file_path = os.path.abspath( os.path.join( trans.app.config.root, 'scripts', 'migrate_tools', '%04d_tools.xml' % migration_stage ) )
     tree = galaxy.util.parse_xml( tools_xml_file_path )
     root = tree.getroot()
     tool_shed = root.get( 'name' )
     tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( trans.app, tool_shed )
     repo_name_dependency_tups = []
     if tool_shed_url:
         for elem in root:
             if elem.tag == 'repository':
                 tool_dependencies = []
                 tool_dependencies_dict = {}
                 repository_name = elem.get( 'name' )
                 changeset_revision = elem.get( 'changeset_revision' )
                 params = dict( name=repository_name, owner='devteam', changeset_revision=changeset_revision )
                 pathspec = [ 'repository', 'get_tool_dependencies' ]
                 text = common_util.tool_shed_get( trans.app, tool_shed_url, pathspec=pathspec, params=params )
                 if text:
                     tool_dependencies_dict = encoding_util.tool_shed_decode( text )
                     for dependency_key, requirements_dict in tool_dependencies_dict.items():
                         tool_dependency_name = requirements_dict[ 'name' ]
                         tool_dependency_version = requirements_dict[ 'version' ]
                         tool_dependency_type = requirements_dict[ 'type' ]
                         tool_dependency_readme = requirements_dict.get( 'readme', '' )
                         tool_dependencies.append( ( tool_dependency_name, tool_dependency_version, tool_dependency_type, tool_dependency_readme ) )
                 repo_name_dependency_tups.append( ( repository_name, tool_dependencies ) )
     return repo_name_dependency_tups
示例#7
0
def get_updated_changeset_revisions_from_tool_shed( app, tool_shed_url, name, owner, changeset_revision ):
    """
    Get all appropriate newer changeset revisions for the repository defined by 
    the received tool_shed_url / name / owner combination.
    """
    url = suc.url_join( tool_shed_url,
                        'repository/updated_changeset_revisions?name=%s&owner=%s&changeset_revision=%s' % ( name, owner, changeset_revision ) )
    text = cu.tool_shed_get( app, tool_shed_url, url )
    return text
示例#8
0
 def check_for_update( self, repository ):
     tool_shed_url = suc.get_url_from_tool_shed( self.app, repository.tool_shed )
     url = '%s/repository/check_for_updates?name=%s&owner=%s&changeset_revision=%s&from_update_manager=True' % \
         ( tool_shed_url, repository.name, repository.owner, repository.changeset_revision )
     try:
         text = common_util.tool_shed_get( self.app, tool_shed_url, url )
     except Exception, e:
         # The required tool shed may be unavailable.
         text = 'False'
示例#9
0
 def check_for_update(self, repository):
     tool_shed_url = suc.get_url_from_tool_shed(self.app,
                                                repository.tool_shed)
     url = '%s/repository/check_for_updates?name=%s&owner=%s&changeset_revision=%s&from_update_manager=True' % \
         ( tool_shed_url, repository.name, repository.owner, repository.changeset_revision )
     try:
         text = common_util.tool_shed_get(self.app, tool_shed_url, url)
     except Exception, e:
         # The required tool shed may be unavailable.
         text = 'False'
示例#10
0
def get_updated_changeset_revisions_from_tool_shed(app, tool_shed_url, name,
                                                   owner, changeset_revision):
    """
    Get all appropriate newer changeset revisions for the repository defined by 
    the received tool_shed_url / name / owner combination.
    """
    url = suc.url_join(
        tool_shed_url,
        'repository/updated_changeset_revisions?name=%s&owner=%s&changeset_revision=%s'
        % (name, owner, changeset_revision))
    text = cu.tool_shed_get(app, tool_shed_url, url)
    return text
示例#11
0
def get_readme_files_dict_for_display( trans, tool_shed_url, repo_info_dict ):
    """
    Return a dictionary of README files contained in the single repository being installed so they can be displayed on the tool panel section 
    selection page.
    """
    name = repo_info_dict.keys()[ 0 ]
    repo_info_tuple = repo_info_dict[ name ]
    description, repository_clone_url, changeset_revision, ctx_rev, repository_owner, repository_dependencies, installed_td = \
        suc.get_repo_info_tuple_contents( repo_info_tuple )
    # Handle README files.
    url = suc.url_join( tool_shed_url,
                       'repository/get_readme_files?name=%s&owner=%s&changeset_revision=%s' % ( name, repository_owner, changeset_revision ) )
    raw_text = common_util.tool_shed_get( trans.app, tool_shed_url, url )
    readme_files_dict = json.from_json_string( raw_text )
    return readme_files_dict
 def get_repository_dependencies_for_installed_tool_shed_repository( self, app, repository ):
     """
     Send a request to the appropriate tool shed to retrieve the dictionary of repository dependencies defined
     for the received repository which is installed into Galaxy.  This method is called only from Galaxy.
     """
     tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( app, str( repository.tool_shed ) )
     params = dict( name=str( repository.name ),
                    owner=str( repository.owner ),
                    changeset_revision=str( repository.changeset_revision ) )
     pathspec = [ 'repository', 'get_repository_dependencies' ]
     try:
         raw_text = common_util.tool_shed_get( app, tool_shed_url, pathspec=pathspec, params=params )
     except Exception, e:
         print "The URL\n%s\nraised the exception:\n%s\n" % ( common_util.url_join( tool_shed_url, pathspec=pathspec, params=params ), str( e ) )
         return ''
 def get_repository_dependencies_for_installed_tool_shed_repository( self, app, repository ):
     """
     Send a request to the appropriate tool shed to retrieve the dictionary of repository dependencies defined
     for the received repository which is installed into Galaxy.  This method is called only from Galaxy.
     """
     tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( app, str( repository.tool_shed ) )
     params = dict( name=str( repository.name ),
                    owner=str( repository.owner ),
                    changeset_revision=str( repository.changeset_revision ) )
     pathspec = [ 'repository', 'get_repository_dependencies' ]
     try:
         raw_text = common_util.tool_shed_get( app, tool_shed_url, pathspec=pathspec, params=params )
     except Exception, e:
         log.error("The URL\n%s\nraised the exception:\n%s\n", common_util.url_join( tool_shed_url, pathspec=pathspec, params=params ), str( e ) )
         return ''
 def get_repository_dependencies_for_installed_tool_shed_repository( self, app, repository ):
     """
     Send a request to the appropriate tool shed to retrieve the dictionary of repository dependencies defined
     for the received repository which is installed into Galaxy.  This method is called only from Galaxy.
     """
     tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( app, str( repository.tool_shed ) )
     params = '?name=%s&owner=%s&changeset_revision=%s' % ( str( repository.name ),
                                                            str( repository.owner ),
                                                            str( repository.changeset_revision ) )
     url = common_util.url_join( tool_shed_url,
                                 'repository/get_repository_dependencies%s' % params )
     try:
         raw_text = common_util.tool_shed_get( app, tool_shed_url, url )
     except Exception, e:
         print "The URL\n%s\nraised the exception:\n%s\n" % ( url, str( e ) )
         return ''
示例#15
0
def get_readme_files_dict_for_display( app, tool_shed_url, repo_info_dict ):
    """
    Return a dictionary of README files contained in the single repository being installed so they can be displayed on the tool panel section
    selection page.
    """
    name = repo_info_dict.keys()[ 0 ]
    repo_info_tuple = repo_info_dict[ name ]
    description, repository_clone_url, changeset_revision, ctx_rev, repository_owner, repository_dependencies, installed_td = \
        suc.get_repo_info_tuple_contents( repo_info_tuple )
    # Handle changing HTTP protocols over time.
    tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( app, tool_shed_url )
    params = dict( name=name, owner=repository_owner, changeset_revision=changeset_revision )
    pathspec = [ 'repository', 'get_readme_files' ]
    raw_text = common_util.tool_shed_get( app, tool_shed_url, pathspec=pathspec, params=params )
    readme_files_dict = json.loads( raw_text )
    return readme_files_dict
示例#16
0
def get_readme_files_dict_for_display( app, tool_shed_url, repo_info_dict ):
    """
    Return a dictionary of README files contained in the single repository being installed so they can be displayed on the tool panel section
    selection page.
    """
    name = repo_info_dict.keys()[ 0 ]
    repo_info_tuple = repo_info_dict[ name ]
    description, repository_clone_url, changeset_revision, ctx_rev, repository_owner, repository_dependencies, installed_td = \
        suc.get_repo_info_tuple_contents( repo_info_tuple )
    # Handle changing HTTP protocols over time.
    tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( app, tool_shed_url )
    params = '?name=%s&owner=%s&changeset_revision=%s' % ( name, repository_owner, changeset_revision )
    url = common_util.url_join( tool_shed_url,
                                'repository/get_readme_files%s' % params )
    raw_text = common_util.tool_shed_get( app, tool_shed_url, url )
    readme_files_dict = json.from_json_string( raw_text )
    return readme_files_dict
 def get_update_to_changeset_revision_and_ctx_rev( self, repository ):
     """Return the changeset revision hash to which the repository can be updated."""
     changeset_revision_dict = {}
     tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( self.app, str( repository.tool_shed ) )
     params = '?name=%s&owner=%s&changeset_revision=%s' % ( str( repository.name ),
                                                            str( repository.owner ),
                                                            str( repository.installed_changeset_revision ) )
     url = common_util.url_join( tool_shed_url, 'repository/get_changeset_revision_and_ctx_rev%s' % params )
     try:
         encoded_update_dict = common_util.tool_shed_get( self.app, tool_shed_url, url )
         if encoded_update_dict:
             update_dict = encoding_util.tool_shed_decode( encoded_update_dict )
             includes_data_managers = update_dict.get( 'includes_data_managers', False )
             includes_datatypes = update_dict.get( 'includes_datatypes', False )
             includes_tools = update_dict.get( 'includes_tools', False )
             includes_tools_for_display_in_tool_panel = update_dict.get( 'includes_tools_for_display_in_tool_panel', False )
             includes_tool_dependencies = update_dict.get( 'includes_tool_dependencies', False )
             includes_workflows = update_dict.get( 'includes_workflows', False )
             has_repository_dependencies = update_dict.get( 'has_repository_dependencies', False )
             has_repository_dependencies_only_if_compiling_contained_td = update_dict.get( 'has_repository_dependencies_only_if_compiling_contained_td', False )
             changeset_revision = update_dict.get( 'changeset_revision', None )
             ctx_rev = update_dict.get( 'ctx_rev', None )
         changeset_revision_dict[ 'includes_data_managers' ] = includes_data_managers
         changeset_revision_dict[ 'includes_datatypes' ] = includes_datatypes
         changeset_revision_dict[ 'includes_tools' ] = includes_tools
         changeset_revision_dict[ 'includes_tools_for_display_in_tool_panel' ] = includes_tools_for_display_in_tool_panel
         changeset_revision_dict[ 'includes_tool_dependencies' ] = includes_tool_dependencies
         changeset_revision_dict[ 'includes_workflows' ] = includes_workflows
         changeset_revision_dict[ 'has_repository_dependencies' ] = has_repository_dependencies
         changeset_revision_dict[ 'has_repository_dependencies_only_if_compiling_contained_td' ] = has_repository_dependencies_only_if_compiling_contained_td
         changeset_revision_dict[ 'changeset_revision' ] = changeset_revision
         changeset_revision_dict[ 'ctx_rev' ] = ctx_rev
     except Exception, e:
         log.debug( "Error getting change set revision for update from the tool shed for repository '%s': %s" % ( repository.name, str( e ) ) )
         changeset_revision_dict[ 'includes_data_managers' ] = False
         changeset_revision_dict[ 'includes_datatypes' ] = False
         changeset_revision_dict[ 'includes_tools' ] = False
         changeset_revision_dict[ 'includes_tools_for_display_in_tool_panel' ] = False
         changeset_revision_dict[ 'includes_tool_dependencies' ] = False
         changeset_revision_dict[ 'includes_workflows' ] = False
         changeset_revision_dict[ 'has_repository_dependencies' ] = False
         changeset_revision_dict[ 'has_repository_dependencies_only_if_compiling_contained_td' ] = False
         changeset_revision_dict[ 'changeset_revision' ] = None
         changeset_revision_dict[ 'ctx_rev' ] = None
示例#18
0
 def get_update_to_changeset_revision_and_ctx_rev( self, repository ):
     """Return the changeset revision hash to which the repository can be updated."""
     changeset_revision_dict = {}
     tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( self.app, str( repository.tool_shed ) )
     params = dict( name=str( repository.name ),
                    owner=str( repository.owner ),
                    changeset_revision=str( repository.installed_changeset_revision ) )
     pathspec = [ 'repository', 'get_changeset_revision_and_ctx_rev' ]
     try:
         encoded_update_dict = common_util.tool_shed_get( self.app, tool_shed_url, pathspec=pathspec, params=params )
         if encoded_update_dict:
             update_dict = encoding_util.tool_shed_decode( encoded_update_dict )
             includes_data_managers = update_dict.get( 'includes_data_managers', False )
             includes_datatypes = update_dict.get( 'includes_datatypes', False )
             includes_tools = update_dict.get( 'includes_tools', False )
             includes_tools_for_display_in_tool_panel = update_dict.get( 'includes_tools_for_display_in_tool_panel', False )
             includes_tool_dependencies = update_dict.get( 'includes_tool_dependencies', False )
             includes_workflows = update_dict.get( 'includes_workflows', False )
             has_repository_dependencies = update_dict.get( 'has_repository_dependencies', False )
             has_repository_dependencies_only_if_compiling_contained_td = update_dict.get( 'has_repository_dependencies_only_if_compiling_contained_td', False )
             changeset_revision = update_dict.get( 'changeset_revision', None )
             ctx_rev = update_dict.get( 'ctx_rev', None )
         changeset_revision_dict[ 'includes_data_managers' ] = includes_data_managers
         changeset_revision_dict[ 'includes_datatypes' ] = includes_datatypes
         changeset_revision_dict[ 'includes_tools' ] = includes_tools
         changeset_revision_dict[ 'includes_tools_for_display_in_tool_panel' ] = includes_tools_for_display_in_tool_panel
         changeset_revision_dict[ 'includes_tool_dependencies' ] = includes_tool_dependencies
         changeset_revision_dict[ 'includes_workflows' ] = includes_workflows
         changeset_revision_dict[ 'has_repository_dependencies' ] = has_repository_dependencies
         changeset_revision_dict[ 'has_repository_dependencies_only_if_compiling_contained_td' ] = has_repository_dependencies_only_if_compiling_contained_td
         changeset_revision_dict[ 'changeset_revision' ] = changeset_revision
         changeset_revision_dict[ 'ctx_rev' ] = ctx_rev
     except Exception, e:
         log.debug( "Error getting change set revision for update from the tool shed for repository '%s': %s" % ( repository.name, str( e ) ) )
         changeset_revision_dict[ 'includes_data_managers' ] = False
         changeset_revision_dict[ 'includes_datatypes' ] = False
         changeset_revision_dict[ 'includes_tools' ] = False
         changeset_revision_dict[ 'includes_tools_for_display_in_tool_panel' ] = False
         changeset_revision_dict[ 'includes_tool_dependencies' ] = False
         changeset_revision_dict[ 'includes_workflows' ] = False
         changeset_revision_dict[ 'has_repository_dependencies' ] = False
         changeset_revision_dict[ 'has_repository_dependencies_only_if_compiling_contained_td' ] = False
         changeset_revision_dict[ 'changeset_revision' ] = None
         changeset_revision_dict[ 'ctx_rev' ] = None
示例#19
0
def create_temporary_tool_dependencies_config( app, tool_shed_url, name, owner, changeset_revision ):
    """Make a call to the tool shed to get the required repository's tool_dependencies.xml file."""
    url = url_join( tool_shed_url,
                    'repository/get_tool_dependencies_config_contents?name=%s&owner=%s&changeset_revision=%s' % ( name, owner, changeset_revision ) )
    text = cu.tool_shed_get( app, tool_shed_url, url )
    if text:
        # Write the contents to a temporary file on disk so it can be reloaded and parsed.
        fh = tempfile.NamedTemporaryFile( 'wb', prefix="tmp-toolshed-cttdc"  )
        tmp_filename = fh.name
        fh.close()
        fh = open( tmp_filename, 'wb' )
        fh.write( text )
        fh.close()
        return tmp_filename
    else:
        message = "Unable to retrieve required tool_dependencies.xml file from the tool shed for revision "
        message += "%s of installed repository %s owned by %s." % ( str( changeset_revision ), str( name ), str( owner ) )
        raise Exception( message )
        return None
示例#20
0
def create_temporary_tool_dependencies_config(app, tool_shed_url, name, owner,
                                              changeset_revision):
    """Make a call to the tool shed to get the required repository's tool_dependencies.xml file."""
    url = url_join(
        tool_shed_url,
        'repository/get_tool_dependencies_config_contents?name=%s&owner=%s&changeset_revision=%s'
        % (name, owner, changeset_revision))
    text = cu.tool_shed_get(app, tool_shed_url, url)
    if text:
        # Write the contents to a temporary file on disk so it can be reloaded and parsed.
        fh = tempfile.NamedTemporaryFile('wb', prefix="tmp-toolshed-cttdc")
        tmp_filename = fh.name
        fh.close()
        fh = open(tmp_filename, 'wb')
        fh.write(text)
        fh.close()
        return tmp_filename
    else:
        message = "Unable to retrieve required tool_dependencies.xml file from the tool shed for revision "
        message += "%s of installed repository %s owned by %s." % (
            str(changeset_revision), str(name), str(owner))
        raise Exception(message)
        return None
示例#21
0
文件: admin.py 项目: NickSto/galaxy
 def check_for_tool_dependencies(self, trans, migration_stage):
     # Get the 000x_tools.xml file associated with migration_stage.
     tools_xml_file_path = os.path.abspath(
         os.path.join(trans.app.config.root, "scripts", "migrate_tools", "%04d_tools.xml" % migration_stage)
     )
     tree = galaxy.util.parse_xml(tools_xml_file_path)
     root = tree.getroot()
     tool_shed = root.get("name")
     tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(trans.app, tool_shed)
     repo_name_dependency_tups = []
     if tool_shed_url:
         for elem in root:
             if elem.tag == "repository":
                 tool_dependencies = []
                 tool_dependencies_dict = {}
                 repository_name = elem.get("name")
                 changeset_revision = elem.get("changeset_revision")
                 params = dict(name=repository_name, owner="devteam", changeset_revision=changeset_revision)
                 pathspec = ["repository", "get_tool_dependencies"]
                 text = common_util.tool_shed_get(trans.app, tool_shed_url, pathspec=pathspec, params=params)
                 if text:
                     tool_dependencies_dict = encoding_util.tool_shed_decode(text)
                     for dependency_key, requirements_dict in tool_dependencies_dict.items():
                         tool_dependency_name = requirements_dict["name"]
                         tool_dependency_version = requirements_dict["version"]
                         tool_dependency_type = requirements_dict["type"]
                         tool_dependency_readme = requirements_dict.get("readme", "")
                         tool_dependencies.append(
                             (
                                 tool_dependency_name,
                                 tool_dependency_version,
                                 tool_dependency_type,
                                 tool_dependency_readme,
                             )
                         )
                 repo_name_dependency_tups.append((repository_name, tool_dependencies))
     return repo_name_dependency_tups
示例#22
0
 def install_repository( self, repository_elem, install_dependencies ):
     # Install a single repository, loading contained tools into the tool panel.
     name = repository_elem.get( 'name' )
     description = repository_elem.get( 'description' )
     installed_changeset_revision = repository_elem.get( 'changeset_revision' )
     # Install path is of the form: <tool path>/<tool shed>/repos/<repository owner>/<repository name>/<installed changeset revision>
     relative_clone_dir = os.path.join( self.tool_shed, 'repos', self.repository_owner, name, installed_changeset_revision )
     clone_dir = os.path.join( self.tool_path, relative_clone_dir )
     if self.__isinstalled( clone_dir ):
         print "Skipping automatic install of repository '", name, "' because it has already been installed in location ", clone_dir
     else:
         tool_shed_url = suc.get_url_from_tool_shed( self.app, self.tool_shed )
         repository_clone_url = os.path.join( tool_shed_url, 'repos', self.repository_owner, name )
         relative_install_dir = os.path.join( relative_clone_dir, name )
         install_dir = os.path.join( clone_dir, name )
         ctx_rev = suc.get_ctx_rev( self.app, tool_shed_url, name, self.repository_owner, installed_changeset_revision )
         tool_shed_repository = suc.create_or_update_tool_shed_repository( app=self.app,
                                                                           name=name,
                                                                           description=description,
                                                                           installed_changeset_revision=installed_changeset_revision,
                                                                           ctx_rev=ctx_rev,
                                                                           repository_clone_url=repository_clone_url,
                                                                           metadata_dict={},
                                                                           status=self.app.model.ToolShedRepository.installation_status.NEW,
                                                                           current_changeset_revision=None,
                                                                           owner=self.repository_owner,
                                                                           dist_to_shed=True )
         suc.update_tool_shed_repository_status( self.app, tool_shed_repository, self.app.model.ToolShedRepository.installation_status.CLONING )
         cloned_ok, error_message = suc.clone_repository( repository_clone_url, os.path.abspath( install_dir ), ctx_rev )
         if cloned_ok:
             self.handle_repository_contents( tool_shed_repository=tool_shed_repository,
                                              repository_clone_url=repository_clone_url,
                                              relative_install_dir=relative_install_dir,
                                              repository_elem=repository_elem,
                                              install_dependencies=install_dependencies )
             self.app.sa_session.refresh( tool_shed_repository )
             metadata_dict = tool_shed_repository.metadata
             if 'tools' in metadata_dict:
                 suc.update_tool_shed_repository_status( self.app,
                                                         tool_shed_repository,
                                                         self.app.model.ToolShedRepository.installation_status.SETTING_TOOL_VERSIONS )
                 # Get the tool_versions from the tool shed for each tool in the installed change set.
                 url = '%s/repository/get_tool_versions?name=%s&owner=%s&changeset_revision=%s' % \
                     ( tool_shed_url, tool_shed_repository.name, self.repository_owner, installed_changeset_revision )
                 text = common_util.tool_shed_get( self.app, tool_shed_url, url )
                 if text:
                     tool_version_dicts = from_json_string( text )
                     tool_util.handle_tool_versions( self.app, tool_version_dicts, tool_shed_repository )
                 else:
                     # Set the tool versions since they seem to be missing for this repository in the tool shed.
                     # CRITICAL NOTE: These default settings may not properly handle all parent/child associations.
                     for tool_dict in metadata_dict[ 'tools' ]:
                         flush_needed = False
                         tool_id = tool_dict[ 'guid' ]
                         old_tool_id = tool_dict[ 'id' ]
                         tool_version = tool_dict[ 'version' ]
                         tool_version_using_old_id = tool_util.get_tool_version( self.app, old_tool_id )
                         tool_version_using_guid = tool_util.get_tool_version( self.app, tool_id )
                         if not tool_version_using_old_id:
                             tool_version_using_old_id = self.app.model.ToolVersion( tool_id=old_tool_id,
                                                                                     tool_shed_repository=tool_shed_repository )
                             self.app.sa_session.add( tool_version_using_old_id )
                             self.app.sa_session.flush()
                         if not tool_version_using_guid:
                             tool_version_using_guid = self.app.model.ToolVersion( tool_id=tool_id,
                                                                                   tool_shed_repository=tool_shed_repository )
                             self.app.sa_session.add( tool_version_using_guid )
                             self.app.sa_session.flush()
                         # Associate the two versions as parent / child.
                         tool_version_association = tool_util.get_tool_version_association( self.app,
                                                                                            tool_version_using_old_id,
                                                                                            tool_version_using_guid )
                         if not tool_version_association:
                             tool_version_association = self.app.model.ToolVersionAssociation( tool_id=tool_version_using_guid.id,
                                                                                               parent_id=tool_version_using_old_id.id )
                             self.app.sa_session.add( tool_version_association )
                             self.app.sa_session.flush()
             suc.update_tool_shed_repository_status( self.app, tool_shed_repository, self.app.model.ToolShedRepository.installation_status.INSTALLED )
示例#23
0
 def install_repository_revision( self, trans, payload, **kwd ):
     """
     POST /api/tool_shed_repositories/install_repository_revision
     Install a specified repository revision from a specified tool shed into Galaxy.
     
     :param key: the current Galaxy admin user's API key
     
     The following parameters are included in the payload.
     :param tool_shed_url (required): the base URL of the Tool Shed from which to install the Repository
     :param name (required): the name of the Repository
     :param owner (required): the owner of the Repository
     :param changset_revision (required): the changset_revision of the RepositoryMetadata object associated with the Repository
     :param new_tool_panel_section_label (optional): label of a new section to be added to the Galaxy tool panel in which to load
                                                     tools contained in the Repository.  Either this parameter must be an empty string or
                                                     the tool_panel_section_id parameter must be an empty string or both must be an empty
                                                     string (both cannot be used simultaneously).
     :param tool_panel_section_id (optional): id of the Galaxy tool panel section in which to load tools contained in the Repository.
                                              If this parameter is an empty string and the above new_tool_panel_section_label parameter is an
                                              empty string, tools will be loaded outside of any sections in the tool panel.  Either this
                                              parameter must be an empty string or the tool_panel_section_id parameter must be an empty string
                                              of both must be an empty string (both cannot be used simultaneously).
     :param install_repository_dependencies (optional): Set to True if you want to install repository dependencies defined for the specified
                                                        repository being installed.  The default setting is False.
     :param install_tool_dependencies (optional): Set to True if you want to install tool dependencies defined for the specified repository being
                                                  installed.  The default setting is False.
     :param shed_tool_conf (optional): The shed-related tool panel configuration file configured in the "tool_config_file" setting in the Galaxy config file
                                       (e.g., universe_wsgi.ini).  At least one shed-related tool panel config file is required to be configured. Setting
                                       this parameter to a specific file enables you to choose where the specified repository will be installed because
                                       the tool_path attribute of the <toolbox> from the specified file is used as the installation location
                                       (e.g., <toolbox tool_path="../shed_tools">).  If this parameter is not set, a shed-related tool panel configuration
                                       file will be selected automatically.
     """
     # Get the information about the repository to be installed from the payload.
     tool_shed_url = payload.get( 'tool_shed_url', '' )
     if not tool_shed_url:
         raise HTTPBadRequest( detail="Missing required parameter 'tool_shed_url'." )
     name = payload.get( 'name', '' )
     if not name:
         raise HTTPBadRequest( detail="Missing required parameter 'name'." )
     owner = payload.get( 'owner', '' )
     if not owner:
         raise HTTPBadRequest( detail="Missing required parameter 'owner'." )
     changeset_revision = payload.get( 'changeset_revision', '' )
     if not changeset_revision:
         raise HTTPBadRequest( detail="Missing required parameter 'changeset_revision'." )
     # Make sure this Galaxy instance is configured with a shed-related tool panel configuration file.
     if not suc.have_shed_tool_conf_for_install( trans ):
         message = get_message_for_no_shed_tool_config()
         log.error( message, exc_info=True )
         trans.response.status = 500
         return dict( status='error', error=message )
     # Make sure the current user's API key proves he is an admin user in this Galaxy instance.
     if not trans.user_is_admin():
         raise HTTPForbidden( detail='You are not authorized to install a tool shed repository into this Galaxy instance.' )
     # Keep track of all repositories that are installed - there may be more than one if repository dependencies are installed.
     installed_tool_shed_repositories = []
     # Get all of the information necessary for installing the repository from the specified tool shed.
     url = suc.url_join( tool_shed_url,
                         'api/repositories/get_repository_revision_install_info?name=%s&owner=%s&changeset_revision=%s' % \
                         ( name, owner, changeset_revision ) )
     try:
         raw_text = common_util.tool_shed_get( trans.app, tool_shed_url, url )
     except Exception, e:
         message = "Error attempting to retrieve installation information from tool shed %s for revision %s of repository %s owned by %s: %s" % \
             ( str( tool_shed_url ), str( changeset_revision ), str( name ), str( owner ), str( e ) )
         log.error( message, exc_info=True )
         trans.response.status = 500
         return dict( status='error', error=message )
示例#24
0
 def populate_containers_dict_from_repository_metadata( self, tool_shed_url, tool_path, repository, reinstalling=False,
                                                        required_repo_info_dicts=None ):
     """
     Retrieve necessary information from the received repository's metadata to populate the
     containers_dict for display.  This method is called only from Galaxy (not the tool shed)
     when displaying repository dependencies for installed repositories and when displaying
     them for uninstalled repositories that are being reinstalled.
     """
     metadata = repository.metadata
     if metadata:
         # Handle proprietary datatypes.
         datatypes = metadata.get( 'datatypes', None )
         # Handle invalid tools.
         invalid_tools = metadata.get( 'invalid_tools', None )
         # Handle README files.
         if repository.has_readme_files:
             if reinstalling or repository.status not in \
                 [ self.app.install_model.ToolShedRepository.installation_status.DEACTIVATED,
                   self.app.install_model.ToolShedRepository.installation_status.INSTALLED ]:
                 # Since we're reinstalling, we need to send a request to the tool shed to get the README files.
                 tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( self.app, tool_shed_url )
                 params = '?name=%s&owner=%s&changeset_revision=%s' % ( str( repository.name ),
                                                                        str( repository.owner ),
                                                                        str( repository.installed_changeset_revision ) )
                 url = common_util.url_join( tool_shed_url,
                                             'repository/get_readme_files%s' % params )
                 raw_text = common_util.tool_shed_get( self.app, tool_shed_url, url )
                 readme_files_dict = json.loads( raw_text )
             else:
                 readme_files_dict = readme_util.build_readme_files_dict( self.app,
                                                                          repository,
                                                                          repository.changeset_revision,
                                                                          repository.metadata, tool_path )
         else:
             readme_files_dict = None
         # Handle repository dependencies.
         installed_repository_dependencies, missing_repository_dependencies = \
             self.app.installed_repository_manager.get_installed_and_missing_repository_dependencies( repository )
         # Handle the current repository's tool dependencies.
         repository_tool_dependencies = metadata.get( 'tool_dependencies', None )
         # Make sure to display missing tool dependencies as well.
         repository_invalid_tool_dependencies = metadata.get( 'invalid_tool_dependencies', None )
         if repository_invalid_tool_dependencies is not None:
             if repository_tool_dependencies is None:
                 repository_tool_dependencies = {}
             repository_tool_dependencies.update( repository_invalid_tool_dependencies )
         repository_installed_tool_dependencies, repository_missing_tool_dependencies = \
             self.get_installed_and_missing_tool_dependencies_for_installed_repository( repository,
                                                                                        repository_tool_dependencies )
         if reinstalling:
             installed_tool_dependencies, missing_tool_dependencies = \
                 self.populate_tool_dependencies_dicts( tool_shed_url,
                                                        tool_path,
                                                        repository_installed_tool_dependencies,
                                                        repository_missing_tool_dependencies,
                                                        required_repo_info_dicts )
         else:
             installed_tool_dependencies = repository_installed_tool_dependencies
             missing_tool_dependencies = repository_missing_tool_dependencies
         # Handle valid tools.
         valid_tools = metadata.get( 'tools', None )
         # Handle workflows.
         workflows = metadata.get( 'workflows', None )
         # Handle Data Managers
         valid_data_managers = None
         invalid_data_managers = None
         data_managers_errors = None
         if 'data_manager' in metadata:
             valid_data_managers = metadata['data_manager'].get( 'data_managers', None )
             invalid_data_managers = metadata['data_manager'].get( 'invalid_data_managers', None )
             data_managers_errors = metadata['data_manager'].get( 'messages', None )
         gucm = GalaxyUtilityContainerManager( self.app )
         containers_dict = gucm.build_repository_containers( repository=repository,
                                                             datatypes=datatypes,
                                                             invalid_tools=invalid_tools,
                                                             missing_repository_dependencies=missing_repository_dependencies,
                                                             missing_tool_dependencies=missing_tool_dependencies,
                                                             readme_files_dict=readme_files_dict,
                                                             repository_dependencies=installed_repository_dependencies,
                                                             tool_dependencies=installed_tool_dependencies,
                                                             valid_tools=valid_tools,
                                                             workflows=workflows,
                                                             valid_data_managers=valid_data_managers,
                                                             invalid_data_managers=invalid_data_managers,
                                                             data_managers_errors=data_managers_errors,
                                                             new_install=False,
                                                             reinstalling=reinstalling )
     else:
         containers_dict = dict( datatypes=None,
                                 invalid_tools=None,
                                 readme_files_dict=None,
                                 repository_dependencies=None,
                                 tool_dependencies=None,
                                 valid_tools=None,
                                 workflows=None )
     return containers_dict
示例#25
0
 def install_repository(self,
                        repository_elem,
                        tool_shed_repository,
                        install_dependencies,
                        is_repository_dependency=False):
     """Install a single repository, loading contained tools into the tool panel."""
     # Install path is of the form: <tool path>/<tool shed>/repos/<repository owner>/<repository name>/<installed changeset revision>
     relative_clone_dir = os.path.join(
         tool_shed_repository.tool_shed, 'repos',
         tool_shed_repository.owner, tool_shed_repository.name,
         tool_shed_repository.installed_changeset_revision)
     clone_dir = os.path.join(self.tool_path, relative_clone_dir)
     cloned_ok = self.__iscloned(clone_dir)
     is_installed = False
     # Any of the following states should count as installed in this context.
     if tool_shed_repository.status in [
             self.app.install_model.ToolShedRepository.installation_status.
             INSTALLED, self.app.install_model.ToolShedRepository.
             installation_status.ERROR, self.app.install_model.
             ToolShedRepository.installation_status.UNINSTALLED,
             self.app.install_model.ToolShedRepository.installation_status.
             DEACTIVATED
     ]:
         is_installed = True
     if cloned_ok and is_installed:
         log.info(
             "Skipping automatic install of repository '%s' because it has already been installed in location %s",
             tool_shed_repository.name, clone_dir)
     else:
         irm = install_manager.InstallRepositoryManager(self.app, self.tpm)
         repository_clone_url = os.path.join(self.tool_shed_url, 'repos',
                                             tool_shed_repository.owner,
                                             tool_shed_repository.name)
         relative_install_dir = os.path.join(relative_clone_dir,
                                             tool_shed_repository.name)
         install_dir = os.path.join(clone_dir, tool_shed_repository.name)
         ctx_rev = suc.get_ctx_rev(
             self.app, self.tool_shed_url, tool_shed_repository.name,
             tool_shed_repository.owner,
             tool_shed_repository.installed_changeset_revision)
         if not cloned_ok:
             irm.update_tool_shed_repository_status(
                 tool_shed_repository, self.app.install_model.
                 ToolShedRepository.installation_status.CLONING)
             cloned_ok, error_message = hg_util.clone_repository(
                 repository_clone_url, os.path.abspath(install_dir),
                 ctx_rev)
         if cloned_ok and not is_installed:
             self.handle_repository_contents(
                 tool_shed_repository=tool_shed_repository,
                 repository_clone_url=repository_clone_url,
                 relative_install_dir=relative_install_dir,
                 repository_elem=repository_elem,
                 install_dependencies=install_dependencies,
                 is_repository_dependency=is_repository_dependency)
             self.app.install_model.context.refresh(tool_shed_repository)
             metadata_dict = tool_shed_repository.metadata
             if 'tools' in metadata_dict:
                 # Initialize the ToolVersionManager.
                 tvm = tool_version_manager.ToolVersionManager(self.app)
                 irm.update_tool_shed_repository_status(
                     tool_shed_repository,
                     self.app.install_model.ToolShedRepository.
                     installation_status.SETTING_TOOL_VERSIONS)
                 # Get the tool_versions from the tool shed for each tool in the installed change set.
                 params = dict(name=tool_shed_repository.name,
                               owner=self.repository_owner,
                               changeset_revision=tool_shed_repository.
                               installed_changeset_revision)
                 pathspec = ['repository', 'get_tool_versions']
                 text = common_util.tool_shed_get(self.app,
                                                  self.tool_shed_url,
                                                  pathspec=pathspec,
                                                  params=params)
                 if text:
                     tool_version_dicts = json.loads(text)
                     tvm.handle_tool_versions(tool_version_dicts,
                                              tool_shed_repository)
                 else:
                     # Set the tool versions since they seem to be missing
                     # for this repository in the tool shed. CRITICAL NOTE:
                     # These default settings may not properly handle all
                     # parent/child associations.
                     for tool_dict in metadata_dict['tools']:
                         tool_id = tool_dict['guid']
                         old_tool_id = tool_dict['id']
                         tool_version_using_old_id = tvm.get_tool_version(
                             old_tool_id)
                         tool_version_using_guid = tvm.get_tool_version(
                             tool_id)
                         if not tool_version_using_old_id:
                             tool_version_using_old_id = self.app.install_model.ToolVersion(
                                 tool_id=old_tool_id,
                                 tool_shed_repository=tool_shed_repository)
                             self.app.install_model.context.add(
                                 tool_version_using_old_id)
                             self.app.install_model.context.flush()
                         if not tool_version_using_guid:
                             tool_version_using_guid = self.app.install_model.ToolVersion(
                                 tool_id=tool_id,
                                 tool_shed_repository=tool_shed_repository)
                             self.app.install_model.context.add(
                                 tool_version_using_guid)
                             self.app.install_model.context.flush()
                         # Associate the two versions as parent / child.
                         tool_version_association = tvm.get_tool_version_association(
                             tool_version_using_old_id,
                             tool_version_using_guid)
                         if not tool_version_association:
                             tool_version_association = \
                                 self.app.install_model.ToolVersionAssociation( tool_id=tool_version_using_guid.id,
                                                                                parent_id=tool_version_using_old_id.id )
                             self.app.install_model.context.add(
                                 tool_version_association)
                             self.app.install_model.context.flush()
             irm.update_tool_shed_repository_status(
                 tool_shed_repository, self.app.install_model.
                 ToolShedRepository.installation_status.INSTALLED)
         else:
             log.error('Error attempting to clone repository %s: %s',
                       str(tool_shed_repository.name), str(error_message))
             irm.update_tool_shed_repository_status(
                 tool_shed_repository,
                 self.app.install_model.ToolShedRepository.
                 installation_status.ERROR,
                 error_message=error_message)
 def install_repository( self, repository_elem, tool_shed_repository, install_dependencies, is_repository_dependency=False ):
     """Install a single repository, loading contained tools into the tool panel."""
     # Install path is of the form: <tool path>/<tool shed>/repos/<repository owner>/<repository name>/<installed changeset revision>
     relative_clone_dir = os.path.join( tool_shed_repository.tool_shed,
                                        'repos',
                                        tool_shed_repository.owner,
                                        tool_shed_repository.name,
                                        tool_shed_repository.installed_changeset_revision )
     clone_dir = os.path.join( self.tool_path, relative_clone_dir )
     cloned_ok = self.__iscloned( clone_dir )
     is_installed = False
     # Any of the following states should count as installed in this context.
     if tool_shed_repository.status in [ self.app.install_model.ToolShedRepository.installation_status.INSTALLED,
                                         self.app.install_model.ToolShedRepository.installation_status.ERROR,
                                         self.app.install_model.ToolShedRepository.installation_status.UNINSTALLED,
                                         self.app.install_model.ToolShedRepository.installation_status.DEACTIVATED ]:
         is_installed = True
     if cloned_ok and is_installed:
         print "Skipping automatic install of repository '", tool_shed_repository.name, "' because it has already been installed in location ", clone_dir
     else:
         irm = install_manager.InstallRepositoryManager( self.app, self.tpm )
         repository_clone_url = os.path.join( self.tool_shed_url, 'repos', tool_shed_repository.owner, tool_shed_repository.name )
         relative_install_dir = os.path.join( relative_clone_dir, tool_shed_repository.name )
         install_dir = os.path.join( clone_dir, tool_shed_repository.name )
         ctx_rev = suc.get_ctx_rev( self.app,
                                    self.tool_shed_url,
                                    tool_shed_repository.name,
                                    tool_shed_repository.owner,
                                    tool_shed_repository.installed_changeset_revision )
         if not cloned_ok:
             irm.update_tool_shed_repository_status( tool_shed_repository,
                                                     self.app.install_model.ToolShedRepository.installation_status.CLONING )
             cloned_ok, error_message = hg_util.clone_repository( repository_clone_url, os.path.abspath( install_dir ), ctx_rev )
         if cloned_ok and not is_installed:
             self.handle_repository_contents( tool_shed_repository=tool_shed_repository,
                                              repository_clone_url=repository_clone_url,
                                              relative_install_dir=relative_install_dir,
                                              repository_elem=repository_elem,
                                              install_dependencies=install_dependencies,
                                              is_repository_dependency=is_repository_dependency )
             self.app.install_model.context.refresh( tool_shed_repository )
             metadata_dict = tool_shed_repository.metadata
             if 'tools' in metadata_dict:
                 # Initialize the ToolVersionManager.
                 tvm = tool_version_manager.ToolVersionManager( self.app )
                 irm.update_tool_shed_repository_status( tool_shed_repository,
                                                         self.app.install_model.ToolShedRepository.installation_status.SETTING_TOOL_VERSIONS )
                 # Get the tool_versions from the tool shed for each tool in the installed change set.
                 url = '%s/repository/get_tool_versions?name=%s&owner=%s&changeset_revision=%s' % \
                     ( self.tool_shed_url, tool_shed_repository.name, self.repository_owner, tool_shed_repository.installed_changeset_revision )
                 text = common_util.tool_shed_get( self.app, self.tool_shed_url, url )
                 if text:
                     tool_version_dicts = json.loads( text )
                     tvm.handle_tool_versions( tool_version_dicts, tool_shed_repository )
                 else:
                     # Set the tool versions since they seem to be missing for this repository in the tool shed.
                     # CRITICAL NOTE: These default settings may not properly handle all parent/child associations.
                     for tool_dict in metadata_dict[ 'tools' ]:
                         flush_needed = False
                         tool_id = tool_dict[ 'guid' ]
                         old_tool_id = tool_dict[ 'id' ]
                         tool_version = tool_dict[ 'version' ]
                         tool_version_using_old_id = tvm.get_tool_version( old_tool_id )
                         tool_version_using_guid = tvm.get_tool_version( tool_id )
                         if not tool_version_using_old_id:
                             tool_version_using_old_id = self.app.install_model.ToolVersion( tool_id=old_tool_id,
                                                                                     tool_shed_repository=tool_shed_repository )
                             self.app.install_model.context.add( tool_version_using_old_id )
                             self.app.install_model.context.flush()
                         if not tool_version_using_guid:
                             tool_version_using_guid = self.app.install_model.ToolVersion( tool_id=tool_id,
                                                                                   tool_shed_repository=tool_shed_repository )
                             self.app.install_model.context.add( tool_version_using_guid )
                             self.app.install_model.context.flush()
                         # Associate the two versions as parent / child.
                         tool_version_association = tvm.get_tool_version_association( tool_version_using_old_id,
                                                                                      tool_version_using_guid )
                         if not tool_version_association:
                             tool_version_association = \
                                 self.app.install_model.ToolVersionAssociation( tool_id=tool_version_using_guid.id,
                                                                                parent_id=tool_version_using_old_id.id )
                             self.app.install_model.context.add( tool_version_association )
                             self.app.install_model.context.flush()
             irm.update_tool_shed_repository_status( tool_shed_repository,
                                                     self.app.install_model.ToolShedRepository.installation_status.INSTALLED )
         else:
             print 'Error attempting to clone repository %s: %s' % ( str( tool_shed_repository.name ), str( error_message ) )
             irm.update_tool_shed_repository_status( tool_shed_repository,
                                                     self.app.install_model.ToolShedRepository.installation_status.ERROR,
                                                     error_message=error_message )
示例#27
0
 def populate_containers_dict_from_repository_metadata(
         self,
         tool_shed_url,
         tool_path,
         repository,
         reinstalling=False,
         required_repo_info_dicts=None):
     """
     Retrieve necessary information from the received repository's metadata to populate the
     containers_dict for display.  This method is called only from Galaxy (not the tool shed)
     when displaying repository dependencies for installed repositories and when displaying
     them for uninstalled repositories that are being reinstalled.
     """
     metadata = repository.metadata
     if metadata:
         # Handle proprietary datatypes.
         datatypes = metadata.get('datatypes', None)
         # Handle invalid tools.
         invalid_tools = metadata.get('invalid_tools', None)
         # Handle README files.
         if repository.has_readme_files:
             if reinstalling or repository.status not in \
                 [ self.app.install_model.ToolShedRepository.installation_status.DEACTIVATED,
                   self.app.install_model.ToolShedRepository.installation_status.INSTALLED ]:
                 # Since we're reinstalling, we need to send a request to the tool shed to get the README files.
                 tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(
                     self.app, tool_shed_url)
                 params = dict(name=str(repository.name),
                               owner=str(repository.owner),
                               changeset_revision=str(
                                   repository.installed_changeset_revision))
                 pathspec = ['repository', 'get_readme_files']
                 raw_text = common_util.tool_shed_get(self.app,
                                                      tool_shed_url,
                                                      pathspec=pathspec,
                                                      params=params)
                 readme_files_dict = json.loads(raw_text)
             else:
                 readme_files_dict = readme_util.build_readme_files_dict(
                     self.app, repository, repository.changeset_revision,
                     repository.metadata, tool_path)
         else:
             readme_files_dict = None
         # Handle repository dependencies.
         installed_repository_dependencies, missing_repository_dependencies = \
             self.app.installed_repository_manager.get_installed_and_missing_repository_dependencies( repository )
         # Handle the current repository's tool dependencies.
         repository_tool_dependencies = metadata.get(
             'tool_dependencies', None)
         # Make sure to display missing tool dependencies as well.
         repository_invalid_tool_dependencies = metadata.get(
             'invalid_tool_dependencies', None)
         if repository_invalid_tool_dependencies is not None:
             if repository_tool_dependencies is None:
                 repository_tool_dependencies = {}
             repository_tool_dependencies.update(
                 repository_invalid_tool_dependencies)
         repository_installed_tool_dependencies, repository_missing_tool_dependencies = \
             self.get_installed_and_missing_tool_dependencies_for_installed_repository( repository,
                                                                                        repository_tool_dependencies )
         if reinstalling:
             installed_tool_dependencies, missing_tool_dependencies = \
                 self.populate_tool_dependencies_dicts( tool_shed_url,
                                                        tool_path,
                                                        repository_installed_tool_dependencies,
                                                        repository_missing_tool_dependencies,
                                                        required_repo_info_dicts )
         else:
             installed_tool_dependencies = repository_installed_tool_dependencies
             missing_tool_dependencies = repository_missing_tool_dependencies
         # Handle valid tools.
         valid_tools = metadata.get('tools', None)
         # Handle workflows.
         workflows = metadata.get('workflows', None)
         # Handle Data Managers
         valid_data_managers = None
         invalid_data_managers = None
         data_managers_errors = None
         if 'data_manager' in metadata:
             valid_data_managers = metadata['data_manager'].get(
                 'data_managers', None)
             invalid_data_managers = metadata['data_manager'].get(
                 'invalid_data_managers', None)
             data_managers_errors = metadata['data_manager'].get(
                 'messages', None)
         gucm = GalaxyUtilityContainerManager(self.app)
         containers_dict = gucm.build_repository_containers(
             repository=repository,
             datatypes=datatypes,
             invalid_tools=invalid_tools,
             missing_repository_dependencies=missing_repository_dependencies,
             missing_tool_dependencies=missing_tool_dependencies,
             readme_files_dict=readme_files_dict,
             repository_dependencies=installed_repository_dependencies,
             tool_dependencies=installed_tool_dependencies,
             valid_tools=valid_tools,
             workflows=workflows,
             valid_data_managers=valid_data_managers,
             invalid_data_managers=invalid_data_managers,
             data_managers_errors=data_managers_errors,
             new_install=False,
             reinstalling=reinstalling)
     else:
         containers_dict = dict(datatypes=None,
                                invalid_tools=None,
                                readme_files_dict=None,
                                repository_dependencies=None,
                                tool_dependencies=None,
                                valid_tools=None,
                                workflows=None)
     return containers_dict