Пример #1
0
def generate_tool_guid(repository_clone_url, tool):
    """
    Generate a guid for the installed tool.  It is critical that this guid matches the guid for
    the tool in the Galaxy tool shed from which it is being installed.  The form of the guid is
    <tool shed host>/repos/<repository owner>/<repository name>/<tool id>/<tool version>
    """
    tmp_url = common_util.remove_protocol_and_user_from_clone_url(
        repository_clone_url)
    return f'{tmp_url}/{tool.id}/{tool.version}'
Пример #2
0
def generate_tool_shed_repository_install_dir(repository_clone_url, changeset_revision):
    """
    Generate a repository installation directory that guarantees repositories with the same
    name will always be installed in different directories.  The tool path will be of the form:
    <tool shed url>/repos/<repository owner>/<repository name>/<installed changeset revision>
    """
    tmp_url = common_util.remove_protocol_and_user_from_clone_url(repository_clone_url)
    # Now tmp_url is something like: bx.psu.edu:9009/repos/some_username/column
    items = tmp_url.split('/repos/')
    tool_shed_url = items[0]
    repo_path = items[1]
    tool_shed_url = common_util.remove_port_from_tool_shed_url(tool_shed_url)
    return '/'.join([tool_shed_url, 'repos', repo_path, changeset_revision])
Пример #3
0
 def generate_tool_panel_elem_list(self,
                                   repository_name,
                                   repository_clone_url,
                                   changeset_revision,
                                   tool_panel_dict,
                                   repository_tools_tups,
                                   owner=''):
     """Generate a list of ElementTree Element objects for each section or tool."""
     elem_list = []
     tool_elem = None
     cleaned_repository_clone_url = remove_protocol_and_user_from_clone_url(
         repository_clone_url)
     if not owner:
         owner = get_repository_owner(cleaned_repository_clone_url)
     tool_shed = cleaned_repository_clone_url.split('/repos/')[0].rstrip(
         '/')
     for guid, tool_section_dicts in tool_panel_dict.items():
         for tool_section_dict in tool_section_dicts:
             tool_section = None
             inside_section = False
             section_in_elem_list = None
             if tool_section_dict['id']:
                 inside_section = True
                 # Create a new section element only if we haven't already created it.
                 for index, elem in enumerate(elem_list):
                     if elem.tag == 'section':
                         section_id = elem.get('id', None)
                         if section_id == tool_section_dict['id']:
                             section_in_elem_list = index
                             tool_section = elem
                             break
                 if tool_section is None:
                     tool_section = self.generate_tool_section_element_from_dict(
                         tool_section_dict)
             # Find the tuple containing the current guid from the list of repository_tools_tups.
             for repository_tool_tup in repository_tools_tups:
                 tool_file_path, tup_guid, tool = repository_tool_tup
                 if tup_guid == guid:
                     break
             tool_elem = self.generate_tool_elem(
                 tool_shed, repository_name, changeset_revision, owner,
                 tool_file_path, tool,
                 tool_section if inside_section else None)
             if inside_section:
                 if section_in_elem_list is not None:
                     elem_list[section_in_elem_list] = tool_section
                 else:
                     elem_list.append(tool_section)
             else:
                 elem_list.append(tool_elem)
     return elem_list
Пример #4
0
 def update_in_shed_tool_config(self):
     """
     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.
     """
     shed_conf_dict = self.shed_config_dict or self.repository.get_shed_config_dict(
         self.app)
     shed_tool_conf = shed_conf_dict['config_filename']
     tool_path = shed_conf_dict['tool_path']
     self.tpm.generate_tool_panel_dict_from_shed_tool_conf_entries(
         self.repository)
     repository_tools_tups = self.get_repository_tools_tups()
     clone_url = common_util.generate_clone_url_for_installed_repository(
         self.app, self.repository)
     tool_shed = self.tool_shed_from_repository_clone_url()
     owner = self.repository.owner
     if not owner:
         cleaned_repository_clone_url = common_util.remove_protocol_and_user_from_clone_url(
             clone_url)
         owner = get_repository_owner(cleaned_repository_clone_url)
     guid_to_tool_elem_dict = {}
     for tool_config_filename, guid, tool in repository_tools_tups:
         guid_to_tool_elem_dict[guid] = self.tpm.generate_tool_elem(
             tool_shed, self.repository.name,
             self.repository.changeset_revision, self.repository.owner
             or '', tool_config_filename, tool, None)
     config_elems = []
     tree, error_message = xml_util.parse_xml(shed_tool_conf)
     if tree:
         root = tree.getroot()
         for elem in root:
             if elem.tag == 'section':
                 for i, tool_elem in enumerate(elem):
                     guid = tool_elem.attrib.get('guid')
                     if guid in guid_to_tool_elem_dict:
                         elem[i] = guid_to_tool_elem_dict[guid]
             elif elem.tag == 'tool':
                 guid = elem.attrib.get('guid')
                 if guid in guid_to_tool_elem_dict:
                     elem = guid_to_tool_elem_dict[guid]
             config_elems.append(elem)
         self.tpm.config_elems_to_xml_file(config_elems, shed_tool_conf,
                                           tool_path)
Пример #5
0
 def tool_shed_from_repository_clone_url(self):
     """Given a repository clone URL, return the tool shed that contains the repository."""
     cleaned_repository_clone_url = common_util.remove_protocol_and_user_from_clone_url(
         self.repository_clone_url)
     return common_util.remove_protocol_and_user_from_clone_url(
         cleaned_repository_clone_url).split('/repos/')[0].rstrip('/')
Пример #6
0
def get_tool_shed_from_clone_url(repository_clone_url):
    tmp_url = common_util.remove_protocol_and_user_from_clone_url(
        repository_clone_url)
    return tmp_url.split('/repos/')[0].rstrip('/')
Пример #7
0
def get_repository_owner_from_clone_url(repository_clone_url):
    """Given a repository clone URL, return the owner of the repository."""
    tmp_url = common_util.remove_protocol_and_user_from_clone_url(
        repository_clone_url)
    return get_repository_owner(tmp_url)