Changeset View
Changeset View
Standalone View
Standalone View
swh/model/model.py
Show First 20 Lines • Show All 622 Lines • ▼ Show 20 Lines | metadata = attr.ib( | ||||
default=None, | default=None, | ||||
) | ) | ||||
id = attr.ib(type=Sha1Git, validator=type_validator(), default=b"", repr=hash_repr) | id = attr.ib(type=Sha1Git, validator=type_validator(), default=b"", repr=hash_repr) | ||||
def compute_hash(self) -> bytes: | def compute_hash(self) -> bytes: | ||||
git_object = git_objects.release_git_object(self) | git_object = git_objects.release_git_object(self) | ||||
return hashlib.new("sha1", git_object).digest() | return hashlib.new("sha1", git_object).digest() | ||||
@author.validator | |||||
def check_author(self, attribute, value): | |||||
"""If the author is `None`, checks the date is `None` too.""" | |||||
if self.author is None and self.date is not None: | |||||
raise ValueError("release date must be None if author is None.") | |||||
def to_dict(self): | def to_dict(self): | ||||
rel = super().to_dict() | rel = super().to_dict() | ||||
if rel["metadata"] is None: | if rel["metadata"] is None: | ||||
del rel["metadata"] | del rel["metadata"] | ||||
return rel | return rel | ||||
@classmethod | @classmethod | ||||
def from_dict(cls, d): | def from_dict(cls, d): | ||||
▲ Show 20 Lines • Show All 679 Lines • Show Last 20 Lines |