Skip to content
Snippets Groups Projects
Commit 3fcb2e78 authored by Antoine Lambert's avatar Antoine Lambert
Browse files

New upstream version 0.0.23

parents baddc949 448eafa0
No related branches found
No related tags found
No related merge requests found
Metadata-Version: 1.0 Metadata-Version: 1.0
Name: swh.model Name: swh.model
Version: 0.0.22 Version: 0.0.23
Summary: Software Heritage data model Summary: Software Heritage data model
Home-page: https://forge.softwareheritage.org/diffusion/DMOD/ Home-page: https://forge.softwareheritage.org/diffusion/DMOD/
Author: Software Heritage developers Author: Software Heritage developers
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
Data model Data model
========== ==========
TODO .. _swh-merkle-dag:
.. figure:: images/swh-merkle-dag.svg
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor :width: 1024px
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis :align: center
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse Software Heritage archive as a Merkle DAG, augmented with crawling
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non information (click to zoom).
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
swh-merkle-dag.pdf
swh-merkle-dag.svg
MERKLE_DAG = swh-merkle-dag.pdf swh-merkle-dag.svg
BUILD_TARGETS =
BUILD_TARGETS += $(MERKLE_DAG)
all: $(BUILD_TARGETS)
# dia exporters
%.eps: %.dia
dia -t eps --export $@ $<
%.svg: %.dia
dia -t svg --export $@ $<
# generic converters
%.pdf: %.eps
epstopdf $<
clean:
-rm -f $(BUILD_TARGETS)
File added
Metadata-Version: 1.0 Metadata-Version: 1.0
Name: swh.model Name: swh.model
Version: 0.0.22 Version: 0.0.23
Summary: Software Heritage data model Summary: Software Heritage data model
Home-page: https://forge.softwareheritage.org/diffusion/DMOD/ Home-page: https://forge.softwareheritage.org/diffusion/DMOD/
Author: Software Heritage developers Author: Software Heritage developers
......
...@@ -26,6 +26,9 @@ docs/index.rst ...@@ -26,6 +26,9 @@ docs/index.rst
docs/persistent-identifiers.rst docs/persistent-identifiers.rst
docs/_static/.placeholder docs/_static/.placeholder
docs/_templates/.placeholder docs/_templates/.placeholder
docs/images/.gitignore
docs/images/Makefile
docs/images/swh-merkle-dag.dia
swh/__init__.py swh/__init__.py
swh.model.egg-info/PKG-INFO swh.model.egg-info/PKG-INFO
swh.model.egg-info/SOURCES.txt swh.model.egg-info/SOURCES.txt
......
...@@ -538,7 +538,7 @@ def snapshot_identifier(snapshot, *, ignore_unresolved=False): ...@@ -538,7 +538,7 @@ def snapshot_identifier(snapshot, *, ignore_unresolved=False):
- the branch name (as raw bytes) - the branch name (as raw bytes)
- a null byte (``\\x00``) - a null byte (``\\x00``)
- the length of the target identifier, as an ascii-encoded decimal number - the length of the target identifier, as an ascii-encoded decimal number
(``20`` for current intrinisic identifiers, ``0`` for dangling (``20`` for current intrinsic identifiers, ``0`` for dangling
branches, the length of the target branch name for branch aliases) branches, the length of the target branch name for branch aliases)
- a colon (``:``) - a colon (``:``)
- the identifier of the target object pointed at by the branch, - the identifier of the target object pointed at by the branch,
...@@ -638,18 +638,35 @@ def persistent_identifier(type, object, version=1): ...@@ -638,18 +638,35 @@ def persistent_identifier(type, object, version=1):
PERSISTENT_IDENTIFIER_KEYS = [ PERSISTENT_IDENTIFIER_KEYS = [
'namespace', 'scheme_version', 'object_type', 'object_id'] 'namespace', 'scheme_version', 'object_type', 'object_id', 'metadata']
PERSISTENT_IDENTIFIER_PARTS_SEP = ';'
def parse_persistent_identifier(persistent_id): def parse_persistent_identifier(persistent_id):
"""Parse swh's persistent identifier scheme. """Parse swh's :ref:`persistent-identifiers` scheme.
Args: Args:
persistent_id (str): A persistent identifier persistent_id (str): A persistent identifier
Returns: Returns:
dict with keys namespace, scheme_version, object_type, object_id dict: dict with keys :
* namespace, holding str value
* scheme_version, holding str value
* object_type, holding str value
* object_id, holding str value
* metadata, holding dict value
""" """
data = persistent_id.split(':') persistent_id_parts = persistent_id.split(PERSISTENT_IDENTIFIER_PARTS_SEP)
data = persistent_id_parts.pop(0).split(':')
persistent_id_metadata = {}
for part in persistent_id_parts:
try:
key, val = part.split('=')
persistent_id_metadata[key] = val
except Exception:
pass
data.append(persistent_id_metadata)
return dict(zip(PERSISTENT_IDENTIFIER_KEYS, data)) return dict(zip(PERSISTENT_IDENTIFIER_KEYS, data))
...@@ -818,6 +818,32 @@ class SnapshotIdentifier(unittest.TestCase): ...@@ -818,6 +818,32 @@ class SnapshotIdentifier(unittest.TestCase):
'scheme_version': _version, 'scheme_version': _version,
'object_type': _type, 'object_type': _type,
'object_id': _hash, 'object_id': _hash,
'metadata': {}
}
actual_result = identifiers.parse_persistent_identifier(pid)
self.assertEquals(actual_result, expected_result)
for pid, _type, _version, _hash, _metadata in [
('swh:1:cnt:9c95815d9e9d91b8dae8e05d8bbc696fe19f796b;lines=1-18;origin=https://github.com/python/cpython', # noqa
'cnt', '1', '9c95815d9e9d91b8dae8e05d8bbc696fe19f796b',
{
'lines': '1-18',
'origin': 'https://github.com/python/cpython'
}),
('swh:1:dir:0b6959356d30f1a4e9b7f6bca59b9a336464c03d;origin=deb://Debian/packages/linuxdoc-tools', # noqa
'dir', '1', '0b6959356d30f1a4e9b7f6bca59b9a336464c03d',
{
'origin': 'deb://Debian/packages/linuxdoc-tools'
}),
('swh:1:dir:0b6959356d30f1a4e9b7f6bca59b9a336464c03d;invalid;malformed', # noqa
'dir', '1', '0b6959356d30f1a4e9b7f6bca59b9a336464c03d', {})
]:
expected_result = {
'namespace': 'swh',
'scheme_version': _version,
'object_type': _type,
'object_id': _hash,
'metadata': _metadata
} }
actual_result = identifiers.parse_persistent_identifier(pid) actual_result = identifiers.parse_persistent_identifier(pid)
self.assertEquals(actual_result, expected_result) self.assertEquals(actual_result, expected_result)
v0.0.22-0-ga06122e v0.0.23-0-g448eafa
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment