Changeset View
Changeset View
Standalone View
Standalone View
swh/model/model.py
Show First 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | def from_dict(cls, d): | ||||
}) | }) | ||||
@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) | ||||
message = attr.ib(type=bytes) | message = attr.ib(type=bytes) | ||||
target = attr.ib(type=Optional[Sha1Git], | target = attr.ib(type=Optional[Sha1Git]) | ||||
validator=attr.validators.optional([])) | |||||
target_type = attr.ib(type=ObjectType) | target_type = attr.ib(type=ObjectType) | ||||
synthetic = attr.ib(type=bool) | synthetic = attr.ib(type=bool) | ||||
author = attr.ib(type=Optional[Person], | author = attr.ib(type=Optional[Person], | ||||
default=None, | default=None) | ||||
validator=attr.validators.optional([])) | |||||
date = attr.ib(type=Optional[TimestampWithTimezone], | date = attr.ib(type=Optional[TimestampWithTimezone], | ||||
default=None, | default=None) | ||||
validator=attr.validators.optional([])) | |||||
metadata = attr.ib(type=Optional[Dict[str, object]], | metadata = attr.ib(type=Optional[Dict[str, object]], | ||||
default=None, | default=None) | ||||
validator=attr.validators.optional([])) | |||||
@author.validator | @author.validator | ||||
def check_author(self, attribute, value): | def check_author(self, attribute, value): | ||||
"""If the author is `None`, checks the date is `None` too.""" | """If the author is `None`, checks the date is `None` too.""" | ||||
if self.author is None and self.date is not None: | if self.author is None and self.date is not None: | ||||
raise ValueError('release date must be None if author is None.') | raise ValueError('release date must be None if author is None.') | ||||
def to_dict(self): | def to_dict(self): | ||||
Show All 31 Lines | class Revision(BaseModel): | ||||
author = attr.ib(type=Person) | author = attr.ib(type=Person) | ||||
committer = attr.ib(type=Person) | committer = attr.ib(type=Person) | ||||
date = attr.ib(type=TimestampWithTimezone) | date = attr.ib(type=TimestampWithTimezone) | ||||
committer_date = attr.ib(type=TimestampWithTimezone) | committer_date = attr.ib(type=TimestampWithTimezone) | ||||
type = attr.ib(type=RevisionType) | type = attr.ib(type=RevisionType) | ||||
directory = attr.ib(type=Sha1Git) | directory = attr.ib(type=Sha1Git) | ||||
synthetic = attr.ib(type=bool) | synthetic = attr.ib(type=bool) | ||||
metadata = attr.ib(type=Optional[Dict[str, object]], | metadata = attr.ib(type=Optional[Dict[str, object]], | ||||
default=None, | default=None) | ||||
validator=attr.validators.optional([])) | |||||
parents = attr.ib(type=List[Sha1Git], | parents = attr.ib(type=List[Sha1Git], | ||||
default=attr.Factory(list)) | default=attr.Factory(list)) | ||||
def to_dict(self): | def to_dict(self): | ||||
rev = attr.asdict(self) | rev = attr.asdict(self) | ||||
rev['date'] = self.date.to_dict() | rev['date'] = self.date.to_dict() | ||||
rev['committer_date'] = self.committer_date.to_dict() | rev['committer_date'] = self.committer_date.to_dict() | ||||
rev['type'] = rev['type'].value | rev['type'] = rev['type'].value | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | class Content(BaseModel): | ||||
sha256 = attr.ib(type=bytes) | sha256 = attr.ib(type=bytes) | ||||
blake2s256 = attr.ib(type=bytes) | blake2s256 = attr.ib(type=bytes) | ||||
length = attr.ib(type=int) | length = attr.ib(type=int) | ||||
status = attr.ib( | status = attr.ib( | ||||
type=str, | type=str, | ||||
validator=attr.validators.in_(['visible', 'absent', 'hidden'])) | validator=attr.validators.in_(['visible', 'absent', 'hidden'])) | ||||
reason = attr.ib(type=Optional[str], | reason = attr.ib(type=Optional[str], | ||||
default=None, | default=None) | ||||
validator=attr.validators.optional([])) | |||||
data = attr.ib(type=Optional[bytes], | data = attr.ib(type=Optional[bytes], | ||||
default=None, | default=None) | ||||
validator=attr.validators.optional([])) | |||||
ctime = attr.ib(type=Optional[datetime.datetime], | ctime = attr.ib(type=Optional[datetime.datetime], | ||||
default=None) | default=None) | ||||
@length.validator | @length.validator | ||||
def check_length(self, attribute, value): | def check_length(self, attribute, value): | ||||
"""Checks the length is positive.""" | """Checks the length is positive.""" | ||||
if self.status == 'absent' and value < -1: | if self.status == 'absent' and value < -1: | ||||
Show All 25 Lines |