Commit 84dfd954 authored by John Chilton's avatar John Chilton
Browse files

Remove a bunch of tool dependency utility code now unused.

parent cad6ff35
Loading
Loading
Loading
Loading
+0 −155
Original line number Diff line number Diff line
@@ -5,107 +5,10 @@ import shutil
from sqlalchemy import and_

from galaxy import util
from galaxy.web.form_builder import SelectField

log = logging.getLogger(__name__)


def build_tool_dependencies_select_field(
    app, tool_shed_repository, name, multiple=True, display="checkboxes", uninstalled_only=False
):
    """
    Generate a SelectField consisting of the current list of tool dependency ids
    for an installed tool shed repository.
    """
    tool_dependencies_select_field = SelectField(name=name, multiple=multiple, display=display)
    for tool_dependency in tool_shed_repository.tool_dependencies:
        if uninstalled_only:
            if tool_dependency.status not in [
                app.install_model.ToolDependency.installation_status.NEVER_INSTALLED,
                app.install_model.ToolDependency.installation_status.UNINSTALLED,
            ]:
                continue
        else:
            if tool_dependency.status in [
                app.install_model.ToolDependency.installation_status.NEVER_INSTALLED,
                app.install_model.ToolDependency.installation_status.UNINSTALLED,
            ]:
                continue
        option_label = f"{tool_dependency.name} version {tool_dependency.version}"
        option_value = app.security.encode_id(tool_dependency.id)
        tool_dependencies_select_field.add_option(option_label, option_value)
    return tool_dependencies_select_field


def create_or_update_tool_dependency(app, tool_shed_repository, name, version, type, status, set_status=True):
    """Create or update a tool_dependency record in the Galaxy database."""
    # Called from Galaxy (never the tool shed) when a new repository is being installed or when an uninstalled
    # repository is being reinstalled.
    context = app.install_model.context
    # First see if an appropriate tool_dependency record exists for the received tool_shed_repository.
    if version:
        tool_dependency = get_tool_dependency_by_name_version_type_repository(
            app, tool_shed_repository, name, version, type
        )
    else:
        tool_dependency = get_tool_dependency_by_name_type_repository(app, tool_shed_repository, name, type)
    if tool_dependency:
        # In some cases we should not override the current status of an existing tool_dependency, so do so only
        # if set_status is True.
        if set_status:
            set_tool_dependency_attributes(app, tool_dependency=tool_dependency, status=status)
    else:
        # Create a new tool_dependency record for the tool_shed_repository.
        debug_msg = f"Creating a new record for version {version} of tool dependency {name} for revision {tool_shed_repository.changeset_revision} of repository {tool_shed_repository.name}.  "
        debug_msg += f"The status is being set to {status}."
        log.debug(debug_msg)
        tool_dependency = app.install_model.ToolDependency(tool_shed_repository.id, name, version, type, status)
        context.add(tool_dependency)
        context.flush()
    return tool_dependency


def get_download_url_for_platform(url_templates, platform_info_dict):
    """
    Compare the dict returned by get_platform_info() with the values specified in the url_template element. Return
    true if and only if all defined attributes match the corresponding dict entries. If an entry is not
    defined in the url_template element, it is assumed to be irrelevant at this stage. For example,
    <url_template os="darwin">http://hgdownload.cse.ucsc.edu/admin/exe/macOSX.${architecture}/faToTwoBit</url_template>
    where the OS must be 'darwin', but the architecture is filled in later using string.Template.
    """
    os_ok = False
    architecture_ok = False
    for url_template in url_templates:
        os_name = url_template.get("os", None)
        architecture = url_template.get("architecture", None)
        if os_name:
            if os_name.lower() == platform_info_dict["os"]:
                os_ok = True
            else:
                os_ok = False
        else:
            os_ok = True
        if architecture:
            if architecture.lower() == platform_info_dict["architecture"]:
                architecture_ok = True
            else:
                architecture_ok = False
        else:
            architecture_ok = True
        if os_ok and architecture_ok:
            return url_template
    return None


def get_platform_info_dict():
    """Return a dict with information about the current platform."""
    platform_dict = {}
    sysname, nodename, release, version, machine = os.uname()
    platform_dict["os"] = sysname.lower()
    platform_dict["architecture"] = machine.lower()
    return platform_dict


def get_tool_dependency(app, id):
    """Get a tool_dependency from the database via id"""
    return app.install_model.context.query(app.install_model.ToolDependency).get(app.security.decode_id(id))
@@ -176,39 +79,6 @@ def get_tool_dependency_ids(as_string=False, **kwd):
    return tool_dependency_ids


def get_tool_dependency_install_dir(
    app,
    repository_name,
    repository_owner,
    repository_changeset_revision,
    tool_dependency_type,
    tool_dependency_name,
    tool_dependency_version,
):
    if tool_dependency_type == "package":
        return os.path.abspath(
            os.path.join(
                app.tool_dependency_dir,
                tool_dependency_name,
                tool_dependency_version,
                repository_owner,
                repository_name,
                repository_changeset_revision,
            )
        )
    if tool_dependency_type == "set_environment":
        return os.path.abspath(
            os.path.join(
                app.tool_dependency_dir,
                "environment_settings",
                tool_dependency_name,
                repository_owner,
                repository_name,
                repository_changeset_revision,
            )
        )


def parse_package_elem(package_elem, platform_info_dict=None, include_after_install_actions=True):
    """
    Parse a <package> element within a tool dependency definition and return a list of action tuples.
@@ -367,28 +237,3 @@ def remove_tool_dependency_installation_directory(dependency_install_dir):
        removed = True
        error_message = ""
    return removed, error_message


def set_tool_dependency_attributes(app, tool_dependency, status, error_message=None):
    sa_session = app.install_model.context
    if status == app.install_model.ToolDependency.installation_status.UNINSTALLED:
        installation_directory = tool_dependency.installation_directory(app)
        remove_tool_dependency_installation_directory(installation_directory)
    tool_dependency.error_message = error_message
    if str(tool_dependency.status) != str(status):
        tool_shed_repository = tool_dependency.tool_shed_repository
        debug_msg = (
            "Updating an existing record for version %s of tool dependency %s for revision %s of repository %s "
            % (
                str(tool_dependency.version),
                str(tool_dependency.name),
                str(tool_shed_repository.changeset_revision),
                str(tool_shed_repository.name),
            )
        )
        debug_msg += f"by updating the status from {tool_dependency.status} to {status}."
        log.debug(debug_msg)
    tool_dependency.status = status
    sa_session.add(tool_dependency)
    sa_session.flush()
    return tool_dependency