Changeset View
Changeset View
Standalone View
Standalone View
swh/model/model.py
Show First 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | class Origin(BaseModel): | ||||
url = attr.ib(type=str) | url = attr.ib(type=str) | ||||
type = attr.ib(type=Optional[str], default=None) | type = attr.ib(type=Optional[str], default=None) | ||||
@attr.s | @attr.s | ||||
class OriginVisit(BaseModel): | class OriginVisit(BaseModel): | ||||
"""Represents a visit of an origin at a given point in time, by a | """Represents a visit of an origin at a given point in time, by a | ||||
SWH loader.""" | SWH loader.""" | ||||
origin = attr.ib(type=Origin) | origin = attr.ib(type=str) | ||||
date = attr.ib(type=datetime.datetime) | date = attr.ib(type=datetime.datetime) | ||||
status = attr.ib( | status = attr.ib( | ||||
type=str, | type=str, | ||||
validator=attr.validators.in_(['ongoing', 'full', 'partial'])) | validator=attr.validators.in_(['ongoing', 'full', 'partial'])) | ||||
type = attr.ib(type=str) | type = attr.ib(type=str) | ||||
snapshot = attr.ib(type=Sha1Git) | snapshot = attr.ib(type=Sha1Git) | ||||
metadata = attr.ib(type=Optional[Dict[str, object]], | metadata = attr.ib(type=Optional[Dict[str, object]], | ||||
default=None) | default=None) | ||||
Show All 11 Lines | def to_dict(self): | ||||
return ov | return ov | ||||
@classmethod | @classmethod | ||||
def from_dict(cls, d): | def from_dict(cls, d): | ||||
"""Parses the date from a string, and accepts missing visit ids.""" | """Parses the date from a string, and accepts missing visit ids.""" | ||||
d = d.copy() | d = d.copy() | ||||
date = d.pop('date') | date = d.pop('date') | ||||
return cls( | return cls( | ||||
origin=Origin.from_dict(d.pop('origin')), | |||||
date=(date | date=(date | ||||
if isinstance(date, datetime.datetime) | if isinstance(date, datetime.datetime) | ||||
else dateutil.parser.parse(date)), | else dateutil.parser.parse(date)), | ||||
**d) | **d) | ||||
class TargetType(Enum): | class TargetType(Enum): | ||||
"""The type of content pointed to by a snapshot branch. Usually a | """The type of content pointed to by a snapshot branch. Usually a | ||||
▲ Show 20 Lines • Show All 232 Lines • Show Last 20 Lines |