commit/galaxy-central: greg: Yet more shed_util refactoring.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/c7bc628577af/ changeset: c7bc628577af user: greg date: 2012-11-16 19:36:36 summary: Yet more shed_util refactoring. affected #: 2 files diff -r 9e1d821b5c12f56bbfe1923ea1092608054c9d08 -r c7bc628577af7f57b5511b2cc8e1423d5faf31df lib/galaxy/util/shed_util.py --- a/lib/galaxy/util/shed_util.py +++ b/lib/galaxy/util/shed_util.py @@ -784,24 +784,6 @@ # Reset the tool_data_tables by loading the empty tool_data_table_conf.xml file. reset_tool_data_tables( app ) return repository_tools_tups -def handle_existing_tool_dependencies_that_changed_in_update( app, repository, original_dependency_dict, new_dependency_dict ): - """ - This method is called when a Galaxy admin is getting updates for an installed tool shed repository in order to cover the case where an - existing tool dependency was changed (e.g., the version of the dependency was changed) but the tool version for which it is a dependency - was not changed. In this case, we only want to determine if any of the dependency information defined in original_dependency_dict was - changed in new_dependency_dict. We don't care if new dependencies were added in new_dependency_dict since they will just be treated as - missing dependencies for the tool. - """ - updated_tool_dependency_names = [] - deleted_tool_dependency_names = [] - for original_dependency_key, original_dependency_val_dict in original_dependency_dict.items(): - if original_dependency_key not in new_dependency_dict: - updated_tool_dependency = update_existing_tool_dependency( app, repository, original_dependency_val_dict, new_dependency_dict ) - if updated_tool_dependency: - updated_tool_dependency_names.append( updated_tool_dependency.name ) - else: - deleted_tool_dependency_names.append( original_dependency_val_dict[ 'name' ] ) - return updated_tool_dependency_names, deleted_tool_dependency_names def handle_missing_index_file( app, tool_path, sample_files, repository_tools_tups, sample_files_copied ): """ Inspect each tool to see if it has any input parameters that are dynamically generated select lists that depend on a .loc file. @@ -1136,21 +1118,6 @@ trans.sa_session.add( tool_dependency ) trans.sa_session.flush() return removed, error_message -def remove_tool_dependency_installation_directory( dependency_install_dir ): - if os.path.exists( dependency_install_dir ): - try: - shutil.rmtree( dependency_install_dir ) - removed = True - error_message = '' - log.debug( "Removed tool dependency installation directory: %s" % str( dependency_install_dir ) ) - except Exception, e: - removed = False - error_message = "Error removing tool dependency installation directory %s: %s" % ( str( dependency_install_dir ), str( e ) ) - log.debug( error_message ) - else: - removed = True - error_message = '' - return removed, error_message def to_html_str( text ): """Translates the characters in text to an html string""" translated = [] @@ -1183,65 +1150,6 @@ else: translated_string = '' return translated_string -def update_existing_tool_dependency( app, repository, original_dependency_dict, new_dependencies_dict ): - """ - Update an exsiting tool dependency whose definition was updated in a change set pulled by a Galaxy administrator when getting updates - to an installed tool shed repository. The original_dependency_dict is a single tool dependency definition, an example of which is:: - - {"name": "bwa", - "readme": "\\nCompiling BWA requires zlib and libpthread to be present on your system.\\n ", - "type": "package", - "version": "0.6.2"} - - The new_dependencies_dict is the dictionary generated by the generate_tool_dependency_metadata method. - """ - new_tool_dependency = None - original_name = original_dependency_dict[ 'name' ] - original_type = original_dependency_dict[ 'type' ] - original_version = original_dependency_dict[ 'version' ] - # Locate the appropriate tool_dependency associated with the repository. - tool_dependency = None - for tool_dependency in repository.tool_dependencies: - if tool_dependency.name == original_name and tool_dependency.type == original_type and tool_dependency.version == original_version: - break - if tool_dependency and tool_dependency.can_update: - dependency_install_dir = tool_dependency.installation_directory( app ) - removed_from_disk, error_message = remove_tool_dependency_installation_directory( dependency_install_dir ) - if removed_from_disk: - sa_session = app.model.context.current - new_dependency_name = None - new_dependency_type = None - new_dependency_version = None - for new_dependency_key, new_dependency_val_dict in new_dependencies_dict.items(): - # Match on name only, hopefully this will be enough! - if original_name == new_dependency_val_dict[ 'name' ]: - new_dependency_name = new_dependency_val_dict[ 'name' ] - new_dependency_type = new_dependency_val_dict[ 'type' ] - new_dependency_version = new_dependency_val_dict[ 'version' ] - break - if new_dependency_name and new_dependency_type and new_dependency_version: - # Update all attributes of the tool_dependency record in the database. - log.debug( "Updating tool dependency '%s' with type '%s' and version '%s' to have new type '%s' and version '%s'." % \ - ( str( tool_dependency.name ), - str( tool_dependency.type ), - str( tool_dependency.version ), - str( new_dependency_type ), - str( new_dependency_version ) ) ) - tool_dependency.type = new_dependency_type - tool_dependency.version = new_dependency_version - tool_dependency.status = app.model.ToolDependency.installation_status.UNINSTALLED - tool_dependency.error_message = None - sa_session.add( tool_dependency ) - sa_session.flush() - new_tool_dependency = tool_dependency - else: - # We have no new tool dependency definition based on a matching dependency name, so remove the existing tool dependency record - # from the database. - log.debug( "Deleting tool dependency with name '%s', type '%s' and version '%s' from the database since it is no longer defined." % \ - ( str( tool_dependency.name ), str( tool_dependency.type ), str( tool_dependency.version ) ) ) - sa_session.delete( tool_dependency ) - sa_session.flush() - return new_tool_dependency def update_in_shed_tool_config( app, repository ): # A tool shed repository is being updated so change the shed_tool_conf file. Parse the config file to generate the entire list # of config_elems instead of using the in-memory list. diff -r 9e1d821b5c12f56bbfe1923ea1092608054c9d08 -r c7bc628577af7f57b5511b2cc8e1423d5faf31df lib/galaxy/util/shed_util_common.py --- a/lib/galaxy/util/shed_util_common.py +++ b/lib/galaxy/util/shed_util_common.py @@ -884,6 +884,24 @@ relative_path_to_file.startswith( os.path.join( shed_config_dict.get( 'tool_path' ), relative_install_dir ) ): relative_path_to_file = relative_path_to_file[ len( shed_config_dict.get( 'tool_path' ) ) + 1: ] return relative_path_to_file +def handle_existing_tool_dependencies_that_changed_in_update( app, repository, original_dependency_dict, new_dependency_dict ): + """ + This method is called when a Galaxy admin is getting updates for an installed tool shed repository in order to cover the case where an + existing tool dependency was changed (e.g., the version of the dependency was changed) but the tool version for which it is a dependency + was not changed. In this case, we only want to determine if any of the dependency information defined in original_dependency_dict was + changed in new_dependency_dict. We don't care if new dependencies were added in new_dependency_dict since they will just be treated as + missing dependencies for the tool. + """ + updated_tool_dependency_names = [] + deleted_tool_dependency_names = [] + for original_dependency_key, original_dependency_val_dict in original_dependency_dict.items(): + if original_dependency_key not in new_dependency_dict: + updated_tool_dependency = update_existing_tool_dependency( app, repository, original_dependency_val_dict, new_dependency_dict ) + if updated_tool_dependency: + updated_tool_dependency_names.append( updated_tool_dependency.name ) + else: + deleted_tool_dependency_names.append( original_dependency_val_dict[ 'name' ] ) + return updated_tool_dependency_names, deleted_tool_dependency_names def handle_sample_files_and_load_tool_from_disk( trans, repo_files_dir, tool_config_filepath, work_dir ): # Copy all sample files from disk to a temporary directory since the sample files may be in multiple directories. message = '' @@ -978,6 +996,21 @@ shutil.rmtree( dir ) except: pass +def remove_tool_dependency_installation_directory( dependency_install_dir ): + if os.path.exists( dependency_install_dir ): + try: + shutil.rmtree( dependency_install_dir ) + removed = True + error_message = '' + log.debug( "Removed tool dependency installation directory: %s" % str( dependency_install_dir ) ) + except Exception, e: + removed = False + error_message = "Error removing tool dependency installation directory %s: %s" % ( str( dependency_install_dir ), str( e ) ) + log.debug( error_message ) + else: + removed = True + error_message = '' + return removed, error_message def reset_all_metadata_on_installed_repository( trans, id ): """Reset all metadata on a single tool shed repository installed into a Galaxy instance.""" repository = get_installed_tool_shed_repository( trans, id ) @@ -1198,6 +1231,65 @@ except: file_name = fpath return file_name +def update_existing_tool_dependency( app, repository, original_dependency_dict, new_dependencies_dict ): + """ + Update an exsiting tool dependency whose definition was updated in a change set pulled by a Galaxy administrator when getting updates + to an installed tool shed repository. The original_dependency_dict is a single tool dependency definition, an example of which is:: + + {"name": "bwa", + "readme": "\\nCompiling BWA requires zlib and libpthread to be present on your system.\\n ", + "type": "package", + "version": "0.6.2"} + + The new_dependencies_dict is the dictionary generated by the generate_tool_dependency_metadata method. + """ + new_tool_dependency = None + original_name = original_dependency_dict[ 'name' ] + original_type = original_dependency_dict[ 'type' ] + original_version = original_dependency_dict[ 'version' ] + # Locate the appropriate tool_dependency associated with the repository. + tool_dependency = None + for tool_dependency in repository.tool_dependencies: + if tool_dependency.name == original_name and tool_dependency.type == original_type and tool_dependency.version == original_version: + break + if tool_dependency and tool_dependency.can_update: + dependency_install_dir = tool_dependency.installation_directory( app ) + removed_from_disk, error_message = remove_tool_dependency_installation_directory( dependency_install_dir ) + if removed_from_disk: + sa_session = app.model.context.current + new_dependency_name = None + new_dependency_type = None + new_dependency_version = None + for new_dependency_key, new_dependency_val_dict in new_dependencies_dict.items(): + # Match on name only, hopefully this will be enough! + if original_name == new_dependency_val_dict[ 'name' ]: + new_dependency_name = new_dependency_val_dict[ 'name' ] + new_dependency_type = new_dependency_val_dict[ 'type' ] + new_dependency_version = new_dependency_val_dict[ 'version' ] + break + if new_dependency_name and new_dependency_type and new_dependency_version: + # Update all attributes of the tool_dependency record in the database. + log.debug( "Updating tool dependency '%s' with type '%s' and version '%s' to have new type '%s' and version '%s'." % \ + ( str( tool_dependency.name ), + str( tool_dependency.type ), + str( tool_dependency.version ), + str( new_dependency_type ), + str( new_dependency_version ) ) ) + tool_dependency.type = new_dependency_type + tool_dependency.version = new_dependency_version + tool_dependency.status = app.model.ToolDependency.installation_status.UNINSTALLED + tool_dependency.error_message = None + sa_session.add( tool_dependency ) + sa_session.flush() + new_tool_dependency = tool_dependency + else: + # We have no new tool dependency definition based on a matching dependency name, so remove the existing tool dependency record + # from the database. + log.debug( "Deleting tool dependency with name '%s', type '%s' and version '%s' from the database since it is no longer defined." % \ + ( str( tool_dependency.name ), str( tool_dependency.type ), str( tool_dependency.version ) ) ) + sa_session.delete( tool_dependency ) + sa_session.flush() + return new_tool_dependency def update_repository( repo, ctx_rev=None ): """ Update the cloned repository to changeset_revision. It is critical that the installed repository is updated to the desired Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
Bitbucket