def get_latest_tool_config_revision_from_repository_manifest( self, repo, filename, changeset_revision ):
     """
     Get the latest revision of a tool config file named filename from the repository
     manifest up to the value of changeset_revision.  This method is restricted to tool_config
     files rather than any file since it is likely that, with the exception of tool config
     files, multiple files will have the same name in various directories within the repository.
     """
     stripped_filename = basic_util.strip_path( filename )
     for changeset in hg_util.reversed_upper_bounded_changelog( repo, changeset_revision ):
         manifest_ctx = repo.changectx( changeset )
         for ctx_file in manifest_ctx.files():
             ctx_file_name = basic_util.strip_path( ctx_file )
             if ctx_file_name == stripped_filename:
                 try:
                     fctx = manifest_ctx[ ctx_file ]
                 except LookupError:
                     # The ctx_file may have been moved in the change set.  For example,
                     # 'ncbi_blastp_wrapper.xml' was moved to 'tools/ncbi_blast_plus/ncbi_blastp_wrapper.xml',
                     # so keep looking for the file until we find the new location.
                     continue
                 fh = tempfile.NamedTemporaryFile( 'wb', prefix="tmp-toolshed-gltcrfrm" )
                 tmp_filename = fh.name
                 fh.close()
                 fh = open( tmp_filename, 'wb' )
                 fh.write( fctx.data() )
                 fh.close()
                 return tmp_filename
     return None
 def get_version_lineage_for_tool( self, repository_id, repository_metadata, guid ):
     """
     Return the tool version lineage chain in descendant order for the received
     guid contained in the received repsitory_metadata.tool_versions.  This function
     is called only from the Tool Shed.
     """
     repository = suc.get_repository_by_id( self.app, repository_id )
     repo = hg_util.get_repo_for_repository( self.app, repository=repository, repo_path=None, create=False )
     # Initialize the tool lineage
     version_lineage = [ guid ]
     # Get all ancestor guids of the received guid.
     current_child_guid = guid
     for changeset in hg_util.reversed_upper_bounded_changelog( repo, repository_metadata.changeset_revision ):
         ctx = repo.changectx( changeset )
         rm = suc.get_repository_metadata_by_changeset_revision( self.app, repository_id, str( ctx ) )
         if rm:
             parent_guid = rm.tool_versions.get( current_child_guid, None )
             if parent_guid:
                 version_lineage.append( parent_guid )
                 current_child_guid = parent_guid
     # Get all descendant guids of the received guid.
     current_parent_guid = guid
     for changeset in hg_util.reversed_lower_upper_bounded_changelog( repo,
                                                                      repository_metadata.changeset_revision,
                                                                      repository.tip( self.app ) ):
         ctx = repo.changectx( changeset )
         rm = suc.get_repository_metadata_by_changeset_revision( self.app, repository_id, str( ctx ) )
         if rm:
             tool_versions = rm.tool_versions
             for child_guid, parent_guid in tool_versions.items():
                 if parent_guid == current_parent_guid:
                     version_lineage.insert( 0, child_guid )
                     current_parent_guid = child_guid
                     break
     return version_lineage
Esempio n. 3
0
 def get_version_lineage_for_tool(self, repository_id, repository_metadata, guid):
     """
     Return the tool version lineage chain in descendant order for the received
     guid contained in the received repsitory_metadata.tool_versions.  This function
     is called only from the Tool Shed.
     """
     repository = repository_util.get_repository_by_id(self.app, repository_id)
     repo = hg_util.get_repo_for_repository(self.app, repository=repository)
     # Initialize the tool lineage
     version_lineage = [guid]
     # Get all ancestor guids of the received guid.
     current_child_guid = guid
     for changeset in hg_util.reversed_upper_bounded_changelog(repo, repository_metadata.changeset_revision):
         ctx = repo.changectx(changeset)
         rm = metadata_util.get_repository_metadata_by_changeset_revision(self.app, repository_id, str(ctx))
         if rm:
             parent_guid = rm.tool_versions.get(current_child_guid, None)
             if parent_guid:
                 version_lineage.append(parent_guid)
                 current_child_guid = parent_guid
     # Get all descendant guids of the received guid.
     current_parent_guid = guid
     for changeset in hg_util.reversed_lower_upper_bounded_changelog(repo,
                                                                     repository_metadata.changeset_revision,
                                                                     repository.tip(self.app)):
         ctx = repo.changectx(changeset)
         rm = metadata_util.get_repository_metadata_by_changeset_revision(self.app, repository_id, str(ctx))
         if rm:
             tool_versions = rm.tool_versions
             for child_guid, parent_guid in tool_versions.items():
                 if parent_guid == current_parent_guid:
                     version_lineage.insert(0, child_guid)
                     current_parent_guid = child_guid
                     break
     return version_lineage
Esempio n. 4
0
def get_previous_repository_reviews(app, repository, changeset_revision):
    """
    Return an ordered dictionary of repository reviews up to and including the
    received changeset revision.
    """
    repo = hg_util.get_repo_for_repository(app,
                                           repository=repository,
                                           repo_path=None,
                                           create=False)
    reviewed_revision_hashes = [
        review.changeset_revision for review in repository.reviews
    ]
    previous_reviews_dict = odict()
    for changeset in hg_util.reversed_upper_bounded_changelog(
            repo, changeset_revision):
        previous_changeset_revision = str(repo.changectx(changeset))
        if previous_changeset_revision in reviewed_revision_hashes:
            previous_rev, previous_changeset_revision_label = \
                hg_util.get_rev_label_from_changeset_revision(repo, previous_changeset_revision)
            revision_reviews = get_reviews_by_repository_id_changeset_revision(
                app, app.security.encode_id(repository.id),
                previous_changeset_revision)
            previous_reviews_dict[previous_changeset_revision] = \
                dict(changeset_revision_label=previous_changeset_revision_label,
                     reviews=revision_reviews)
    return previous_reviews_dict
Esempio n. 5
0
def has_previous_repository_reviews( app, repository, changeset_revision ):
    """
    Determine if a repository has a changeset revision review prior to the
    received changeset revision.
    """
    repo = hg_util.get_repo_for_repository( app, repository=repository, repo_path=None, create=False )
    reviewed_revision_hashes = [ review.changeset_revision for review in repository.reviews ]
    for changeset in hg_util.reversed_upper_bounded_changelog( repo, changeset_revision ):
        previous_changeset_revision = str( repo.changectx( changeset ) )
        if previous_changeset_revision in reviewed_revision_hashes:
            return True
    return False
Esempio n. 6
0
def has_previous_repository_reviews(app, repository, changeset_revision):
    """
    Determine if a repository has a changeset revision review prior to the
    received changeset revision.
    """
    repo = repository.hg_repo
    reviewed_revision_hashes = [
        review.changeset_revision for review in repository.reviews
    ]
    for changeset in hg_util.reversed_upper_bounded_changelog(
            repo, changeset_revision):
        previous_changeset_revision = str(repo[changeset])
        if previous_changeset_revision in reviewed_revision_hashes:
            return True
    return False
Esempio n. 7
0
 def get_list_of_copied_sample_files(self, repo, changeset_revision, dir):
     """
     Find all sample files (files in the repository with the special .sample extension)
     in the reversed repository manifest up to changeset_revision. Copy each discovered file to dir and
     return the list of filenames.  If a .sample file was added in a changeset and then
     deleted in a later changeset, it will be returned in the deleted_sample_files list.
     The caller will set the value of app.config.tool_data_path to dir in order to load
     the tools and generate metadata for them.
     """
     deleted_sample_files = []
     sample_files = []
     for changeset in hg_util.reversed_upper_bounded_changelog(
             repo, changeset_revision):
         changeset_ctx = repo[changeset]
         for ctx_file in changeset_ctx.files():
             ctx_file = unicodify(ctx_file)
             ctx_file_name = basic_util.strip_path(ctx_file)
             # If we decide in the future that files deleted later in the changelog should
             # not be used, we can use the following if statement. if ctx_file_name.endswith( '.sample' )
             # and ctx_file_name not in sample_files and ctx_file_name not in deleted_sample_files:
             if ctx_file_name.endswith(
                     '.sample') and ctx_file_name not in sample_files:
                 fctx = hg_util.get_file_context_from_ctx(
                     changeset_ctx, ctx_file)
                 if fctx in ['DELETED']:
                     # Since the possibly future used if statement above is commented out, the
                     # same file that was initially added will be discovered in an earlier changeset
                     # in the change log and fall through to the else block below.  In other words,
                     # if a file named blast2go.loc.sample was added in change set 0 and then deleted
                     # in changeset 3, the deleted file in changeset 3 will be handled here, but the
                     # later discovered file in changeset 0 will be handled in the else block below.
                     # In this way, the file contents will always be found for future tools even though
                     # the file was deleted.
                     if ctx_file_name not in deleted_sample_files:
                         deleted_sample_files.append(ctx_file_name)
                 else:
                     sample_files.append(ctx_file_name)
                     tmp_ctx_file_name = os.path.join(
                         dir, ctx_file_name.replace('.sample', ''))
                     with open(tmp_ctx_file_name, 'wb') as fh:
                         fh.write(fctx.data())
     return sample_files, deleted_sample_files
Esempio n. 8
0
def get_previous_repository_reviews( app, repository, changeset_revision ):
    """
    Return an ordered dictionary of repository reviews up to and including the
    received changeset revision.
    """
    repo = hg_util.get_repo_for_repository( app, repository=repository, repo_path=None, create=False )
    reviewed_revision_hashes = [ review.changeset_revision for review in repository.reviews ]
    previous_reviews_dict = odict()
    for changeset in hg_util.reversed_upper_bounded_changelog( repo, changeset_revision ):
        previous_changeset_revision = str( repo.changectx( changeset ) )
        if previous_changeset_revision in reviewed_revision_hashes:
            previous_rev, previous_changeset_revision_label = \
                hg_util.get_rev_label_from_changeset_revision( repo, previous_changeset_revision )
            revision_reviews = get_reviews_by_repository_id_changeset_revision( app,
                                                                                app.security.encode_id( repository.id ),
                                                                                previous_changeset_revision )
            previous_reviews_dict[ previous_changeset_revision ] = \
                dict( changeset_revision_label=previous_changeset_revision_label,
                      reviews=revision_reviews )
    return previous_reviews_dict
 def get_list_of_copied_sample_files( self, repo, ctx, dir ):
     """
     Find all sample files (files in the repository with the special .sample extension)
     in the reversed repository manifest up to ctx.  Copy each discovered file to dir and
     return the list of filenames.  If a .sample file was added in a changeset and then
     deleted in a later changeset, it will be returned in the deleted_sample_files list.
     The caller will set the value of app.config.tool_data_path to dir in order to load
     the tools and generate metadata for them.
     """
     deleted_sample_files = []
     sample_files = []
     for changeset in hg_util.reversed_upper_bounded_changelog( repo, ctx ):
         changeset_ctx = repo.changectx( changeset )
         for ctx_file in changeset_ctx.files():
             ctx_file_name = basic_util.strip_path( ctx_file )
             # If we decide in the future that files deleted later in the changelog should
             # not be used, we can use the following if statement. if ctx_file_name.endswith( '.sample' )
             # and ctx_file_name not in sample_files and ctx_file_name not in deleted_sample_files:
             if ctx_file_name.endswith( '.sample' ) and ctx_file_name not in sample_files:
                 fctx = hg_util.get_file_context_from_ctx( changeset_ctx, ctx_file )
                 if fctx in [ 'DELETED' ]:
                     # Since the possibly future used if statement above is commented out, the
                     # same file that was initially added will be discovered in an earlier changeset
                     # in the change log and fall through to the else block below.  In other words,
                     # if a file named blast2go.loc.sample was added in change set 0 and then deleted
                     # in changeset 3, the deleted file in changeset 3 will be handled here, but the
                     # later discovered file in changeset 0 will be handled in the else block below.
                     # In this way, the file contents will always be found for future tools even though
                     # the file was deleted.
                     if ctx_file_name not in deleted_sample_files:
                         deleted_sample_files.append( ctx_file_name )
                 else:
                     sample_files.append( ctx_file_name )
                     tmp_ctx_file_name = os.path.join( dir, ctx_file_name.replace( '.sample', '' ) )
                     fh = open( tmp_ctx_file_name, 'wb' )
                     fh.write( fctx.data() )
                     fh.close()
     return sample_files, deleted_sample_files