Changeset View
Changeset View
Standalone View
Standalone View
swh/model/model.py
# Copyright (C) 2018-2019 The Software Heritage developers | # Copyright (C) 2018-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import datetime | import datetime | ||||
from abc import ABCMeta, abstractmethod | from abc import ABCMeta, abstractmethod | ||||
from enum import Enum | from enum import Enum | ||||
▲ Show 20 Lines • Show All 213 Lines • ▼ Show 20 Lines | |||||
class Origin(BaseModel): | class Origin(BaseModel): | ||||
"""Represents a software source: a VCS and an URL.""" | """Represents a software source: a VCS and an URL.""" | ||||
url = attr.ib(type=str, validator=type_validator()) | url = attr.ib(type=str, validator=type_validator()) | ||||
@attr.s(frozen=True) | @attr.s(frozen=True) | ||||
class OriginVisit(BaseModel): | class OriginVisit(BaseModel): | ||||
"""Represents a visit of an origin at a given point in time, by a | """Represents an origin visit with a given type at a given point in time, by a | ||||
SWH loader.""" | SWH loader.""" | ||||
origin = attr.ib(type=str, validator=type_validator()) | origin = attr.ib(type=str, validator=type_validator()) | ||||
date = attr.ib(type=datetime.datetime, validator=type_validator()) | date = attr.ib(type=datetime.datetime, validator=type_validator()) | ||||
status = attr.ib( | |||||
type=str, validator=attr.validators.in_(["ongoing", "full", "partial"]) | |||||
) | |||||
type = attr.ib(type=str, validator=type_validator()) | type = attr.ib(type=str, validator=type_validator()) | ||||
snapshot = attr.ib(type=Optional[Sha1Git], validator=type_validator()) | |||||
metadata = attr.ib( | |||||
type=Optional[Dict[str, object]], validator=type_validator(), default=None | |||||
) | |||||
visit = attr.ib(type=Optional[int], validator=type_validator(), default=None) | visit = attr.ib(type=Optional[int], validator=type_validator(), default=None) | ||||
"""Should not be set before calling 'origin_visit_add()'.""" | |||||
def to_dict(self): | def to_dict(self): | ||||
"""Serializes the date as a string and omits the visit id if it is | """Serializes the date as a string and omits the visit id if it is | ||||
`None`.""" | `None`.""" | ||||
ov = super().to_dict() | ov = super().to_dict() | ||||
if ov["visit"] is None: | if ov["visit"] is None: | ||||
del ov["visit"] | del ov["visit"] | ||||
return ov | return ov | ||||
▲ Show 20 Lines • Show All 396 Lines • Show Last 20 Lines |