Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/svn/loader.py
Show All 9 Lines | |||||
import os | import os | ||||
import pty | import pty | ||||
import re | import re | ||||
import shutil | import shutil | ||||
import tempfile | import tempfile | ||||
from mmap import mmap, ACCESS_WRITE | from mmap import mmap, ACCESS_WRITE | ||||
from subprocess import Popen | from subprocess import Popen | ||||
from typing import Iterator, List, Tuple | from typing import Iterator, List, Optional, Tuple | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from swh.model.model import ( | from swh.model.model import ( | ||||
Content, | Content, | ||||
Directory, | Directory, | ||||
Origin, | Origin, | ||||
SkippedContent, | SkippedContent, | ||||
Revision, | Revision, | ||||
▲ Show 20 Lines • Show All 524 Lines • ▼ Show 20 Lines | def store_data(self): | ||||
revision=self._last_revision, snapshot=self._snapshot | revision=self._last_revision, snapshot=self._snapshot | ||||
) | ) | ||||
self.flush() | self.flush() | ||||
self.loaded_snapshot_id = self.snapshot.id | self.loaded_snapshot_id = self.snapshot.id | ||||
# reset internal state for next iteration | # reset internal state for next iteration | ||||
self._revisions = [] | self._revisions = [] | ||||
def generate_and_load_snapshot(self, revision=None, snapshot=None): | def generate_and_load_snapshot( | ||||
self, revision: Optional[Revision] = None, snapshot: Optional[Snapshot] = None | |||||
) -> Snapshot: | |||||
"""Create the snapshot either from existing revision or snapshot. | """Create the snapshot either from existing revision or snapshot. | ||||
Revision (supposedly new) has priority over the snapshot | Revision (supposedly new) has priority over the snapshot | ||||
(supposedly existing one). | (supposedly existing one). | ||||
Args: | Args: | ||||
revision (dict): Last revision seen if any (None by default) | revision (dict): Last revision seen if any (None by default) | ||||
snapshot (dict): Snapshot to use if any (None by default) | snapshot (dict): Snapshot to use if any (None by default) | ||||
Returns: | Returns: | ||||
Optional[Snapshot] The newly created snapshot | Optional[Snapshot] The newly created snapshot | ||||
""" | """ | ||||
if revision: # Priority to the revision | if revision: # Priority to the revision | ||||
snap = build_swh_snapshot(revision.id) | snap = build_swh_snapshot(revision.id) | ||||
elif snapshot: # Fallback to prior snapshot | elif snapshot: # Fallback to prior snapshot | ||||
snap = snapshot | snap = snapshot | ||||
else: | else: | ||||
return None | raise ValueError( | ||||
"generate_and_load_snapshot called with null revision and snapshot!" | |||||
) | |||||
self.log.debug("snapshot: %s" % snap) | self.log.debug("snapshot: %s" % snap) | ||||
self.storage.snapshot_add([snap]) | self.storage.snapshot_add([snap]) | ||||
return snap | return snap | ||||
def load_status(self): | def load_status(self): | ||||
return { | return { | ||||
"status": self._load_status, | "status": self._load_status, | ||||
} | } | ||||
▲ Show 20 Lines • Show All 221 Lines • Show Last 20 Lines |