Changeset View
Changeset View
Standalone View
Standalone View
swh/model/model.py
Show First 20 Lines • Show All 551 Lines • ▼ Show 20 Lines | def anonymize(self) -> "Revision": | ||||
Person object. | Person object. | ||||
""" | """ | ||||
return attr.evolve( | return attr.evolve( | ||||
self, author=self.author.anonymize(), committer=self.committer.anonymize() | self, author=self.author.anonymize(), committer=self.committer.anonymize() | ||||
) | ) | ||||
@attr.s(frozen=True, slots=True) | @attr.s(frozen=True, slots=True) | ||||
class ExtID(BaseModel): | |||||
object_type: Final = "extid" | |||||
extid = attr.ib(type=bytes, validator=type_validator()) | |||||
extid_type = attr.ib(type=str, validator=type_validator()) | |||||
vlorentz: Not an enum? | |||||
douarddaAuthorUnsubmitted Done Inline ActionsNot sure yet if we want an enum for this. So I started simple... douardda: Not sure yet if we want an enum for this. So I started simple... | |||||
target = attr.ib(type=Sha1Git, validator=type_validator()) | |||||
target_type = attr.ib(type=ObjectType, validator=type_validator()) | |||||
vlorentzUnsubmitted Not Done Inline ActionsWhat about a SWHID instead? vlorentz: What about a SWHID instead? | |||||
douarddaAuthorUnsubmitted Done Inline Actionswe do not (want) to support generic SWHID (with context), plus swhid is a textual representation that will need string manipulations / (en|de)coding, etc. so the idea was to stick, in the data model, to stricly what we need. douardda: we do not (want) to support generic SWHID (with context), plus swhid is a textual… | |||||
vlorentzUnsubmitted Not Done Inline Actions
neither does raw_extrinsic_metadata, there's a validator to check it has no context. vlorentz: > we do not (want) to support generic SWHID (with context)
neither does… | |||||
@classmethod | |||||
def from_dict(cls, d): | |||||
return cls( | |||||
extid=d["extid"], | |||||
extid_type=d["extid_type"], | |||||
target=d["target"], | |||||
target_type=ObjectType(d["target_type"]), | |||||
) | |||||
@attr.s(frozen=True, slots=True) | |||||
class DirectoryEntry(BaseModel): | class DirectoryEntry(BaseModel): | ||||
object_type: Final = "directory_entry" | object_type: Final = "directory_entry" | ||||
name = attr.ib(type=bytes, validator=type_validator()) | name = attr.ib(type=bytes, validator=type_validator()) | ||||
type = attr.ib(type=str, validator=attr.validators.in_(["file", "dir", "rev"])) | type = attr.ib(type=str, validator=attr.validators.in_(["file", "dir", "rev"])) | ||||
target = attr.ib(type=Sha1Git, validator=type_validator()) | target = attr.ib(type=Sha1Git, validator=type_validator()) | ||||
perms = attr.ib(type=int, validator=type_validator()) | perms = attr.ib(type=int, validator=type_validator()) | ||||
"""Usually one of the values of `swh.model.from_disk.DentryPerms`.""" | """Usually one of the values of `swh.model.from_disk.DentryPerms`.""" | ||||
▲ Show 20 Lines • Show All 498 Lines • ▼ Show 20 Lines | def unique_key(self) -> KeyType: | ||||
return { | return { | ||||
"type": self.type.value, | "type": self.type.value, | ||||
"target": str(self.target), | "target": str(self.target), | ||||
"authority_type": self.authority.type.value, | "authority_type": self.authority.type.value, | ||||
"authority_url": self.authority.url, | "authority_url": self.authority.url, | ||||
"discovery_date": str(self.discovery_date), | "discovery_date": str(self.discovery_date), | ||||
"fetcher_name": self.fetcher.name, | "fetcher_name": self.fetcher.name, | ||||
"fetcher_version": self.fetcher.version, | "fetcher_version": self.fetcher.version, | ||||
} | } | ||||
Not Done Inline ActionsYou're manually handling all the attributes, why not just call the class initializer directly? olasd: You're manually handling all the attributes, why not just call the class initializer directly? | |||||
Done Inline Actionspossibly "just" the result of several refactorings... lemme check douardda: possibly "just" the result of several refactorings... lemme check |
Not an enum?