From 690dc8fd92dd57213bcfc2abff9fdb6b62833f00 Mon Sep 17 00:00:00 2001 From: Greg Von Kuster Date: Thu, 27 Oct 2011 15:08:07 -0400 Subject: [PATCH] Create a new ToolShedRepository record only if necessary - if one already exists for the installed repository but is marked deleted, mark the exisint record undeleted. --- lib/galaxy/web/base/controller.py | 7 ++++++ lib/galaxy/web/controllers/admin.py | 34 +++++++++++++++++------------ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/lib/galaxy/web/base/controller.py b/lib/galaxy/web/base/controller.py index aac24eca02e..aaa4be76156 100644 --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -2443,6 +2443,13 @@ def get_quota( trans, id ): id = trans.security.decode_id( id ) quota = trans.sa_session.query( trans.model.Quota ).get( id ) return quota +def get_tool_shed_repository( trans, tool_shed, name, owner, changeset_revision ): + return trans.sa_session.query( trans.model.ToolShedRepository ) \ + .filter( and_( trans.model.ToolShedRepository.table.c.tool_shed == tool_shed, + trans.model.ToolShedRepository.table.c.name == name, + trans.model.ToolShedRepository.table.c.owner == owner, + trans.model.ToolShedRepository.table.c.changeset_revision == changeset_revision ) ) \ + .first() def handle_sample_tool_data_table_conf_file( trans, filename ): """ Parse the incoming filename and add new entries to the in-memory diff --git a/lib/galaxy/web/controllers/admin.py b/lib/galaxy/web/controllers/admin.py index e56e0c9e02b..d2f6fe9354b 100644 --- a/lib/galaxy/web/controllers/admin.py +++ b/lib/galaxy/web/controllers/admin.py @@ -766,12 +766,9 @@ class AdminGalaxy( BaseUIController, Admin, AdminActions, UsesQuota, QuotaParamP os.chdir( current_working_dir ) tmp_stderr.close() if returncode == 0: - # Add a new record to the tool_shed_repository table. - tool_shed_repository = self.__create_tool_shed_repository( trans, - name, - description, - changeset_revision, - repository_clone_url ) + # Add a new record to the tool_shed_repository table if one doesn't + # already exist. If one exists but is marked deleted, undelete it. + self.__create_or_undelete_tool_shed_repository( trans, name, description, changeset_revision, repository_clone_url ) # Update the cloned repository to changeset_revision. repo_files_dir = os.path.join( clone_dir, name ) log.debug( 'Updating cloned repository to revision "%s"...' % changeset_revision ) @@ -1055,17 +1052,26 @@ class AdminGalaxy( BaseUIController, Admin, AdminActions, UsesQuota, QuotaParamP # We have an invalid .xml file, so not a tool config. log.debug( "Ignoring invalid tool config (%s). Error: %s" % ( str( relative_path ), str( e ) ) ) return sample_files, repository_tools_tups - def __create_tool_shed_repository( self, trans, name, description, changeset_revision, repository_clone_url ): + def __create_or_undelete_tool_shed_repository( self, trans, name, description, changeset_revision, repository_clone_url ): tmp_url = self.__clean_repository_clone_url( repository_clone_url ) tool_shed = tmp_url.split( 'repos' )[ 0 ].rstrip( '/' ) owner = self.__get_repository_owner( tmp_url ) - tool_shed_repository = trans.model.ToolShedRepository( tool_shed=tool_shed, - name=name, - description=description, - owner=owner, - changeset_revision=changeset_revision ) - trans.sa_session.add( tool_shed_repository ) - trans.sa_session.flush() + flush_needed = False + tool_shed_repository = get_tool_shed_repository( trans, tool_shed, name, owner, changeset_revision ) + if tool_shed_repository: + if tool_shed_repository.deleted: + tool_shed_repository.deleted = False + flush_needed = True + else: + tool_shed_repository = trans.model.ToolShedRepository( tool_shed=tool_shed, + name=name, + description=description, + owner=owner, + changeset_revision=changeset_revision ) + flush_needed = True + if flush_needed: + trans.sa_session.add( tool_shed_repository ) + trans.sa_session.flush() def __add_shed_tool_conf_entry( self, trans, shed_tool_conf, new_tool_section ): # Add an entry in the shed_tool_conf file. An entry looks something like: #