Exemplo n.º 1
0
        def to_representation(self, value):
            """Snapshot JSON serialization."""
            snapshot = value
            snapshot_repo = SnapshotRepo()
            info = {
                'hash_digest': snapshot.hash_digest.hex(),
                'created_at': snapshot.created_at,
            }

            info['files'] = {
                path: {
                    "url": self._expand_url(snapshot_repo.url(snapshot, path)),
                    "size": file_info.size,
                    "hash_digest": file_info.hash_digest.hex(),
                }
                for path, file_info in snapshot.files.items()
            }

            info['links'] = {
                link.name: {
                    "direct":
                    self._serialized_dep(link.direct_dependency),
                    "indirect": [
                        self._serialized_dep(dep)
                        for dep in link.indirect_dependencies
                    ]
                }
                for link in snapshot.links
            }

            return info
Exemplo n.º 2
0
def _bundle_version_data_from_model(bundle_version_model):
    """
    Create and return BundleVersionData from bundle version model.
    """
    snapshot = bundle_version_model.snapshot()
    snapshot_repo = SnapshotRepo()

    return BundleVersionData(
        bundle_uuid=bundle_version_model.bundle.uuid,
        version=bundle_version_model.version_num,
        change_description=bundle_version_model.change_description,
        created_at=snapshot.created_at,
        files={
            path: BundleFileData(
                path=path,
                url=_build_absolute_uri(snapshot_repo.url(snapshot, path)),
                size=file_info.size,
                hash_digest=file_info.hash_digest.hex(),
            ) for path, file_info in snapshot.files.items()
        },
        links={
            link.name: BundleLinkData(
                name=link.name,
                direct=link.direct_dependency,
                indirect=link.indirect_dependencies,
            )
            for link in snapshot.links
        },
    )
Exemplo n.º 3
0
        def to_representation(self, value):
            """Snapshot JSON serialization."""
            snapshot = value
            snapshot_repo = SnapshotRepo()
            basic_info = {
                'hash_digest': snapshot.hash_digest.hex(),
                'created_at': snapshot.created_at,
            }

            basic_info['files'] = {
                path: {
                    "url": snapshot_repo.url(snapshot, path),
                    "size": file_info.size,
                    "hash_digest": file_info.hash_digest.hex(),
                }
                for path, file_info in snapshot.files.items()
            }

            return basic_info