Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/tar/loader.py
Show All 12 Lines | |||||
from tempfile import mkdtemp | from tempfile import mkdtemp | ||||
from swh.core import tarball | from swh.core import tarball | ||||
from swh.loader.core.loader import BufferedLoader | from swh.loader.core.loader import BufferedLoader | ||||
from swh.loader.dir.loader import revision_from, snapshot_from | from swh.loader.dir.loader import revision_from, snapshot_from | ||||
from swh.model.hashutil import MultiHash, HASH_BLOCK_SIZE | from swh.model.hashutil import MultiHash, HASH_BLOCK_SIZE | ||||
from swh.model.from_disk import Directory | from swh.model.from_disk import Directory | ||||
from .build import compute_revision | from .build import compute_revision, set_original_artifact | ||||
try: | try: | ||||
from _version import __version__ | from _version import __version__ | ||||
except ImportError: | except ImportError: | ||||
__version__ = 'devel' | __version__ = 'devel' | ||||
TEMPORARY_DIR_PREFIX_PATTERN = 'swh.loader.tar.' | TEMPORARY_DIR_PREFIX_PATTERN = 'swh.loader.tar.' | ||||
▲ Show 20 Lines • Show All 228 Lines • ▼ Show 20 Lines | class RemoteTarLoader(BaseTarLoader): | ||||
def build_revision(self, filepath, nature, hashes): | def build_revision(self, filepath, nature, hashes): | ||||
"""Build the revision with identifier | """Build the revision with identifier | ||||
We use the `last_modified` date provided by the caller to | We use the `last_modified` date provided by the caller to | ||||
build the revision. | build the revision. | ||||
""" | """ | ||||
return { | return set_original_artifact( | ||||
**compute_revision(filepath, self.last_modified), | revision=compute_revision(filepath, self.last_modified), | ||||
'metadata': { | filepath=filepath, | ||||
'original_artifact': [{ | nature=nature, | ||||
'name': os.path.basename(filepath), | hashes=hashes, | ||||
'archive_type': nature, | ) | ||||
**hashes, | |||||
}], | |||||
} | |||||
} | |||||
def build_snapshot(self, revision): | def build_snapshot(self, revision): | ||||
"""Build the snapshot targeting the revision. | """Build the snapshot targeting the revision. | ||||
""" | """ | ||||
branch_name = os.path.basename(self.dir_path) | branch_name = os.path.basename(self.dir_path) | ||||
return snapshot_from(revision['id'], branch_name) | return snapshot_from(revision['id'], branch_name) | ||||
Show All 36 Lines | class LegacyLocalTarLoader(BaseTarLoader): | ||||
def build_revision(self, filepath, nature, hashes): | def build_revision(self, filepath, nature, hashes): | ||||
"""Build the revision with identifier | """Build the revision with identifier | ||||
We use the revision provided by the caller as a scaffolding | We use the revision provided by the caller as a scaffolding | ||||
revision. | revision. | ||||
""" | """ | ||||
return { | return set_original_artifact( | ||||
**self.revision, | revision=self.revision, | ||||
'metadata': { | filepath=filepath, | ||||
'original_artifact': [{ | nature=nature, | ||||
'name': os.path.basename(filepath), | hashes=hashes, | ||||
'archive_type': nature, | ) | ||||
**hashes, | |||||
}], | |||||
} | |||||
} | |||||
def build_snapshot(self, revision): | def build_snapshot(self, revision): | ||||
"""Build the snapshot targeting the revision. | """Build the snapshot targeting the revision. | ||||
We use the branch_name provided by the caller as a scaffolding | We use the branch_name provided by the caller as a scaffolding | ||||
as well. | as well. | ||||
""" | """ | ||||
return snapshot_from(revision['id'], self.branch_name) | return snapshot_from(revision['id'], self.branch_name) |