Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/revision.py
from datetime import datetime, timezone | from datetime import datetime, timezone | ||||
from itertools import islice | from itertools import islice | ||||
import logging | import logging | ||||
import os | import os | ||||
import time | import time | ||||
from typing import Iterable, Iterator, List, Optional, Tuple | from typing import Generator, Iterable, Iterator, List, Optional, Tuple | ||||
import iso8601 | |||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.model import Sha1Git | from swh.model.model import Sha1Git | ||||
from .archive import ArchiveInterface | from .archive import ArchiveInterface | ||||
from .graph import IsochroneNode, build_isochrone_graph | from .graph import IsochroneNode, build_isochrone_graph | ||||
from .model import DirectoryEntry, RevisionEntry | from .model import DirectoryEntry, RevisionEntry | ||||
from .provenance import ProvenanceInterface | from .provenance import ProvenanceInterface | ||||
Show All 11 Lines | class CSVRevisionIterator: | ||||
- date: is the author date | - date: is the author date | ||||
- root: sha1 of the directory | - root: sha1 of the directory | ||||
""" | """ | ||||
def __init__( | def __init__( | ||||
self, | self, | ||||
revisions: Iterable[Tuple[Sha1Git, datetime, Sha1Git]], | revisions: Iterable[Tuple[Sha1Git, datetime, Sha1Git]], | ||||
limit: Optional[int] = None, | limit: Optional[int] = None, | ||||
): | ) -> None: | ||||
self.revisions: Iterator[Tuple[Sha1Git, datetime, Sha1Git]] | self.revisions: Iterator[Tuple[Sha1Git, datetime, Sha1Git]] | ||||
if limit is not None: | if limit is not None: | ||||
self.revisions = islice(revisions, limit) | self.revisions = islice(revisions, limit) | ||||
else: | else: | ||||
self.revisions = iter(revisions) | self.revisions = iter(revisions) | ||||
def __iter__(self): | def __iter__(self) -> Generator[RevisionEntry, None, None]: | ||||
return self | for id, date, root in self.revisions: | ||||
def __next__(self): | |||||
id, date, root = next(self.revisions) | |||||
date = iso8601.parse_date(date) | |||||
if date.tzinfo is None: | if date.tzinfo is None: | ||||
date = date.replace(tzinfo=timezone.utc) | date = date.replace(tzinfo=timezone.utc) | ||||
return RevisionEntry( | yield RevisionEntry( | ||||
hash_to_bytes(id), | hash_to_bytes(id), | ||||
date=date, | date=date, | ||||
root=hash_to_bytes(root), | root=hash_to_bytes(root), | ||||
) | ) | ||||
def revision_add( | def revision_add( | ||||
provenance: ProvenanceInterface, | provenance: ProvenanceInterface, | ||||
archive: ArchiveInterface, | archive: ArchiveInterface, | ||||
revisions: List[RevisionEntry], | revisions: List[RevisionEntry], | ||||
trackall: bool = True, | trackall: bool = True, | ||||
lower: bool = True, | lower: bool = True, | ||||
Show All 40 Lines | |||||
def revision_process_content( | def revision_process_content( | ||||
archive: ArchiveInterface, | archive: ArchiveInterface, | ||||
provenance: ProvenanceInterface, | provenance: ProvenanceInterface, | ||||
revision: RevisionEntry, | revision: RevisionEntry, | ||||
graph: IsochroneNode, | graph: IsochroneNode, | ||||
trackall: bool = True, | trackall: bool = True, | ||||
lower: bool = True, | lower: bool = True, | ||||
mindepth: int = 1, | mindepth: int = 1, | ||||
): | ) -> None: | ||||
assert revision.date is not None | assert revision.date is not None | ||||
provenance.revision_add(revision) | provenance.revision_add(revision) | ||||
stack = [graph] | stack = [graph] | ||||
while stack: | while stack: | ||||
current = stack.pop() | current = stack.pop() | ||||
if current.dbdate is not None: | if current.dbdate is not None: | ||||
assert current.dbdate <= revision.date | assert current.dbdate <= revision.date | ||||
▲ Show 20 Lines • Show All 132 Lines • Show Last 20 Lines |