Changeset View
Changeset View
Standalone View
Standalone View
swh/model/from_disk.py
# Copyright (C) 2017-2020 The Software Heritage developers | # Copyright (C) 2017-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 enum | import enum | ||||
import os | import os | ||||
import stat | import stat | ||||
import attr | import attr | ||||
from attrs_strict import type_validator | |||||
from typing import List, Optional, Iterable, Any | from typing import List, Optional, Iterable, Any | ||||
from typing_extensions import Final | |||||
from .hashutil import MultiHash | from .hashutil import MultiHash | ||||
from .merkle import MerkleLeaf, MerkleNode | from .merkle import MerkleLeaf, MerkleNode | ||||
from .identifiers import ( | from .identifiers import ( | ||||
directory_entry_sort_key, | directory_entry_sort_key, | ||||
directory_identifier, | directory_identifier, | ||||
identifier_to_bytes as id_to_bytes, | identifier_to_bytes as id_to_bytes, | ||||
identifier_to_str as id_to_str, | identifier_to_str as id_to_str, | ||||
) | ) | ||||
from . import model | from . import model | ||||
@attr.s | @attr.s | ||||
class DiskBackedContent(model.Content): | class DiskBackedContent(model.BaseContent): | ||||
"""Subclass of Content, which allows lazy-loading data from the disk.""" | """Content-like class, which allows lazy-loading data from the disk.""" | ||||
object_type: Final = "content_file" | |||||
sha1 = attr.ib(type=bytes, validator=type_validator()) | |||||
sha1_git = attr.ib(type=model.Sha1Git, validator=type_validator()) | |||||
sha256 = attr.ib(type=bytes, validator=type_validator()) | |||||
blake2s256 = attr.ib(type=bytes, validator=type_validator()) | |||||
length = attr.ib(type=int, validator=type_validator()) | |||||
status = attr.ib( | |||||
type=str, | |||||
validator=attr.validators.in_(["visible", "hidden"]), | |||||
default="visible", | |||||
) | |||||
ctime = attr.ib( | |||||
type=Optional[datetime.datetime], | |||||
validator=type_validator(), | |||||
default=None, | |||||
ardumont: Is that to exclude it from the comparison computation? | |||||
Done Inline Actionsthe eq=False? yes it is. I've introduced this a few days ago because this ctime attribute really is just a helper metadata, not an "intrisinc property" of a Content. See a95646fc douardda: the `eq=False`? yes it is. I've introduced this a few days ago because this ctime attribute… | |||||
eq=False, | |||||
) | |||||
path = attr.ib(type=Optional[bytes], default=None) | path = attr.ib(type=Optional[bytes], default=None) | ||||
@classmethod | |||||
def from_dict(cls, d): | |||||
return cls(**d) | |||||
def __attrs_post_init__(self): | def __attrs_post_init__(self): | ||||
if self.path is None: | if self.path is None: | ||||
raise TypeError("path must not be None.") | raise TypeError("path must not be None.") | ||||
def with_data(self) -> model.Content: | def with_data(self) -> model.Content: | ||||
args = self.to_dict() | args = self.to_dict() | ||||
del args["path"] | del args["path"] | ||||
assert self.path is not None | assert self.path is not None | ||||
▲ Show 20 Lines • Show All 382 Lines • Show Last 20 Lines |
Is that to exclude it from the comparison computation?