Exemplo n.º 1
0
 def __init__( self, app, tpm=None ):
     super( InstalledRepositoryMetadataManager, self ).__init__( app )
     self.app = app
     if tpm is None:
         self.tpm = tool_panel_manager.ToolPanelManager( self.app )
     else:
         self.tpm = tpm
Exemplo n.º 2
0
    def repair_tool_shed_repository( self, repository, repo_info_dict ):

        def add_repair_dict_entry( repository_name, error_message ):
            if repository_name in repair_dict:
                repair_dict[ repository_name ].append( error_message )
            else:
                repair_dict[ repository_name ] = [ error_message ]
            return repair_dict

        metadata = repository.metadata
        repair_dict = {}
        tpm = tool_panel_manager.ToolPanelManager( self.app )
        if repository.status in [ self.app.install_model.ToolShedRepository.installation_status.DEACTIVATED ]:
            try:
                self.app.installed_repository_manager.activate_repository( repository )
            except Exception, e:
                error_message = "Error activating repository %s: %s" % ( repository.name, str( e ) )
                log.debug( error_message )
                repair_dict[ repository.name ] = error_message
    def repair_tool_shed_repository( self, repository, repo_info_dict ):

        def add_repair_dict_entry( repository_name, error_message ):
            if repository_name in repair_dict:
                repair_dict[ repository_name ].append( error_message )
            else:
                repair_dict[ repository_name ] = [ error_message ]
            return repair_dict
        tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( self.app, repository.tool_shed )
        metadata = repository.metadata
        # The repository.metadata contains dependency information that corresponds to the current changeset revision,
        # which may be different from what is stored in the database
        # If any of these repository-repository dependency associations is obsolete, clean_dependency_relationships removes them.
        suc.clean_dependency_relationships(self.app, metadata, repository, tool_shed_url)
        repair_dict = {}
        tpm = tool_panel_manager.ToolPanelManager( self.app )
        if repository.status in [ self.app.install_model.ToolShedRepository.installation_status.DEACTIVATED ]:
            try:
                self.app.installed_repository_manager.activate_repository( repository )
            except Exception, e:
                error_message = "Error activating repository %s: %s" % ( repository.name, str( e ) )
                log.debug( error_message )
                repair_dict[ repository.name ] = error_message
Exemplo n.º 4
0
 def install_data_managers( self, shed_data_manager_conf_filename, metadata_dict, shed_config_dict,
                            relative_install_dir, repository, repository_tools_tups ):
     rval = []
     if 'data_manager' in metadata_dict:
         tpm = tool_panel_manager.ToolPanelManager( self.app )
         repository_tools_by_guid = {}
         for tool_tup in repository_tools_tups:
             repository_tools_by_guid[ tool_tup[ 1 ] ] = dict( tool_config_filename=tool_tup[ 0 ], tool=tool_tup[ 2 ] )
         # Load existing data managers.
         tree, error_message = xml_util.parse_xml( shed_data_manager_conf_filename )
         if tree is None:
             return rval
         config_elems = [ elem for elem in tree.getroot() ]
         repo_data_manager_conf_filename = metadata_dict['data_manager'].get( 'config_filename', None )
         if repo_data_manager_conf_filename is None:
             log.debug( "No data_manager_conf.xml file has been defined." )
             return rval
         data_manager_config_has_changes = False
         relative_repo_data_manager_dir = os.path.join( shed_config_dict.get( 'tool_path', '' ), relative_install_dir )
         repo_data_manager_conf_filename = os.path.join( relative_repo_data_manager_dir, repo_data_manager_conf_filename )
         tree, error_message = xml_util.parse_xml( repo_data_manager_conf_filename )
         if tree is None:
             return rval
         root = tree.getroot()
         for elem in root:
             if elem.tag == 'data_manager':
                 data_manager_id = elem.get( 'id', None )
                 if data_manager_id is None:
                     log.error( "A data manager was defined that does not have an id and will not be installed:\n%s" % \
                                 xml_util.xml_to_string( elem ) )
                     continue
                 data_manager_dict = metadata_dict['data_manager'].get( 'data_managers', {} ).get( data_manager_id, None )
                 if data_manager_dict is None:
                     log.error( "Data manager metadata is not defined properly for '%s'." % ( data_manager_id ) )
                     continue
                 guid = data_manager_dict.get( 'guid', None )
                 if guid is None:
                     log.error( "Data manager guid '%s' is not set in metadata for '%s'." % ( guid, data_manager_id ) )
                     continue
                 elem.set( 'guid', guid )
                 tool_guid = data_manager_dict.get( 'tool_guid', None )
                 if tool_guid is None:
                     log.error( "Data manager tool guid '%s' is not set in metadata for '%s'." % ( tool_guid, data_manager_id ) )
                     continue
                 tool_dict = repository_tools_by_guid.get( tool_guid, None )
                 if tool_dict is None:
                     log.error( "Data manager tool guid '%s' could not be found for '%s'. Perhaps the tool is invalid?" % \
                                 ( tool_guid, data_manager_id ) )
                     continue
                 tool = tool_dict.get( 'tool', None )
                 if tool is None:
                     log.error( "Data manager tool with guid '%s' could not be found for '%s'. Perhaps the tool is invalid?" % \
                                ( tool_guid, data_manager_id ) )
                     continue
                 tool_config_filename = tool_dict.get( 'tool_config_filename', None )
                 if tool_config_filename is None:
                     log.error( "Data manager metadata is missing 'tool_config_file' for '%s'." % ( data_manager_id ) )
                     continue
                 elem.set( 'shed_conf_file', shed_config_dict['config_filename'] )
                 if elem.get( 'tool_file', None ) is not None:
                     del elem.attrib[ 'tool_file' ] #remove old tool_file info
                 tool_elem = tpm.generate_tool_elem( repository.tool_shed,
                                                     repository.name,
                                                     repository.installed_changeset_revision,
                                                     repository.owner,
                                                     tool_config_filename,
                                                     tool,
                                                     None )
                 elem.insert( 0, tool_elem )
                 data_manager = \
                     self.app.data_managers.load_manager_from_elem( elem,
                                                                    tool_path=shed_config_dict.get( 'tool_path', '' ),
                                                                    replace_existing=True )
                 if data_manager:
                     rval.append( data_manager )
             else:
                 log.warning( "Encountered unexpected element '%s':\n%s" % ( elem.tag, xml_util.xml_to_string( elem ) ) )
             config_elems.append( elem )
             data_manager_config_has_changes = True
         # Persist the altered shed_data_manager_config file.
         if data_manager_config_has_changes:
             self.data_manager_config_elems_to_xml_file( config_elems, shed_data_manager_conf_filename  )
     return rval
 def create_repository_dependency_objects( self, tool_path, tool_shed_url, repo_info_dicts, install_repository_dependencies=False,
                                           no_changes_checked=False, tool_panel_section_id=None, new_tool_panel_section_label=None ):
     """
     Discover all repository dependencies and make sure all tool_shed_repository and
     associated repository_dependency records exist as well as the dependency relationships
     between installed repositories.  This method is called when uninstalled repositories
     are being reinstalled.  If the user elected to install repository dependencies, all
     items in the all_repo_info_dicts list will be processed.  However, if repository
     dependencies are not to be installed, only those items contained in the received
     repo_info_dicts list will be processed.
     """
     install_model = self.app.install_model
     log.debug( "Creating repository dependency objects..." )
     # The following list will be maintained within this method to contain all created
     # or updated tool shed repositories, including repository dependencies that may not
     # be installed.
     all_created_or_updated_tool_shed_repositories = []
     # There will be a one-to-one mapping between items in 3 lists:
     # created_or_updated_tool_shed_repositories, tool_panel_section_keys
     # and filtered_repo_info_dicts.  The 3 lists will filter out repository
     # dependencies that are not to be installed.
     created_or_updated_tool_shed_repositories = []
     tool_panel_section_keys = []
     # Repositories will be filtered (e.g., if already installed, if elected
     # to not be installed, etc), so filter the associated repo_info_dicts accordingly.
     filtered_repo_info_dicts = []
     # Discover all repository dependencies and retrieve information for installing
     # them.  Even if the user elected to not install repository dependencies we have
     # to make sure all repository dependency objects exist so that the appropriate
     # repository dependency relationships can be built.
     all_required_repo_info_dict = self.get_required_repo_info_dicts( tool_shed_url, repo_info_dicts )
     all_repo_info_dicts = all_required_repo_info_dict.get( 'all_repo_info_dicts', [] )
     if not all_repo_info_dicts:
         # No repository dependencies were discovered so process the received repositories.
         all_repo_info_dicts = [ rid for rid in repo_info_dicts ]
     for repo_info_dict in all_repo_info_dicts:
         # If the user elected to install repository dependencies, all items in the
         # all_repo_info_dicts list will be processed.  However, if repository dependencies
         # are not to be installed, only those items contained in the received repo_info_dicts
         # list will be processed but the all_repo_info_dicts list will be used to create all
         # defined repository dependency relationships.
         if self.is_in_repo_info_dicts( repo_info_dict, repo_info_dicts ) or install_repository_dependencies:
             for name, repo_info_tuple in repo_info_dict.items():
                 can_update_db_record = False
                 description, \
                     repository_clone_url, \
                     changeset_revision, \
                     ctx_rev, \
                     repository_owner, \
                     repository_dependencies, \
                     tool_dependencies = \
                     suc.get_repo_info_tuple_contents( repo_info_tuple )
                 # See if the repository has an existing record in the database.
                 repository_db_record, installed_changeset_revision = \
                     suc.repository_was_previously_installed( self.app, tool_shed_url, name, repo_info_tuple, from_tip=False )
                 if repository_db_record:
                     if repository_db_record.status in [ install_model.ToolShedRepository.installation_status.INSTALLED,
                                                         install_model.ToolShedRepository.installation_status.CLONING,
                                                         install_model.ToolShedRepository.installation_status.SETTING_TOOL_VERSIONS,
                                                         install_model.ToolShedRepository.installation_status.INSTALLING_REPOSITORY_DEPENDENCIES,
                                                         install_model.ToolShedRepository.installation_status.INSTALLING_TOOL_DEPENDENCIES,
                                                         install_model.ToolShedRepository.installation_status.LOADING_PROPRIETARY_DATATYPES ]:
                         debug_msg = "Skipping installation of revision %s of repository '%s' because it was installed " % \
                             ( str( changeset_revision ), str( repository_db_record.name ) )
                         debug_msg += "with the (possibly updated) revision %s and its current installation status is '%s'." % \
                             ( str( installed_changeset_revision ), str( repository_db_record.status ) )
                         log.debug( debug_msg )
                         can_update_db_record = False
                     else:
                         if repository_db_record.status in [ install_model.ToolShedRepository.installation_status.ERROR,
                                                             install_model.ToolShedRepository.installation_status.NEW,
                                                             install_model.ToolShedRepository.installation_status.UNINSTALLED ]:
                             # The current tool shed repository is not currently installed, so we can update its
                             # record in the database.
                             name = repository_db_record.name
                             installed_changeset_revision = repository_db_record.installed_changeset_revision
                             can_update_db_record = True
                         elif repository_db_record.status in [ install_model.ToolShedRepository.installation_status.DEACTIVATED ]:
                             # The current tool shed repository is deactivated, so updating its database record
                             # is not necessary - just activate it.
                             log.debug( "Reactivating deactivated tool_shed_repository '%s'." % str( repository_db_record.name ) )
                             self.app.installed_repository_manager.activate_repository( repository_db_record )
                             # No additional updates to the database record are necessary.
                             can_update_db_record = False
                         elif repository_db_record.status not in [ install_model.ToolShedRepository.installation_status.NEW ]:
                             # Set changeset_revision here so suc.create_or_update_tool_shed_repository will find
                             # the previously installed and uninstalled repository instead of creating a new record.
                             changeset_revision = repository_db_record.installed_changeset_revision
                             self.reset_previously_installed_repository( repository_db_record )
                             can_update_db_record = True
                 else:
                     # No record exists in the database for the repository currently being processed.
                     installed_changeset_revision = changeset_revision
                     can_update_db_record = True
                 if can_update_db_record:
                     # The database record for the tool shed repository currently being processed can be updated.
                     # Get the repository metadata to see where it was previously located in the tool panel.
                     tpm = tool_panel_manager.ToolPanelManager( self.app )
                     if repository_db_record and repository_db_record.metadata:
                         _, tool_panel_section_key = \
                             tpm.handle_tool_panel_selection( toolbox=self.app.toolbox,
                                                              metadata=repository_db_record.metadata,
                                                              no_changes_checked=no_changes_checked,
                                                              tool_panel_section_id=tool_panel_section_id,
                                                              new_tool_panel_section_label=new_tool_panel_section_label )
                     else:
                         # We're installing a new tool shed repository that does not yet have a database record.
                         tool_panel_section_key, _ = \
                             tpm.handle_tool_panel_section( self.app.toolbox,
                                                            tool_panel_section_id=tool_panel_section_id,
                                                            new_tool_panel_section_label=new_tool_panel_section_label )
                     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=install_model.ToolShedRepository.installation_status.NEW,
                                                                    current_changeset_revision=changeset_revision,
                                                                    owner=repository_owner,
                                                                    dist_to_shed=False )
                     if tool_shed_repository not in all_created_or_updated_tool_shed_repositories:
                         all_created_or_updated_tool_shed_repositories.append( tool_shed_repository )
                     # Only append the tool shed repository to the list of created_or_updated_tool_shed_repositories if
                     # it is supposed to be installed.
                     if install_repository_dependencies or self.is_in_repo_info_dicts( repo_info_dict, repo_info_dicts ):
                         if tool_shed_repository not in created_or_updated_tool_shed_repositories:
                             # Keep the one-to-one mapping between items in 3 lists.
                             created_or_updated_tool_shed_repositories.append( tool_shed_repository )
                             tool_panel_section_keys.append( tool_panel_section_key )
                             filtered_repo_info_dicts.append( repo_info_dict )
     # Build repository dependency relationships even if the user chose to not install repository dependencies.
     self.build_repository_dependency_relationships( all_repo_info_dicts, all_created_or_updated_tool_shed_repositories )
     return created_or_updated_tool_shed_repositories, tool_panel_section_keys, all_repo_info_dicts, filtered_repo_info_dicts