Ejemplo n.º 1
0
 def get_containing_tool_sections( self, tool_config ):
     """
     If tool_config is defined somewhere in self.proprietary_tool_panel_elems, return True and a list of ToolSections in which the
     tool is displayed.  If the tool is displayed outside of any sections, None is appended to the list.
     """
     tool_sections = []
     is_displayed = False
     for proprietary_tool_panel_elem in self.proprietary_tool_panel_elems:
         if proprietary_tool_panel_elem.tag == 'tool':
             # The proprietary_tool_panel_elem looks something like <tool file="emboss_5/emboss_antigenic.xml" />.
             proprietary_tool_config = proprietary_tool_panel_elem.get( 'file' )
             proprietary_name = suc.strip_path( proprietary_tool_config )
             if tool_config == proprietary_name:
                 # The tool is loaded outside of any sections.
                 tool_sections.append( None )
                 if not is_displayed:
                     is_displayed = True
         if proprietary_tool_panel_elem.tag == 'section':
             # The proprietary_tool_panel_elem looks something like <section name="EMBOSS" id="EMBOSSLite">.
             for section_elem in proprietary_tool_panel_elem:
                 if section_elem.tag == 'tool':
                     # The section_elem looks something like <tool file="emboss_5/emboss_antigenic.xml" />.
                     proprietary_tool_config = section_elem.get( 'file' )
                     proprietary_name = suc.strip_path( proprietary_tool_config )
                     if tool_config == proprietary_name:
                         # The tool is loaded inside of the section_elem.
                         tool_sections.append( ToolSection( proprietary_tool_panel_elem ) )
                         if not is_displayed:
                             is_displayed = True
     return is_displayed, tool_sections
Ejemplo n.º 2
0
 def get_containing_tool_sections( self, tool_config ):
     """
     If tool_config is defined somewhere in self.proprietary_tool_panel_elems, return True and a list of ToolSections in which the
     tool is displayed.  If the tool is displayed outside of any sections, None is appended to the list.
     """
     tool_sections = []
     is_displayed = False
     for proprietary_tool_panel_elem in self.proprietary_tool_panel_elems:
         if proprietary_tool_panel_elem.tag == 'tool':
             # The proprietary_tool_panel_elem looks something like <tool file="emboss_5/emboss_antigenic.xml" />.
             proprietary_tool_config = proprietary_tool_panel_elem.get( 'file' )
             proprietary_name = suc.strip_path( proprietary_tool_config )
             if tool_config == proprietary_name:
                 # The tool is loaded outside of any sections.
                 tool_sections.append( None )
                 if not is_displayed:
                     is_displayed = True
         if proprietary_tool_panel_elem.tag == 'section':
             # The proprietary_tool_panel_elem looks something like <section name="EMBOSS" id="EMBOSSLite">.
             for section_elem in proprietary_tool_panel_elem:
                 if section_elem.tag == 'tool':
                     # The section_elem looks something like <tool file="emboss_5/emboss_antigenic.xml" />.
                     proprietary_tool_config = section_elem.get( 'file' )
                     proprietary_name = suc.strip_path( proprietary_tool_config )
                     if tool_config == proprietary_name:
                         # The tool is loaded inside of the section_elem.
                         tool_sections.append( ToolSection( proprietary_tool_panel_elem ) )
                         if not is_displayed:
                             is_displayed = True
     return is_displayed, tool_sections
Ejemplo n.º 3
0
 def get_guid( self, repository_clone_url, relative_install_dir, tool_config ):
     if self.shed_config_dict.get( 'tool_path' ):
         relative_install_dir = os.path.join( self.shed_config_dict[ 'tool_path' ], relative_install_dir )
     tool_config_filename = suc.strip_path( tool_config )
     for root, dirs, files in os.walk( relative_install_dir ):
         if root.find( '.hg' ) < 0 and root.find( 'hgrc' ) < 0:
             if '.hg' in dirs:
                 dirs.remove( '.hg' )
             for name in files:
                 filename = suc.strip_path( name )
                 if filename == tool_config_filename:
                     full_path = str( os.path.abspath( os.path.join( root, name ) ) )
                     tool = self.toolbox.load_tool( full_path )
                     return suc.generate_tool_guid( repository_clone_url, tool )
     # Not quite sure what should happen here, throw an exception or what?
     return None
Ejemplo n.º 4
0
 def get_proprietary_tool_panel_elems( self, latest_tool_migration_script_number ):
     """
     Parse each config in self.proprietary_tool_confs (the default is tool_conf.xml) and generate a list of Elements that are
     either ToolSection elements or Tool elements.  These will be used to generate new entries in the migrated_tools_conf.xml
     file for the installed tools.
     """
     tools_xml_file_path = os.path.abspath( os.path.join( 'scripts', 'migrate_tools', '%04d_tools.xml' % latest_tool_migration_script_number ) )
     # Parse the XML and load the file attributes for later checking against the integrated elements from self.proprietary_tool_confs.
     migrated_tool_configs = []
     tree, error_message = xml_util.parse_xml( tools_xml_file_path )
     if tree is None:
         return []
     root = tree.getroot()
     for elem in root:
         if elem.tag == 'repository':
             for tool_elem in elem:
                 migrated_tool_configs.append( tool_elem.get( 'file' ) )
     # Parse each file in self.proprietary_tool_confs and generate the integrated list of tool panel Elements that contain them.
     tool_panel_elems = []
     for proprietary_tool_conf in self.proprietary_tool_confs:
         tree, error_message = xml_util.parse_xml( proprietary_tool_conf )
         if tree is None:
             return []
         root = tree.getroot()
         for elem in root:
             if elem.tag == 'tool':
                 # Tools outside of sections.
                 file_path = elem.get( 'file', None )
                 if file_path:
                     name = suc.strip_path( file_path )
                     if name in migrated_tool_configs:
                         if elem not in tool_panel_elems:
                             tool_panel_elems.append( elem )
             elif elem.tag == 'section':
                 # Tools contained in a section.
                 for section_elem in elem:
                     if section_elem.tag == 'tool':
                         file_path = section_elem.get( 'file', None )
                         if file_path:
                             name = suc.strip_path( file_path )
                             if name in migrated_tool_configs:
                                 # Append the section, not the tool.
                                 if elem not in tool_panel_elems:
                                     tool_panel_elems.append( elem )
     return tool_panel_elems
Ejemplo n.º 5
0
 def get_proprietary_tool_panel_elems( self, latest_tool_migration_script_number ):
     # Parse each config in self.proprietary_tool_confs (the default is tool_conf.xml) and generate a list of Elements that are
     # either ToolSection elements or Tool elements.  These will be used to generate new entries in the migrated_tools_conf.xml
     # file for the installed tools.
     tools_xml_file_path = os.path.abspath( os.path.join( 'scripts', 'migrate_tools', '%04d_tools.xml' % latest_tool_migration_script_number ) )
     # Parse the XML and load the file attributes for later checking against the integrated elements from self.proprietary_tool_confs.
     migrated_tool_configs = []
     tree, error_message = xml_util.parse_xml( tools_xml_file_path )
     if tree is None:
         return []
     root = tree.getroot()
     for elem in root:
         if elem.tag == 'repository':
             for tool_elem in elem:
                 migrated_tool_configs.append( tool_elem.get( 'file' ) )
     # Parse each file in self.proprietary_tool_confs and generate the integrated list of tool panel Elements that contain them.
     tool_panel_elems = []
     for proprietary_tool_conf in self.proprietary_tool_confs:
         tree, error_message = xml_util.parse_xml( proprietary_tool_conf )
         if tree is None:
             return []
         root = tree.getroot()
         for elem in root:
             if elem.tag == 'tool':
                 # Tools outside of sections.
                 file_path = elem.get( 'file', None )
                 if file_path:
                     name = suc.strip_path( file_path )
                     if name in migrated_tool_configs:
                         if elem not in tool_panel_elems:
                             tool_panel_elems.append( elem )
             elif elem.tag == 'section':
                 # Tools contained in a section.
                 for section_elem in elem:
                     if section_elem.tag == 'tool':
                         file_path = section_elem.get( 'file', None )
                         if file_path:
                             name = suc.strip_path( file_path )
                             if name in migrated_tool_configs:
                                 # Append the section, not the tool.
                                 if elem not in tool_panel_elems:
                                     tool_panel_elems.append( elem )
     return tool_panel_elems
Ejemplo n.º 6
0
def get_converter_and_display_paths(registration_elem, relative_install_dir):
    """Find the relative path to data type converters and display applications included in installed tool shed repositories."""
    converter_path = None
    display_path = None
    for elem in registration_elem.findall('datatype'):
        if not converter_path:
            # If any of the <datatype> tag sets contain <converter> tags, set the converter_path
            # if it is not already set.  This requires developers to place all converters in the
            # same subdirectory within the repository hierarchy.
            for converter in elem.findall('converter'):
                converter_config = converter.get('file', None)
                if converter_config:
                    converter_config_file_name = suc.strip_path(
                        converter_config)
                    for root, dirs, files in os.walk(relative_install_dir):
                        if root.find('.hg') < 0:
                            for name in files:
                                if name == converter_config_file_name:
                                    # The value of converter_path must be absolute due to job_working_directory.
                                    converter_path = os.path.abspath(root)
                                    break
                if converter_path:
                    break
        if not display_path:
            # If any of the <datatype> tag sets contain <display> tags, set the display_path
            # if it is not already set.  This requires developers to place all display acpplications
            # in the same subdirectory within the repository hierarchy.
            for display_app in elem.findall('display'):
                display_config = display_app.get('file', None)
                if display_config:
                    display_config_file_name = suc.strip_path(display_config)
                    for root, dirs, files in os.walk(relative_install_dir):
                        if root.find('.hg') < 0:
                            for name in files:
                                if name == display_config_file_name:
                                    # The value of display_path must be absolute due to job_working_directory.
                                    display_path = os.path.abspath(root)
                                    break
                if display_path:
                    break
        if converter_path and display_path:
            break
    return converter_path, display_path
Ejemplo n.º 7
0
def get_converter_and_display_paths( registration_elem, relative_install_dir ):
    """Find the relative path to data type converters and display applications included in installed tool shed repositories."""
    converter_path = None
    display_path = None
    for elem in registration_elem.findall( 'datatype' ):
        if not converter_path:
            # If any of the <datatype> tag sets contain <converter> tags, set the converter_path
            # if it is not already set.  This requires developers to place all converters in the
            # same subdirectory within the repository hierarchy.
            for converter in elem.findall( 'converter' ):
                converter_config = converter.get( 'file', None )
                if converter_config:
                    converter_config_file_name = suc.strip_path( converter_config )
                    for root, dirs, files in os.walk( relative_install_dir ):
                        if root.find( '.hg' ) < 0:
                            for name in files:
                                if name == converter_config_file_name:
                                    # The value of converter_path must be absolute due to job_working_directory.
                                    converter_path = os.path.abspath( root )
                                    break
                if converter_path:
                    break
        if not display_path:
            # If any of the <datatype> tag sets contain <display> tags, set the display_path
            # if it is not already set.  This requires developers to place all display acpplications
            # in the same subdirectory within the repository hierarchy.
            for display_app in elem.findall( 'display' ):
                display_config = display_app.get( 'file', None )
                if display_config:
                    display_config_file_name = suc.strip_path( display_config )
                    for root, dirs, files in os.walk( relative_install_dir ):
                        if root.find( '.hg' ) < 0:
                            for name in files:
                                if name == display_config_file_name:
                                    # The value of display_path must be absolute due to job_working_directory.
                                    display_path = os.path.abspath( root )
                                    break
                if display_path:
                    break
        if converter_path and display_path:
            break
    return converter_path, display_path
Ejemplo n.º 8
0
    def filter_and_persist_proprietary_tool_panel_configs( self, tool_configs_to_filter ):
        """Eliminate all entries in all non-shed-related tool panel configs for all tool config file names in the received tool_configs_to_filter."""
        for proprietary_tool_conf in self.proprietary_tool_confs:
            persist_required = False
            tree, error_message = xml_util.parse_xml( proprietary_tool_conf )
            if tree:
                root = tree.getroot()
                for elem in root:
                    if elem.tag == 'tool':
                        # Tools outside of sections.
                        file_path = elem.get( 'file', None )
                        if file_path:
                            file_name = suc.strip_path( file_path )
                            if file_name in tool_configs_to_filter:
                                root.remove( elem )
                                persist_required = True
                    elif elem.tag == 'section':
                        # Tools contained in a section.
                        for section_elem in elem:
                            if section_elem.tag == 'tool':
                                file_path = section_elem.get( 'file', None )
                                if file_path:
                                    file_name = suc.strip_path( file_path )

                                    if file_name in tool_configs_to_filter:
                                        elem.remove( section_elem )
                                        persist_required = True
            if persist_required:
                fh = tempfile.NamedTemporaryFile( 'wb', prefix="tmp-toolshed-fapptpc"  )
                tmp_filename = fh.name
                fh.close()
                fh = open( tmp_filename, 'wb' )
                tree.write( tmp_filename, encoding='utf-8', xml_declaration=True )
                fh.close()
                shutil.move( tmp_filename, os.path.abspath( proprietary_tool_conf ) )
                os.chmod( proprietary_tool_conf, 0644 )
 def is_valid_for_type( self, app, repository, revisions_to_check=None ):
     """
     Inspect the received repository's contents to determine if they abide by the rules defined for the contents of this type.
     If the received revisions_to_check is a list of changeset revisions, then inspection will be restricted to the revisions
     in the list.
     """
     repo = hg.repository( ui.ui(), repository.repo_path( app ) )
     if revisions_to_check:
         changeset_revisions = revisions_to_check
     else:
         changeset_revisions = repo.changelog
     for changeset in changeset_revisions:
         changeset_revision = str( repo.changectx( changeset ) )
         ctx = repo.changectx( changeset )
         # Inspect all files in the changeset (in sorted order) to make sure there is only one and it is named tool_dependencies.xml.
         files_changed_in_changeset = ctx.files()
         for file_path in files_changed_in_changeset:
             file_name = suc.strip_path( file_path )
             if file_name not in self.valid_file_names:
                 return False
     return True
Ejemplo n.º 10
0
 def is_valid_for_type(self, app, repository, revisions_to_check=None):
     """
     Inspect the received repository's contents to determine if they abide by the rules defined for the contents of this type.
     If the received revisions_to_check is a list of changeset revisions, then inspection will be restricted to the revisions
     in the list.
     """
     repo = hg.repository(ui.ui(), repository.repo_path(app))
     if revisions_to_check:
         changeset_revisions = revisions_to_check
     else:
         changeset_revisions = repo.changelog
     for changeset in changeset_revisions:
         changeset_revision = str(repo.changectx(changeset))
         ctx = repo.changectx(changeset)
         # Inspect all files in the changeset (in sorted order) to make sure there is only one and it is named tool_dependencies.xml.
         files_changed_in_changeset = ctx.files()
         for file_path in files_changed_in_changeset:
             file_name = suc.strip_path(file_path)
             if file_name not in self.valid_file_names:
                 return False
     return True