Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/model.py
Show First 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | def dirs(self) -> Iterator["DirectoryEntry"]: | ||||
"Children of this node has not yet been retrieved. " | "Children of this node has not yet been retrieved. " | ||||
"Please call retrieve_children() before using this property." | "Please call retrieve_children() before using this property." | ||||
) | ) | ||||
return (x for x in self._dirs) | return (x for x in self._dirs) | ||||
def __str__(self): | def __str__(self): | ||||
return f"<MDirectory[{self.id.hex()}] {self.name}>" | return f"<MDirectory[{self.id.hex()}] {self.name}>" | ||||
def __eq__(self, other): | |||||
sameFiles = (self._files is None and other._files is None) or ( | |||||
set(self._files) == set(other._files) | |||||
) | |||||
sameDirs = (self._dirs is None and other._dirs is None) or ( | |||||
set(self._dirs) == set(other._dirs) | |||||
) | |||||
return ( | |||||
isinstance(other, DirectoryEntry) | |||||
and (self.id, self.name) == (other.id, other.name) | |||||
and sameFiles | |||||
and sameDirs | |||||
) | |||||
class FileEntry: | class FileEntry: | ||||
def __init__(self, id: bytes, name: bytes): | def __init__(self, id: bytes, name: bytes): | ||||
self.id = id | self.id = id | ||||
self.name = name | self.name = name | ||||
def __str__(self): | def __str__(self): | ||||
return f"<MFile[{self.id.hex()}] {self.name}>" | return f"<MFile[{self.id.hex()}] {self.name}>" | ||||
def __eq__(self, other): | |||||
return isinstance(other, FileEntry) and (self.id, self.name) == ( | |||||
other.id, | |||||
other.name, | |||||
) |