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 = common_util.remove_protocol_and_user_from_clone_url( repository_clone_url ) if not owner: owner = suc.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 = False 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 = True 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 if inside_section: tool_elem = self.generate_tool_elem( tool_shed, repository_name, changeset_revision, owner, tool_file_path, tool, tool_section ) else: tool_elem = self.generate_tool_elem( tool_shed, repository_name, changeset_revision, owner, tool_file_path, tool, None ) if inside_section: if section_in_elem_list: elem_list[ index ] = tool_section else: elem_list.append( tool_section ) else: elem_list.append( tool_elem ) return elem_list
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 = common_util.remove_protocol_and_user_from_clone_url( repository_clone_url) if not owner: owner = suc.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 = False 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 = True 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 if inside_section: tool_elem = self.generate_tool_elem( tool_shed, repository_name, changeset_revision, owner, tool_file_path, tool, tool_section) else: tool_elem = self.generate_tool_elem( tool_shed, repository_name, changeset_revision, owner, tool_file_path, tool, None) if inside_section: if section_in_elem_list: elem_list[index] = tool_section else: elem_list.append(tool_section) else: elem_list.append(tool_elem) return elem_list
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.repository.get_shed_config_dict(self.app) shed_tool_conf = shed_conf_dict['config_filename'] tool_path = shed_conf_dict['tool_path'] tool_panel_dict = 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 = suc.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)
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.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 = suc.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 )