Changeset View
Changeset View
Standalone View
Standalone View
swh/model/model.py
Show First 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | class Snapshot(BaseModel): | ||||
"""Represents the full state of an origin at a given point in time.""" | """Represents the full state of an origin at a given point in time.""" | ||||
id = attr.ib(type=Sha1Git) | id = attr.ib(type=Sha1Git) | ||||
branches = attr.ib(type=Dict[bytes, Optional[SnapshotBranch]]) | branches = attr.ib(type=Dict[bytes, Optional[SnapshotBranch]]) | ||||
def to_dict(self): | def to_dict(self): | ||||
return { | return { | ||||
'id': self.id, | 'id': self.id, | ||||
'branches': { | 'branches': { | ||||
name: branch.to_dict() | name: branch.to_dict() if branch else None | ||||
for (name, branch) in self.branches.items() | for (name, branch) in self.branches.items() | ||||
} | } | ||||
} | } | ||||
@classmethod | @classmethod | ||||
def from_dict(cls, d): | def from_dict(cls, d): | ||||
return cls( | return cls( | ||||
id=d['id'], | id=d['id'], | ||||
branches={ | branches={ | ||||
name: SnapshotBranch.from_dict(branch) | name: SnapshotBranch.from_dict(branch) if branch else None | ||||
for (name, branch) in d['branches'].items() | for (name, branch) in d['branches'].items() | ||||
}) | }) | ||||
@attr.s | @attr.s | ||||
class Release(BaseModel): | class Release(BaseModel): | ||||
id = attr.ib(type=Sha1Git) | id = attr.ib(type=Sha1Git) | ||||
name = attr.ib(type=bytes) | name = attr.ib(type=bytes) | ||||
▲ Show 20 Lines • Show All 166 Lines • Show Last 20 Lines |