Beispiel #1
0
def _patch_client_for_direct_access(client: DSSClient):
    old_get_file = client.get_file
    old_get_bundle = client.get_bundle
    mini_dss = MiniDSS(config.dss_endpoint)

    def new_get_file(self, uuid, replica, version=None):
        assert client is self
        try:
            blob = mini_dss.get_file(uuid, version, replica)
        except Exception:
            logger.warning(
                'Failed getting file %s, version %s directly. '
                'Falling back to official method', uuid, version)
            return old_get_file(uuid=uuid, version=version, replica=replica)
        else:
            return blob

    class NewGetBundle:
        def paginate(self, *args, **kwargs):
            uuid, version, replica = kwargs['uuid'], kwargs['version'], kwargs[
                'replica']
            try:
                bundle = mini_dss.get_bundle(uuid, version, replica)
            except Exception:
                logger.warning(
                    'Failed getting bundle file %s, version %s directly. '
                    'Falling back to official method', uuid, version)
                return old_get_bundle.paginate(*args, **kwargs)
            else:
                page = {'bundle': bundle, 'version': version, 'uuid': uuid}
                return [page]

    new_get_bundle = NewGetBundle()
    client.get_file = types.MethodType(new_get_file, client)
    client.get_bundle = new_get_bundle
Beispiel #2
0
from hca.dss import DSSClient
import json

dss = DSSClient()

json_response = dss.get_file(replica="aws",
                             uuid="666ff3f0-67a1-4ead-82e9-3f96a8c0a9b1")

for content in json_response:
    print(f"{content}: {json.dumps(json_response[content], indent=4)}")
Beispiel #3
0
        )

        # Retrieves a bundle given a UUID and optionally a version.
        files_uuid = []
        for file in dss.get_bundle:
            file_version = bundle["version"]
            file_uuid = bundle["uuid"]
            file_name = bundle["name"]
            file_sha256 = bundle["sha256"]
            files_uuid.append(file_uuid)
            s += f" File: {file_name} \n"
            s += f"   Sha_256:{file_sha256} \n"
            s += f"     UUID/Version:{file_uuid}.{file_version} \n"
        print(s[:-1])
        break
    except ValueError:
        pass

for file_uuid in files_uuid:
    # Given a file UUID, return latest version of the file.
    try:
        fh = dss.get_file(replica="aws", uuid=file_uuid)
        print(dss.head_file(uuid=file_uuid, replica="aws"))
        print(fh["describedBy"] + " \n   type:" + fh["schema_type"])
    except TypeError:
        pass

# Clear sphinx-build dss authentication credentials previously
# configured with sphinx-build dss login
dss.logout()