Page MenuHomeSoftware Heritage

D1814.diff
No OneTemporary

D1814.diff

diff --git a/swh/loader/package/loader.py b/swh/loader/package/loader.py
--- a/swh/loader/package/loader.py
+++ b/swh/loader/package/loader.py
@@ -17,7 +17,7 @@
from swh.model.from_disk import Directory
from swh.model.identifiers import (
- identifier_to_bytes, revision_identifier
+ identifier_to_bytes, revision_identifier, snapshot_identifier
)
@@ -430,3 +430,90 @@
if self.done:
self.generate_and_load_snapshot()
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)

File Metadata

Mime Type
text/plain
Expires
Thu, Jan 23, 2:46 AM (17 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3215609

Event Timeline