def gen_manifest_artifact_files(file_names, collection_path, chksum_type=None):
    # file_names = file_names or []
    file_names = file_names or []
    default_chksum_type = chksum_type or 'sha256'

    for file_name in file_names:

        current_chksum_type = default_chksum_type

        # TODO: enum
        if os.path.isfile(file_name):
            ftype = 'file'
        if os.path.isdir(file_name):
            ftype = 'dir'

        chksum = None
        if ftype == 'file':
            chksum = chksums.sha256sum_from_path(file_name)
        else:
            chksum = None
            current_chksum_type = None

        dest_relative_path = os.path.relpath(file_name, collection_path)
        arcname = dest_relative_path

        artifact_file = CollectionArtifactFile(
            src_name=file_name,
            # The path where the file will live inside the archive
            name=arcname,
            ftype=ftype,
            chksum_type=current_chksum_type,
            chksum_sha256=chksum)

        yield artifact_file
Beispiel #2
0
def _publish(galaxy_context, archive_path, display_callback=None):

    results = {'errors': [], 'success': True}

    api = GalaxyAPI(galaxy_context)

    publish_api_key = galaxy_context.server.get('api_key', None)

    data = {
        'sha256': chksums.sha256sum_from_path(archive_path),
    }

    form = multipart_form.MultiPartForm()
    for key in data:
        form.add_field(key, data[key])

    form.add_file('file', os.path.basename(archive_path),
                  codecs.open(archive_path, 'rb'), 'application/octet-stream')

    log.debug('form: %s', form)

    log.debug("Publishing file %s with data: %s" %
              (archive_path, json.dumps(data)))

    try:
        response_data = api.publish_file(form, publish_api_key)
        log.debug('response_data: %s', response_data)
        results['response_data'] = response_data
    except exceptions.GalaxyError as exc:
        results['success'] = False
        results['errors'].append(str(exc))

    return results
Beispiel #3
0
def validate_artifact(artifact_path, expected_chksum):
    '''Check the sha256sum of file at `artifact_path` against `expected_chksum`

    Raise a GalaxyArtifactChksumError if they don't match.
    '''
    actual = chksums.sha256sum_from_path(artifact_path)

    if actual != expected_chksum:
        raise exceptions.GalaxyArtifactChksumError(artifact_path=artifact_path,
                                                   expected=expected_chksum,
                                                   actual=actual)
Beispiel #4
0
def create_file_manifest_item(file_name, file_name_in_archive):
    if os.path.isfile(file_name):
        # At the moment, 'sha256' is the only supported chksum_type for files
        ftype = 'file'
        chksum_type = 'sha256'
        chksum = chksums.sha256sum_from_path(file_name)

    if os.path.isdir(file_name):
        chksum = None
        chksum_type = None
        ftype = 'dir'

    log.debug('ftype: %s file_name: %s fnia: %s', ftype, file_name,
              file_name_in_archive)

    artifact_file_item = CollectionArtifactFile(
        src_name=file_name,
        # The path where the file will live inside the archive
        name=file_name_in_archive,
        ftype=ftype,
        chksum_type=chksum_type,
        chksum_sha256=chksum)

    return artifact_file_item