Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/loader.py
Show All 11 Lines | |||||
from swh.core import tarball | from swh.core import tarball | ||||
from swh.loader.core.utils import clean_dangling_folders | from swh.loader.core.utils import clean_dangling_folders | ||||
from swh.loader.core.loader import BufferedLoader | from swh.loader.core.loader import BufferedLoader | ||||
from swh.model.hashutil import MultiHash, HASH_BLOCK_SIZE | from swh.model.hashutil import MultiHash, HASH_BLOCK_SIZE | ||||
from swh.storage.algos.snapshot import snapshot_get_all_branches | from swh.storage.algos.snapshot import snapshot_get_all_branches | ||||
from swh.model.from_disk import Directory | from swh.model.from_disk import Directory | ||||
from swh.model.identifiers import ( | from swh.model.identifiers import ( | ||||
identifier_to_bytes, revision_identifier | identifier_to_bytes, revision_identifier, snapshot_identifier | ||||
) | ) | ||||
from .build_revision import BuildRevision | from .build_revision import BuildRevision | ||||
DEBUG_MODE = '** DEBUG MODE **' | DEBUG_MODE = '** DEBUG MODE **' | ||||
▲ Show 20 Lines • Show All 396 Lines • ▼ Show 20 Lines | def store_data(self): | ||||
""" | """ | ||||
self.maybe_load_contents(self.package_contents) | self.maybe_load_contents(self.package_contents) | ||||
self.maybe_load_directories(self.package_directories) | self.maybe_load_directories(self.package_directories) | ||||
self.maybe_load_revisions(self.package_revisions) | self.maybe_load_revisions(self.package_revisions) | ||||
if self.done: | if self.done: | ||||
self.generate_and_load_snapshot() | self.generate_and_load_snapshot() | ||||
self.flush() | self.flush() | ||||
def generate_and_load_snapshot(self): | |||||
"""Generate and load snapshot for the package visit. | |||||
""" | |||||
snapshot = { | |||||
'branches': self.generate_branches(), | |||||
} | |||||
snapshot['id'] = identifier_to_bytes(snapshot_identifier(snapshot)) | |||||
self.maybe_load_snapshot(snapshot) | |||||
def generate_branches(self): | |||||
"""Generate branches for the focused package | |||||
""" | |||||
branches = {} | |||||
key = self.get_key() | |||||
for version in self.package_source_data: | |||||
branch_name = self.branch_name(version) | |||||
target = self.target_from_version(version[key]) | |||||
branches[branch_name] = target | |||||
branches = self.find_head(branches, branch_name) | |||||
# How to find HEAD and branch name? | |||||
if not target: | |||||
self.package_visit_status = 'partial' | |||||
return branches | |||||
def find_head(self, branches, branch_name): | |||||
"""Make branch head. | |||||
Checks if the current version is the latest version. Make it as head | |||||
if it is the latest version. | |||||
Args: | |||||
branches (dict): Branches for the focused package. | |||||
branch_name (str): Branch name | |||||
Returns: | |||||
dict: Branches for the focused package | |||||
""" | |||||
if True: # I don't know what to do here | |||||
# we need some condition here to check if the version is the | |||||
# latest version. I don't know how to check that because all | |||||
# of the package manager do not provide field like version | |||||
branches[b'HEAD'] = { | |||||
'target_type': 'alias', | |||||
'target': branch_name, | |||||
} | |||||
return branches | |||||
def branch_name(self, version): | |||||
"""Find branch name. | |||||
Args: | |||||
version (dict): Information related to a particular package version | |||||
Returns: | |||||
Branch name encoded in ascii | |||||
""" | |||||
# How to tackle this | |||||
pass | |||||
def target_from_version(self, key_value): | |||||
target = self.known_versions.get(key_value) | |||||
return { | |||||
'target': target, | |||||
'target_type': 'revision', | |||||
} if target else None | |||||
def cleanup(self): | |||||
"""Clean up temporary disk use after downloading and extracting | |||||
package tarballs. | |||||
""" | |||||
if self.debug: | |||||
self.log.warn('%s Will not clean up temp dir %s' % ( | |||||
DEBUG_MODE, self.temp_directory | |||||
)) | |||||
return | |||||
if os.path.exists(self.temp_directory): | |||||
self.log.debug('Clean up %s' % self.temp_directory) | |||||
shutil.rmtree(self.temp_directory) |