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:
         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:
             suc.update_tool_shed_repository_status( self.app, tool_shed_repository, self.app.install_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 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:
                 suc.update_tool_shed_repository_status( self.app,
                                                         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 = 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.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 = 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.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()
             suc.update_tool_shed_repository_status( self.app, 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 ) )
             suc.update_tool_shed_repository_status( self.app,
                                                     tool_shed_repository,
                                                     self.app.install_model.ToolShedRepository.installation_status.ERROR,
                                                     error_message=error_message )
示例#2
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 )