Page MenuHomeSoftware Heritage

D5188.id23017.diff
No OneTemporary

D5188.id23017.diff

diff --git a/swh/web/api/views/identifiers.py b/swh/web/api/views/identifiers.py
--- a/swh/web/api/views/identifiers.py
+++ b/swh/web/api/views/identifiers.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2020 The Software Heritage developers
+# Copyright (C) 2018-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -54,14 +54,14 @@
# object is present in the archive, NotFoundExc
# will be raised otherwise
swhid_parsed = swhid_resolved["swhid_parsed"]
- object_type = swhid_parsed.object_type.name.lower()
+ object_type = swhid_parsed.object_type
object_id = hash_to_hex(swhid_parsed.object_id)
- archive.lookup_object(object_type, object_id)
+ archive.lookup_object(swhid_parsed.object_type, object_id)
# id is well-formed and the pointed object exists
return {
"namespace": swhid_parsed.namespace,
"scheme_version": swhid_parsed.scheme_version,
- "object_type": object_type,
+ "object_type": object_type.name.lower(),
"object_id": object_id,
"metadata": swhid_parsed.qualifiers(),
"browse_url": request.build_absolute_uri(swhid_resolved["browse_url"]),
diff --git a/swh/web/browse/snapshot_context.py b/swh/web/browse/snapshot_context.py
--- a/swh/web/browse/snapshot_context.py
+++ b/swh/web/browse/snapshot_context.py
@@ -13,15 +13,7 @@
from django.utils.html import escape
from swh.model.hashutil import hash_to_bytes
-from swh.model.identifiers import (
- CONTENT,
- DIRECTORY,
- RELEASE,
- REVISION,
- SNAPSHOT,
- CoreSWHID,
- ObjectType,
-)
+from swh.model.identifiers import CoreSWHID, ObjectType
from swh.model.model import Snapshot
from swh.web.browse.utils import (
content_display_max_size,
@@ -806,16 +798,22 @@
revision_found = False
if sha1_git is not None:
- swh_objects.append(SWHObjectInfo(object_type=DIRECTORY, object_id=sha1_git))
+ swh_objects.append(
+ SWHObjectInfo(object_type=ObjectType.DIRECTORY, object_id=sha1_git)
+ )
vault_cooking.update(
{"directory_context": True, "directory_swhid": f"swh:1:dir:{sha1_git}",}
)
if revision_found:
- swh_objects.append(SWHObjectInfo(object_type=REVISION, object_id=revision_id))
+ swh_objects.append(
+ SWHObjectInfo(object_type=ObjectType.REVISION, object_id=revision_id)
+ )
vault_cooking.update(
{"revision_context": True, "revision_swhid": f"swh:1:rev:{revision_id}",}
)
- swh_objects.append(SWHObjectInfo(object_type=SNAPSHOT, object_id=snapshot_id))
+ swh_objects.append(
+ SWHObjectInfo(object_type=ObjectType.SNAPSHOT, object_id=snapshot_id)
+ )
visit_date = None
visit_type = None
@@ -825,10 +823,12 @@
release_id = snapshot_context["release_id"]
if release_id:
- swh_objects.append(SWHObjectInfo(object_type=RELEASE, object_id=release_id))
+ swh_objects.append(
+ SWHObjectInfo(object_type=ObjectType.RELEASE, object_id=release_id)
+ )
dir_metadata = DirectoryMetadata(
- object_type=DIRECTORY,
+ object_type=ObjectType.DIRECTORY,
object_id=sha1_git,
directory=sha1_git,
nb_files=nb_files,
@@ -984,10 +984,12 @@
content_checksums = content_data.get("checksums", {})
swh_objects = [
- SWHObjectInfo(object_type=CONTENT, object_id=content_checksums.get("sha1_git")),
- SWHObjectInfo(object_type=DIRECTORY, object_id=directory_id),
- SWHObjectInfo(object_type=REVISION, object_id=revision_id),
- SWHObjectInfo(object_type=SNAPSHOT, object_id=snapshot_id),
+ SWHObjectInfo(
+ object_type=ObjectType.CONTENT, object_id=content_checksums.get("sha1_git")
+ ),
+ SWHObjectInfo(object_type=ObjectType.DIRECTORY, object_id=directory_id),
+ SWHObjectInfo(object_type=ObjectType.REVISION, object_id=revision_id),
+ SWHObjectInfo(object_type=ObjectType.SNAPSHOT, object_id=snapshot_id),
]
visit_date = None
@@ -998,10 +1000,12 @@
release_id = snapshot_context["release_id"]
if release_id:
- swh_objects.append(SWHObjectInfo(object_type=RELEASE, object_id=release_id))
+ swh_objects.append(
+ SWHObjectInfo(object_type=ObjectType.RELEASE, object_id=release_id)
+ )
content_metadata = ContentMetadata(
- object_type=CONTENT,
+ object_type=ObjectType.CONTENT,
object_id=content_checksums.get("sha1_git"),
sha1=content_checksums.get("sha1"),
sha1_git=content_checksums.get("sha1_git"),
@@ -1175,13 +1179,15 @@
revision_metadata["origin visit type"] = visit_info["type"]
swh_objects = [
- SWHObjectInfo(object_type=REVISION, object_id=revision_id),
- SWHObjectInfo(object_type=SNAPSHOT, object_id=snapshot_id),
+ SWHObjectInfo(object_type=ObjectType.REVISION, object_id=revision_id),
+ SWHObjectInfo(object_type=ObjectType.SNAPSHOT, object_id=snapshot_id),
]
release_id = snapshot_context["release_id"]
if release_id:
- swh_objects.append(SWHObjectInfo(object_type=RELEASE, object_id=release_id))
+ swh_objects.append(
+ SWHObjectInfo(object_type=ObjectType.RELEASE, object_id=release_id)
+ )
browse_rel_link = gen_release_link(release_id)
revision_metadata["release"] = release_id
revision_metadata["context-independent release"] = browse_rel_link
diff --git a/swh/web/browse/views/content.py b/swh/web/browse/views/content.py
--- a/swh/web/browse/views/content.py
+++ b/swh/web/browse/views/content.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017-2020 The Software Heritage developers
+# Copyright (C) 2017-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -12,7 +12,7 @@
from django.shortcuts import render
from swh.model.hashutil import hash_to_hex
-from swh.model.identifiers import CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT
+from swh.model.identifiers import ObjectType
from swh.web.browse.browseurls import browse_route
from swh.web.browse.snapshot_context import get_snapshot_context
from swh.web.browse.utils import (
@@ -208,7 +208,7 @@
release_name=request.GET.get("release"),
revision_id=request.GET.get("revision"),
path=path,
- browse_context=CONTENT,
+ browse_context="content",
)
except NotFoundExc as e:
if str(e).startswith("Origin"):
@@ -305,7 +305,7 @@
)
content_metadata = ContentMetadata(
- object_type=CONTENT,
+ object_type=ObjectType.CONTENT,
object_id=content_checksums.get("sha1_git"),
sha1=content_checksums.get("sha1"),
sha1_git=content_checksums.get("sha1_git"),
@@ -327,27 +327,34 @@
)
swh_objects = [
- SWHObjectInfo(object_type=CONTENT, object_id=content_checksums.get("sha1_git"))
+ SWHObjectInfo(
+ object_type=ObjectType.CONTENT, object_id=content_checksums.get("sha1_git")
+ )
]
if directory_id:
- swh_objects.append(SWHObjectInfo(object_type=DIRECTORY, object_id=directory_id))
+ swh_objects.append(
+ SWHObjectInfo(object_type=ObjectType.DIRECTORY, object_id=directory_id)
+ )
if snapshot_context:
swh_objects.append(
SWHObjectInfo(
- object_type=REVISION, object_id=snapshot_context["revision_id"]
+ object_type=ObjectType.REVISION,
+ object_id=snapshot_context["revision_id"],
)
)
swh_objects.append(
SWHObjectInfo(
- object_type=SNAPSHOT, object_id=snapshot_context["snapshot_id"]
+ object_type=ObjectType.SNAPSHOT,
+ object_id=snapshot_context["snapshot_id"],
)
)
if snapshot_context["release_id"]:
swh_objects.append(
SWHObjectInfo(
- object_type=RELEASE, object_id=snapshot_context["release_id"]
+ object_type=ObjectType.RELEASE,
+ object_id=snapshot_context["release_id"],
)
)
diff --git a/swh/web/browse/views/directory.py b/swh/web/browse/views/directory.py
--- a/swh/web/browse/views/directory.py
+++ b/swh/web/browse/views/directory.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017-2020 The Software Heritage developers
+# Copyright (C) 2017-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -10,7 +10,7 @@
from django.http import HttpResponse
from django.shortcuts import redirect, render
-from swh.model.identifiers import DIRECTORY, RELEASE, REVISION, SNAPSHOT
+from swh.model.identifiers import ObjectType
from swh.web.browse.browseurls import browse_route
from swh.web.browse.snapshot_context import get_snapshot_context
from swh.web.browse.utils import gen_link, get_directory_entries, get_readme_to_display
@@ -135,7 +135,7 @@
readme_name, readme_url, readme_html = get_readme_to_display(readmes)
dir_metadata = DirectoryMetadata(
- object_type=DIRECTORY,
+ object_type=ObjectType.DIRECTORY,
object_id=sha1_git,
directory=root_sha1_git,
nb_files=len(files),
@@ -156,23 +156,26 @@
"revision_swhid": None,
}
- swh_objects = [SWHObjectInfo(object_type=DIRECTORY, object_id=sha1_git)]
+ swh_objects = [SWHObjectInfo(object_type=ObjectType.DIRECTORY, object_id=sha1_git)]
if snapshot_context:
swh_objects.append(
SWHObjectInfo(
- object_type=REVISION, object_id=snapshot_context["revision_id"]
+ object_type=ObjectType.REVISION,
+ object_id=snapshot_context["revision_id"],
)
)
swh_objects.append(
SWHObjectInfo(
- object_type=SNAPSHOT, object_id=snapshot_context["snapshot_id"]
+ object_type=ObjectType.SNAPSHOT,
+ object_id=snapshot_context["snapshot_id"],
)
)
if snapshot_context["release_id"]:
swh_objects.append(
SWHObjectInfo(
- object_type=RELEASE, object_id=snapshot_context["release_id"]
+ object_type=ObjectType.RELEASE,
+ object_id=snapshot_context["release_id"],
)
)
diff --git a/swh/web/browse/views/release.py b/swh/web/browse/views/release.py
--- a/swh/web/browse/views/release.py
+++ b/swh/web/browse/views/release.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017-2020 The Software Heritage developers
+# Copyright (C) 2017-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -7,7 +7,7 @@
from django.shortcuts import render
-from swh.model.identifiers import CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT
+from swh.model.identifiers import ObjectType
from swh.web.browse.browseurls import browse_route
from swh.web.browse.snapshot_context import get_snapshot_context
from swh.web.browse.utils import (
@@ -81,7 +81,7 @@
snapshot_id = snapshot_context.get("snapshot_id", None)
release_metadata = ReleaseMetadata(
- object_type=RELEASE,
+ object_type=ObjectType.RELEASE,
object_id=sha1_git,
release=sha1_git,
author=release["author"]["fullname"] if release["author"] else "None",
@@ -101,13 +101,13 @@
if release["message"]:
release_note_lines = release["message"].split("\n")
- swh_objects = [SWHObjectInfo(object_type=RELEASE, object_id=sha1_git)]
+ swh_objects = [SWHObjectInfo(object_type=ObjectType.RELEASE, object_id=sha1_git)]
vault_cooking = None
rev_directory = None
target_link = None
- if release["target_type"] == REVISION:
+ if release["target_type"] == ObjectType.REVISION.name.lower():
target_link = gen_revision_link(
release["target"],
snapshot_context=snapshot_context,
@@ -124,14 +124,16 @@
"revision_swhid": f"swh:1:rev:{release['target']}",
}
swh_objects.append(
- SWHObjectInfo(object_type=REVISION, object_id=release["target"])
+ SWHObjectInfo(
+ object_type=ObjectType.REVISION, object_id=release["target"]
+ )
)
swh_objects.append(
- SWHObjectInfo(object_type=DIRECTORY, object_id=rev_directory)
+ SWHObjectInfo(object_type=ObjectType.DIRECTORY, object_id=rev_directory)
)
except Exception as exc:
sentry_sdk.capture_exception(exc)
- elif release["target_type"] == DIRECTORY:
+ elif release["target_type"] == ObjectType.DIRECTORY.name.lower():
target_link = gen_directory_link(
release["target"],
snapshot_context=snapshot_context,
@@ -148,11 +150,13 @@
"revision_swhid": None,
}
swh_objects.append(
- SWHObjectInfo(object_type=DIRECTORY, object_id=release["target"])
+ SWHObjectInfo(
+ object_type=ObjectType.DIRECTORY, object_id=release["target"]
+ )
)
except Exception as exc:
sentry_sdk.capture_exception(exc)
- elif release["target_type"] == CONTENT:
+ elif release["target_type"] == ObjectType.CONTENT.name.lower():
target_link = gen_content_link(
release["target"],
snapshot_context=snapshot_context,
@@ -160,9 +164,9 @@
link_attrs=None,
)
swh_objects.append(
- SWHObjectInfo(object_type=CONTENT, object_id=release["target"])
+ SWHObjectInfo(object_type=ObjectType.CONTENT, object_id=release["target"])
)
- elif release["target_type"] == RELEASE:
+ elif release["target_type"] == ObjectType.RELEASE.name.lower():
target_link = gen_release_link(
release["target"],
snapshot_context=snapshot_context,
@@ -202,7 +206,9 @@
snapshot_id = snapshot_context["snapshot_id"]
if snapshot_id:
- swh_objects.append(SWHObjectInfo(object_type=SNAPSHOT, object_id=snapshot_id))
+ swh_objects.append(
+ SWHObjectInfo(object_type=ObjectType.SNAPSHOT, object_id=snapshot_id)
+ )
swhids_info = get_swhids_info(swh_objects, snapshot_context)
diff --git a/swh/web/browse/views/revision.py b/swh/web/browse/views/revision.py
--- a/swh/web/browse/views/revision.py
+++ b/swh/web/browse/views/revision.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017-2020 The Software Heritage developers
+# Copyright (C) 2017-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -12,14 +12,7 @@
from django.utils.safestring import mark_safe
from swh.model.hashutil import hash_to_bytes
-from swh.model.identifiers import (
- CONTENT,
- DIRECTORY,
- REVISION,
- SNAPSHOT,
- CoreSWHID,
- ObjectType,
-)
+from swh.model.identifiers import CoreSWHID, ObjectType
from swh.web.browse.browseurls import browse_route
from swh.web.browse.snapshot_context import get_snapshot_context
from swh.web.browse.utils import (
@@ -377,7 +370,7 @@
dirs, files = get_directory_entries(dir_id)
revision_metadata = RevisionMetadata(
- object_type=REVISION,
+ object_type=ObjectType.REVISION,
object_id=sha1_git,
revision=sha1_git,
author=revision["author"]["fullname"] if revision["author"] else "None",
@@ -448,7 +441,7 @@
"revision_swhid": f"swh:1:rev:{sha1_git}",
}
- swh_objects = [SWHObjectInfo(object_type=REVISION, object_id=sha1_git)]
+ swh_objects = [SWHObjectInfo(object_type=ObjectType.REVISION, object_id=sha1_git)]
content = None
content_size = None
@@ -492,7 +485,7 @@
}
swh_objects.append(
- SWHObjectInfo(object_type=CONTENT, object_id=file_info["target"])
+ SWHObjectInfo(object_type=ObjectType.CONTENT, object_id=file_info["target"])
)
else:
for d in dirs:
@@ -528,7 +521,9 @@
vault_cooking["directory_context"] = True
vault_cooking["directory_swhid"] = f"swh:1:dir:{dir_id}"
- swh_objects.append(SWHObjectInfo(object_type=DIRECTORY, object_id=dir_id))
+ swh_objects.append(
+ SWHObjectInfo(object_type=ObjectType.DIRECTORY, object_id=dir_id)
+ )
query_params.pop("path", None)
@@ -537,7 +532,9 @@
)
if snapshot_id:
- swh_objects.append(SWHObjectInfo(object_type=SNAPSHOT, object_id=snapshot_id))
+ swh_objects.append(
+ SWHObjectInfo(object_type=ObjectType.SNAPSHOT, object_id=snapshot_id)
+ )
swhids_info = get_swhids_info(swh_objects, snapshot_context, extra_context)
diff --git a/swh/web/common/archive.py b/swh/web/common/archive.py
--- a/swh/web/common/archive.py
+++ b/swh/web/common/archive.py
@@ -11,14 +11,7 @@
from urllib.parse import urlparse
from swh.model import hashutil
-from swh.model.identifiers import (
- CONTENT,
- DIRECTORY,
- RELEASE,
- REVISION,
- SNAPSHOT,
- CoreSWHID,
-)
+from swh.model.identifiers import ObjectType, CoreSWHID
from swh.model.model import OriginVisit, Revision
from swh.storage.algos import diff, revisions_walker
from swh.storage.algos.origin import origin_get_latest_visit_status
@@ -26,7 +19,7 @@
from swh.vault.exc import NotFoundExc as VaultNotFoundExc
from swh.web import config
from swh.web.common import converters, query
-from swh.web.common.exc import BadInputExc, NotFoundExc
+from swh.web.common.exc import NotFoundExc
from swh.web.common.typing import (
OriginInfo,
OriginMetadataInfo,
@@ -1331,7 +1324,7 @@
return _RevisionsWalkerProxy(rev_walker_type, rev_start, *args, **kwargs)
-def lookup_object(object_type: str, object_id: str) -> Dict[str, Any]:
+def lookup_object(object_type: ObjectType, object_id: str) -> Dict[str, Any]:
"""
Utility function for looking up an object in the archive by its type
and id.
@@ -1351,24 +1344,18 @@
the archive
BadInputExc: if the object identifier is invalid
"""
- if object_type == CONTENT:
+ if object_type == ObjectType.CONTENT:
return lookup_content(f"sha1_git:{object_id}")
- elif object_type == DIRECTORY:
+ elif object_type == ObjectType.DIRECTORY:
return {"id": object_id, "content": list(lookup_directory(object_id))}
- elif object_type == RELEASE:
+ elif object_type == ObjectType.RELEASE:
return lookup_release(object_id)
- elif object_type == REVISION:
+ elif object_type == ObjectType.REVISION:
return lookup_revision(object_id)
- elif object_type == SNAPSHOT:
+ elif object_type == ObjectType.SNAPSHOT:
return lookup_snapshot(object_id)
-
- raise BadInputExc(
- (
- "Invalid swh object type! Valid types are "
- f"{CONTENT}, {DIRECTORY}, {RELEASE} "
- f"{REVISION} or {SNAPSHOT}."
- )
- )
+ else:
+ raise ValueError(f"Unexpected object type variant: {object_type}")
def lookup_missing_hashes(grouped_swhids: Dict[str, List[bytes]]) -> Set[str]:
@@ -1385,15 +1372,15 @@
missing_hashes = []
for obj_type, obj_ids in grouped_swhids.items():
- if obj_type == CONTENT:
+ if obj_type == ObjectType.CONTENT:
missing_hashes.append(storage.content_missing_per_sha1_git(obj_ids))
- elif obj_type == DIRECTORY:
+ elif obj_type == ObjectType.DIRECTORY:
missing_hashes.append(storage.directory_missing(obj_ids))
- elif obj_type == REVISION:
+ elif obj_type == ObjectType.REVISION:
missing_hashes.append(storage.revision_missing(obj_ids))
- elif obj_type == RELEASE:
+ elif obj_type == ObjectType.RELEASE:
missing_hashes.append(storage.release_missing(obj_ids))
- elif obj_type == SNAPSHOT:
+ elif obj_type == ObjectType.SNAPSHOT:
missing_hashes.append(storage.snapshot_missing(obj_ids))
missing = set(
diff --git a/swh/web/common/converters.py b/swh/web/common/converters.py
--- a/swh/web/common/converters.py
+++ b/swh/web/common/converters.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2020 The Software Heritage developers
+# Copyright (C) 2015-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -7,8 +7,11 @@
import json
from typing import Any, Dict, Union
+from django.core.serializers.json import DjangoJSONEncoder
+
from swh.core.utils import decode_with_escape
from swh.model import hashutil
+from swh.model.identifiers import ObjectType
from swh.model.model import RawExtrinsicMetadata, Release, Revision
from swh.storage.interface import PartialBranches
from swh.web.common.typing import OriginInfo, OriginVisitInfo
@@ -229,6 +232,17 @@
)
+class SWHDjangoJSONEncoder(DjangoJSONEncoder):
+ """Wrapper around DjangoJSONEncoder to serialize SWH-specific types
+ found in :class:`swh.web.common.typing.SWHObjectInfo`."""
+
+ def default(self, o):
+ if isinstance(o, ObjectType):
+ return o.name.lower()
+ else:
+ super().default(o)
+
+
class SWHMetadataEncoder(json.JSONEncoder):
"""Special json encoder for metadata field which can contain bytes
encoded value.
diff --git a/swh/web/common/identifiers.py b/swh/web/common/identifiers.py
--- a/swh/web/common/identifiers.py
+++ b/swh/web/common/identifiers.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2020 The Software Heritage developers
+# Copyright (C) 2020-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -12,15 +12,7 @@
from swh.model.exceptions import ValidationError
from swh.model.hashutil import hash_to_bytes, hash_to_hex
-from swh.model.identifiers import (
- CONTENT,
- DIRECTORY,
- RELEASE,
- REVISION,
- SNAPSHOT,
- ObjectType,
- QualifiedSWHID,
-)
+from swh.model.identifiers import ObjectType, QualifiedSWHID
from swh.web.common import archive
from swh.web.common.exc import BadInputExc
from swh.web.common.typing import (
@@ -33,8 +25,18 @@
from swh.web.common.utils import reverse
+def parse_object_type(object_type: str) -> ObjectType:
+ try:
+ return ObjectType[object_type.upper()]
+ except KeyError:
+ valid_types = ", ".join(variant.name.lower() for variant in ObjectType)
+ raise BadInputExc(
+ f"Invalid swh object type! Valid types are {valid_types}; not {object_type}"
+ )
+
+
def gen_swhid(
- object_type: str,
+ object_type: ObjectType,
object_id: str,
scheme_version: int = 1,
metadata: SWHIDContext = {},
@@ -61,11 +63,10 @@
generate a valid identifier
"""
try:
- decoded_object_type = ObjectType[object_type.upper()]
decoded_object_id = hash_to_bytes(object_id)
obj_swhid = str(
QualifiedSWHID(
- object_type=decoded_object_type,
+ object_type=object_type,
object_id=decoded_object_id,
scheme_version=scheme_version,
**metadata,
@@ -136,7 +137,7 @@
release = archive.lookup_release(
hash_to_hex(swhid_parsed.anchor.object_id)
)
- if release["target_type"] == REVISION:
+ if release["target_type"] == ObjectType.REVISION.name.lower():
revision = archive.lookup_revision(release["target"])
directory = revision["directory"]
if object_type == ObjectType.CONTENT:
@@ -241,7 +242,7 @@
raise BadInputExc("Error when parsing identifier: %s" % " ".join(ve.messages))
-def group_swhids(swhids: Iterable[QualifiedSWHID],) -> Dict[str, List[bytes]]:
+def group_swhids(swhids: Iterable[QualifiedSWHID],) -> Dict[ObjectType, List[bytes]]:
"""
Groups many SoftWare Heritage persistent IDentifiers into a
dictionary depending on their type.
@@ -255,18 +256,18 @@
keys: object types
values: object hashes
"""
- swhids_by_type: Dict[str, List[bytes]] = {
- CONTENT: [],
- DIRECTORY: [],
- REVISION: [],
- RELEASE: [],
- SNAPSHOT: [],
+ swhids_by_type: Dict[ObjectType, List[bytes]] = {
+ ObjectType.CONTENT: [],
+ ObjectType.DIRECTORY: [],
+ ObjectType.REVISION: [],
+ ObjectType.RELEASE: [],
+ ObjectType.SNAPSHOT: [],
}
for obj_swhid in swhids:
obj_id = obj_swhid.object_id
obj_type = obj_swhid.object_type
- swhids_by_type[obj_type.name.lower()].append(hash_to_bytes(obj_id))
+ swhids_by_type[obj_type].append(hash_to_bytes(obj_id))
return swhids_by_type
@@ -313,47 +314,49 @@
swhid_context["origin"] = quote(
snapshot_context["origin_info"]["url"], safe="/?:@&"
)
- if object_type != SNAPSHOT:
+ if object_type != ObjectType.SNAPSHOT:
swhid_context["visit"] = gen_swhid(
- SNAPSHOT, snapshot_context["snapshot_id"]
+ ObjectType.SNAPSHOT, snapshot_context["snapshot_id"]
)
- if object_type in (CONTENT, DIRECTORY):
+ if object_type in (ObjectType.CONTENT, ObjectType.DIRECTORY):
if snapshot_context["release_id"] is not None:
swhid_context["anchor"] = gen_swhid(
- RELEASE, snapshot_context["release_id"]
+ ObjectType.RELEASE, snapshot_context["release_id"]
)
elif snapshot_context["revision_id"] is not None:
swhid_context["anchor"] = gen_swhid(
- REVISION, snapshot_context["revision_id"]
+ ObjectType.REVISION, snapshot_context["revision_id"]
)
- if object_type in (CONTENT, DIRECTORY):
+ if object_type in (ObjectType.CONTENT, ObjectType.DIRECTORY):
if (
extra_context
and "revision" in extra_context
and extra_context["revision"]
and "anchor" not in swhid_context
):
- swhid_context["anchor"] = gen_swhid(REVISION, extra_context["revision"])
+ swhid_context["anchor"] = gen_swhid(
+ ObjectType.REVISION, extra_context["revision"]
+ )
elif (
extra_context
and "root_directory" in extra_context
and extra_context["root_directory"]
and "anchor" not in swhid_context
and (
- object_type != DIRECTORY
+ object_type != ObjectType.DIRECTORY
or extra_context["root_directory"] != object_id
)
):
swhid_context["anchor"] = gen_swhid(
- DIRECTORY, extra_context["root_directory"]
+ ObjectType.DIRECTORY, extra_context["root_directory"]
)
path = None
if extra_context and "path" in extra_context:
path = extra_context["path"] or "/"
- if "filename" in extra_context and object_type == CONTENT:
+ if "filename" in extra_context and object_type == ObjectType.CONTENT:
path += extra_context["filename"]
- if object_type == DIRECTORY and path == "/":
+ if object_type == ObjectType.DIRECTORY and path == "/":
path = None
if path:
swhid_context["path"] = quote(path, safe="/?:@&")
diff --git a/swh/web/common/swh_templatetags.py b/swh/web/common/swh_templatetags.py
--- a/swh/web/common/swh_templatetags.py
+++ b/swh/web/common/swh_templatetags.py
@@ -7,9 +7,9 @@
import re
from django import template
-from django.core.serializers.json import DjangoJSONEncoder
from django.utils.safestring import mark_safe
+from swh.web.common.converters import SWHDjangoJSONEncoder
from swh.web.common.origin_save import get_savable_visit_types
from swh.web.common.utils import rst_to_html
@@ -79,7 +79,7 @@
JSON representation of the variable.
"""
- return mark_safe(json.dumps(obj, cls=DjangoJSONEncoder))
+ return mark_safe(json.dumps(obj, cls=SWHDjangoJSONEncoder))
@register.filter
diff --git a/swh/web/common/typing.py b/swh/web/common/typing.py
--- a/swh/web/common/typing.py
+++ b/swh/web/common/typing.py
@@ -10,6 +10,7 @@
from django.http import QueryDict
from swh.core.api.classes import PagedResult as CorePagedResult
+from swh.model.identifiers import ObjectType
QueryParameters = Union[Dict[str, Any], QueryDict]
@@ -133,7 +134,7 @@
class SWHObjectInfo(TypedDict):
- object_type: str
+ object_type: ObjectType
object_id: str
diff --git a/swh/web/misc/badges.py b/swh/web/misc/badges.py
--- a/swh/web/misc/badges.py
+++ b/swh/web/misc/badges.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2019-2020 The Software Heritage developers
+# Copyright (C) 2019-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -14,10 +14,10 @@
from swh.model.exceptions import ValidationError
from swh.model.hashutil import hash_to_bytes, hash_to_hex
-from swh.model.identifiers import RELEASE, CoreSWHID, ObjectType, QualifiedSWHID
+from swh.model.identifiers import CoreSWHID, ObjectType, QualifiedSWHID
from swh.web.common import archive
from swh.web.common.exc import BadInputExc, NotFoundExc
-from swh.web.common.identifiers import resolve_swhid
+from swh.web.common.identifiers import parse_object_type, resolve_swhid
from swh.web.common.utils import reverse
_orange = "#f36a24"
@@ -92,9 +92,9 @@
# from it
if object_swhid:
parsed_swhid = QualifiedSWHID.from_string(object_swhid)
- object_type = parsed_swhid.object_type.name.lower()
+ parsed_object_type = parsed_swhid.object_type
object_id = hash_to_hex(parsed_swhid.object_id)
- swh_object = archive.lookup_object(object_type, object_id)
+ swh_object = archive.lookup_object(parsed_swhid.object_type, object_id)
# remove SWHID qualified if any for badge text
right_text = str(
CoreSWHID(
@@ -102,18 +102,20 @@
object_id=parsed_swhid.object_id,
)
)
+ object_type = parsed_swhid.object_type.name.lower()
else:
+ parsed_object_type = parse_object_type(object_type)
right_text = str(
CoreSWHID(
- object_type=ObjectType[object_type.upper()],
+ object_type=parsed_object_type,
object_id=hash_to_bytes(object_id),
)
)
- swh_object = archive.lookup_object(object_type, object_id)
+ swh_object = archive.lookup_object(parsed_object_type, object_id)
whole_link = resolve_swhid(str(right_text))["browse_url"]
# use release name for badge text
- if object_type == RELEASE:
+ if parsed_object_type == ObjectType.RELEASE:
right_text = "release %s" % swh_object["name"]
left_text = "archived"
except (BadInputExc, ValidationError):
diff --git a/swh/web/misc/iframe.py b/swh/web/misc/iframe.py
--- a/swh/web/misc/iframe.py
+++ b/swh/web/misc/iframe.py
@@ -10,14 +10,7 @@
from django.views.decorators.clickjacking import xframe_options_exempt
from swh.model.hashutil import hash_to_bytes
-from swh.model.identifiers import (
- CONTENT,
- DIRECTORY,
- REVISION,
- SNAPSHOT,
- ObjectType,
- QualifiedSWHID,
-)
+from swh.model.identifiers import ObjectType, QualifiedSWHID
from swh.web.browse.snapshot_context import get_snapshot_context
from swh.web.browse.utils import (
content_display_max_size,
@@ -220,7 +213,8 @@
view_data = _get_content_rendering_data(parsed_swhid, path)
swh_objects.append(
SWHObjectInfo(
- object_type=CONTENT, object_id=parsed_swhid.object_id.hex()
+ object_type=ObjectType.CONTENT,
+ object_id=parsed_swhid.object_id.hex(),
)
)
@@ -230,7 +224,8 @@
)
swh_objects.append(
SWHObjectInfo(
- object_type=DIRECTORY, object_id=parsed_swhid.object_id.hex()
+ object_type=ObjectType.DIRECTORY,
+ object_id=parsed_swhid.object_id.hex(),
)
)
@@ -251,7 +246,8 @@
if parsed_swhid.object_type == ObjectType.CONTENT and len(breadcrumbs) > 1:
swh_objects.append(
SWHObjectInfo(
- object_type=DIRECTORY, object_id=breadcrumbs[-2]["object_id"]
+ object_type=ObjectType.DIRECTORY,
+ object_id=breadcrumbs[-2]["object_id"],
)
)
swhids_info_extra_context["path"] = breadcrumbs[-2]["path"]
@@ -260,13 +256,13 @@
if snapshot_context:
swh_objects.append(
SWHObjectInfo(
- object_type=REVISION,
+ object_type=ObjectType.REVISION,
object_id=snapshot_context["revision_id"] or "",
)
)
swh_objects.append(
SWHObjectInfo(
- object_type=SNAPSHOT,
+ object_type=ObjectType.SNAPSHOT,
object_id=snapshot_context["snapshot_id"] or "",
)
)
diff --git a/swh/web/templates/includes/show-metadata.html b/swh/web/templates/includes/show-metadata.html
--- a/swh/web/templates/includes/show-metadata.html
+++ b/swh/web/templates/includes/show-metadata.html
@@ -1,5 +1,5 @@
{% comment %}
-Copyright (C) 2017-2020 The Software Heritage developers
+Copyright (C) 2017-2021 The Software Heritage developers
See the AUTHORS file at the top-level directory of this distribution
License: GNU Affero General Public License version 3, or any later version
See top-level LICENSE file for more information
@@ -38,7 +38,7 @@
<div class="dropdown-menu swh-extrinsic-metadata-menu">
{% for swhid_info in swhids_info %}
<a href="{% url 'api-1-raw-extrinsic-metadata-swhid-authorities' swhid_info.swhid %}" class="dropdown-item" role="button">
- <i class="{{ swh_object_icons|key_value:swhid_info.object_type }} mdi-fw" aria-hidden="true"></i>
+ <i class="{{ swh_object_icons|key_value:swhid_info.object_type.name.lower }} mdi-fw" aria-hidden="true"></i>
{{swhid_info.object_type}}
</a>
{% endfor %}
diff --git a/swh/web/templates/includes/show-swhids.html b/swh/web/templates/includes/show-swhids.html
--- a/swh/web/templates/includes/show-swhids.html
+++ b/swh/web/templates/includes/show-swhids.html
@@ -33,14 +33,14 @@
{% for swhid_info in swhids_info %}
{% if forloop.first %}
<li class="nav-item">
- <a class="nav-link active" href="#swhid-tab-{{ swhid_info.object_type }}" data-toggle="tab" onclick="swh.browse.swhIdObjectTypeToggled(event)">
- <i class="{{ swh_object_icons|key_value:swhid_info.object_type }} mdi-fw" aria-hidden="true"></i>{{ swhid_info.object_type }}
+ <a class="nav-link active" href="#swhid-tab-{{ swhid_info.object_type.name.lower }}" data-toggle="tab" onclick="swh.browse.swhIdObjectTypeToggled(event)">
+ <i class="{{ swh_object_icons|key_value:swhid_info.object_type.name.lower }} mdi-fw" aria-hidden="true"></i>{{ swhid_info.object_type.name.lower }}
</a>
</li>
{% else %}
<li class="nav-item">
- <a class="nav-link" href="#swhid-tab-{{ swhid_info.object_type }}" data-toggle="tab" onclick="swh.browse.swhIdObjectTypeToggled(event)">
- <i class="{{ swh_object_icons|key_value:swhid_info.object_type }} mdi-fw" aria-hidden="true"></i>{{ swhid_info.object_type }}
+ <a class="nav-link" href="#swhid-tab-{{ swhid_info.object_type.name.lower }}" data-toggle="tab" onclick="swh.browse.swhIdObjectTypeToggled(event)">
+ <i class="{{ swh_object_icons|key_value:swhid_info.object_type.name.lower }} mdi-fw" aria-hidden="true"></i>{{ swhid_info.object_type.name.lower }}
</a>
</li>
{% endif %}
@@ -50,9 +50,9 @@
<div class="tab-content">
{% for swhid_info in swhids_info %}
{% if forloop.first %}
- <div class="tab-pane active" id="swhid-tab-{{ swhid_info.object_type }}">
+ <div class="tab-pane active" id="swhid-tab-{{ swhid_info.object_type.name.lower }}">
{% else %}
- <div class="tab-pane" id="swhid-tab-{{ swhid_info.object_type }}">
+ <div class="tab-pane" id="swhid-tab-{{ swhid_info.object_type.name.lower }}">
{% endif %}
<div class="card">
<div class="card-body swhid-ui">
@@ -65,14 +65,14 @@
title="Click to display badge integration info">
{% endif %}
{% if swhid_info.object_id %}
- <img class="swh-badge swh-badge-{{ swhid_info.object_type }}"
- src="{% url 'swh-badge' swhid_info.object_type swhid_info.object_id %}"
- onclick="swh.webapp.showBadgeInfoModal('{{ swhid_info.object_type }}', $(this).parent().parent().find('.swhid').text())"
+ <img class="swh-badge swh-badge-{{ swhid_info.object_type.name.lower }}"
+ src="{% url 'swh-badge' swhid_info.object_type.name.lower swhid_info.object_id %}"
+ onclick="swh.webapp.showBadgeInfoModal('{{ swhid_info.object_type.name.lower }}', $(this).parent().parent().find('.swhid').text())"
title="Click to display badge integration info">
{% endif %}
- {% if swhid_info.object_type == "content" or swhid_info.object_type == "directory" %}
+ {% if swhid_info.object_type.name.lower == "content" or swhid_info.object_type.name.lower == "directory" %}
<a class="float-right" style="cursor: pointer;"
- onclick="swh.webapp.showIframeInfoModal('{{ swhid_info.object_type }}', $(this).parent().parent().find('.swhid').text())">
+ onclick="swh.webapp.showIframeInfoModal('{{ swhid_info.object_type.name.lower }}', $(this).parent().parent().find('.swhid').text())">
Iframe embedding
</a>
{% endif %}
@@ -87,11 +87,11 @@
<form id="swhid-options">
<div class="custom-control custom-checkbox swhid-option">
<input class="custom-control-input swhid-context-option" value="option-origin" type="checkbox"
- id="swhid-context-option-{{ swhid_info.object_type }}"
+ id="swhid-context-option-{{ swhid_info.object_type.name.lower }}"
data-swhid-with-context="{{ swhid_info.swhid_with_context }}"
data-swhid-with-context-url="{{ swhid_info.swhid_with_context_url }}"
onclick="swh.browse.swhIdContextOptionToggled(event)">
- <label class="custom-control-label font-weight-normal" for="swhid-context-option-{{ swhid_info.object_type }}">Add contextual information</label>
+ <label class="custom-control-label font-weight-normal" for="swhid-context-option-{{ swhid_info.object_type.name.lower }}">Add contextual information</label>
</div>
</form>
</div>
diff --git a/swh/web/tests/api/test_apiresponse.py b/swh/web/tests/api/test_apiresponse.py
--- a/swh/web/tests/api/test_apiresponse.py
+++ b/swh/web/tests/api/test_apiresponse.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2019 The Software Heritage developers
+# Copyright (C) 2015-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -12,7 +12,7 @@
)
from hypothesis import given
-from swh.model.identifiers import CONTENT, DIRECTORY, REVISION
+from swh.model.identifiers import ObjectType
from swh.web.api.apiresponse import (
compute_link_header,
filter_by_fields,
@@ -163,9 +163,9 @@
assert ACCESS_CONTROL_ALLOW_ORIGIN in resp
swhids = [
- gen_swhid(CONTENT, content["sha1_git"]),
- gen_swhid(DIRECTORY, directory),
- gen_swhid(REVISION, revision),
+ gen_swhid(ObjectType.CONTENT, content["sha1_git"]),
+ gen_swhid(ObjectType.DIRECTORY, directory),
+ gen_swhid(ObjectType.REVISION, revision),
]
url = reverse("api-1-known")
ac_request_method = "POST"
diff --git a/swh/web/tests/api/views/test_identifiers.py b/swh/web/tests/api/views/test_identifiers.py
--- a/swh/web/tests/api/views/test_identifiers.py
+++ b/swh/web/tests/api/views/test_identifiers.py
@@ -1,11 +1,11 @@
-# Copyright (C) 2018-2020 The Software Heritage developers
+# Copyright (C) 2018-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
from hypothesis import given
-from swh.model.identifiers import CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT
+from swh.model.identifiers import ObjectType
from swh.web.common.identifiers import gen_swhid
from swh.web.common.utils import reverse
from swh.web.tests.data import random_sha1
@@ -31,27 +31,30 @@
):
for obj_type, obj_id in (
- (CONTENT, content["sha1_git"]),
- (DIRECTORY, directory),
- (RELEASE, release),
- (REVISION, revision),
- (SNAPSHOT, snapshot),
+ (ObjectType.CONTENT, content["sha1_git"]),
+ (ObjectType.DIRECTORY, directory),
+ (ObjectType.RELEASE, release),
+ (ObjectType.REVISION, revision),
+ (ObjectType.SNAPSHOT, snapshot),
):
swhid = gen_swhid(obj_type, obj_id, metadata={"origin": origin["url"]})
+
url = reverse("api-1-resolve-swhid", url_args={"swhid": swhid})
resp = check_api_get_responses(api_client, url, status_code=200)
- if obj_type == CONTENT:
+ if obj_type == ObjectType.CONTENT:
url_args = {"query_string": "sha1_git:%s" % obj_id}
- elif obj_type == SNAPSHOT:
+ elif obj_type == ObjectType.SNAPSHOT:
url_args = {"snapshot_id": obj_id}
else:
url_args = {"sha1_git": obj_id}
+ obj_type_str = obj_type.name.lower()
+
browse_rev_url = reverse(
- "browse-%s" % obj_type,
+ f"browse-{obj_type_str}",
url_args=url_args,
query_params={"origin_url": origin["url"]},
request=resp.wsgi_request,
@@ -62,7 +65,7 @@
"metadata": {"origin": origin["url"]},
"namespace": "swh",
"object_id": obj_id,
- "object_type": obj_type,
+ "object_type": obj_type_str,
"scheme_version": 1,
}
@@ -93,11 +96,11 @@
):
for obj_type, obj_id in (
- (CONTENT, unknown_content["sha1_git"]),
- (DIRECTORY, unknown_directory),
- (RELEASE, unknown_release),
- (REVISION, unknown_revision),
- (SNAPSHOT, unknown_snapshot),
+ (ObjectType.CONTENT, unknown_content["sha1_git"]),
+ (ObjectType.DIRECTORY, unknown_directory),
+ (ObjectType.RELEASE, unknown_release),
+ (ObjectType.REVISION, unknown_revision),
+ (ObjectType.SNAPSHOT, unknown_snapshot),
):
swhid = gen_swhid(obj_type, obj_id)
@@ -118,11 +121,11 @@
api_client, content, directory, release, revision, snapshot
):
input_swhids = [
- gen_swhid(CONTENT, content["sha1_git"]),
- gen_swhid(DIRECTORY, directory),
- gen_swhid(REVISION, revision),
- gen_swhid(RELEASE, release),
- gen_swhid(SNAPSHOT, snapshot),
+ gen_swhid(ObjectType.CONTENT, content["sha1_git"]),
+ gen_swhid(ObjectType.DIRECTORY, directory),
+ gen_swhid(ObjectType.REVISION, revision),
+ gen_swhid(ObjectType.RELEASE, release),
+ gen_swhid(ObjectType.SNAPSHOT, snapshot),
]
url = reverse("api-1-known")
@@ -134,11 +137,11 @@
@given(content(), directory())
def test_api_known_swhid_some_present(api_client, content, directory):
- content_ = gen_swhid(CONTENT, content["sha1_git"])
- directory_ = gen_swhid(DIRECTORY, directory)
- unknown_revision_ = gen_swhid(REVISION, random_sha1())
- unknown_release_ = gen_swhid(RELEASE, random_sha1())
- unknown_snapshot_ = gen_swhid(SNAPSHOT, random_sha1())
+ content_ = gen_swhid(ObjectType.CONTENT, content["sha1_git"])
+ directory_ = gen_swhid(ObjectType.DIRECTORY, directory)
+ unknown_revision_ = gen_swhid(ObjectType.REVISION, random_sha1())
+ unknown_release_ = gen_swhid(ObjectType.RELEASE, random_sha1())
+ unknown_snapshot_ = gen_swhid(ObjectType.SNAPSHOT, random_sha1())
input_swhids = [
content_,
diff --git a/swh/web/tests/browse/test_snapshot_context.py b/swh/web/tests/browse/test_snapshot_context.py
--- a/swh/web/tests/browse/test_snapshot_context.py
+++ b/swh/web/tests/browse/test_snapshot_context.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2020 The Software Heritage developers
+# Copyright (C) 2020-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -7,6 +7,7 @@
from hypothesis import given
+from swh.model.identifiers import ObjectType
from swh.web.browse.snapshot_context import (
_get_release,
get_origin_visit_snapshot,
@@ -130,7 +131,7 @@
branches_url = reverse("browse-snapshot-branches", url_args=url_args)
releases_url = reverse("browse-snapshot-releases", url_args=url_args)
is_empty = not branches and not releases
- snapshot_swhid = gen_swhid("snapshot", snapshot)
+ snapshot_swhid = gen_swhid(ObjectType.SNAPSHOT, snapshot)
snapshot_sizes = archive_data.snapshot_count_branches(snapshot)
expected = SnapshotContext(
@@ -223,7 +224,7 @@
"browse-origin-visits", query_params={"origin_url": kwargs["origin_url"]}
)
is_empty = not branches and not releases
- snapshot_swhid = gen_swhid("snapshot", snapshot)
+ snapshot_swhid = gen_swhid(ObjectType.SNAPSHOT, snapshot)
snapshot_sizes = archive_data.snapshot_count_branches(snapshot)
visit_info["url"] = reverse(
diff --git a/swh/web/tests/browse/views/test_content.py b/swh/web/tests/browse/views/test_content.py
--- a/swh/web/tests/browse/views/test_content.py
+++ b/swh/web/tests/browse/views/test_content.py
@@ -9,7 +9,7 @@
from django.utils.html import escape
-from swh.model.identifiers import CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT
+from swh.model.identifiers import ObjectType
from swh.web.browse.snapshot_context import process_snapshot_branches
from swh.web.browse.utils import (
_re_encode_content,
@@ -60,7 +60,7 @@
assert_contains(resp, escape(content_display["content_data"]))
assert_contains(resp, url_raw)
- swh_cnt_id = gen_swhid(CONTENT, sha1_git)
+ swh_cnt_id = gen_swhid(ObjectType.CONTENT, sha1_git)
swh_cnt_id_url = reverse("browse-swhid", url_args={"swhid": swh_cnt_id})
assert_contains(resp, swh_cnt_id)
assert_contains(resp, swh_cnt_id_url)
@@ -89,7 +89,7 @@
assert_contains(resp, escape(content_display["content_data"]))
assert_contains(resp, url_raw)
- swh_cnt_id = gen_swhid(CONTENT, sha1_git)
+ swh_cnt_id = gen_swhid(ObjectType.CONTENT, sha1_git)
swh_cnt_id_url = reverse("browse-swhid", url_args={"swhid": swh_cnt_id})
assert_contains(resp, swh_cnt_id)
@@ -108,7 +108,7 @@
content_display = _process_content_for_display(archive_data, content)
- swh_cnt_id = gen_swhid(CONTENT, sha1_git)
+ swh_cnt_id = gen_swhid(ObjectType.CONTENT, sha1_git)
swh_cnt_id_url = reverse("browse-swhid", url_args={"swhid": swh_cnt_id})
assert_contains(resp, swh_cnt_id_url)
assert_contains(resp, escape(content_display["content_data"]))
@@ -181,11 +181,13 @@
path = path.replace(root_dir_sha1 + "/", "").replace(filename, "")
swhid_context = {
- "anchor": gen_swhid(DIRECTORY, root_dir_sha1),
+ "anchor": gen_swhid(ObjectType.DIRECTORY, root_dir_sha1),
"path": f"/{path}{filename}",
}
- swh_cnt_id = gen_swhid(CONTENT, content["sha1_git"], metadata=swhid_context)
+ swh_cnt_id = gen_swhid(
+ ObjectType.CONTENT, content["sha1_git"], metadata=swhid_context
+ )
swh_cnt_id_url = reverse("browse-swhid", url_args={"swhid": swh_cnt_id})
assert_contains(resp, swh_cnt_id)
assert_contains(resp, swh_cnt_id_url)
@@ -449,40 +451,40 @@
assert_contains(resp, f"Branch: <strong>{branch_info['name']}</strong>")
cnt_swhid = gen_swhid(
- CONTENT,
+ ObjectType.CONTENT,
directory_file["checksums"]["sha1_git"],
metadata={
"origin": origin["url"],
- "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
- "anchor": gen_swhid(REVISION, branch_info["revision"]),
+ "visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
+ "anchor": gen_swhid(ObjectType.REVISION, branch_info["revision"]),
"path": f"/{directory_file['name']}",
},
)
assert_contains(resp, cnt_swhid)
dir_swhid = gen_swhid(
- DIRECTORY,
+ ObjectType.DIRECTORY,
directory,
metadata={
"origin": origin["url"],
- "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
- "anchor": gen_swhid(REVISION, branch_info["revision"]),
+ "visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
+ "anchor": gen_swhid(ObjectType.REVISION, branch_info["revision"]),
},
)
assert_contains(resp, dir_swhid)
rev_swhid = gen_swhid(
- REVISION,
+ ObjectType.REVISION,
branch_info["revision"],
metadata={
"origin": origin["url"],
- "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
+ "visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
},
)
assert_contains(resp, rev_swhid)
snp_swhid = gen_swhid(
- SNAPSHOT, snapshot["id"], metadata={"origin": origin["url"],},
+ ObjectType.SNAPSHOT, snapshot["id"], metadata={"origin": origin["url"],},
)
assert_contains(resp, snp_swhid)
@@ -523,50 +525,50 @@
assert_contains(resp, f"Release: <strong>{release_info['name']}</strong>")
cnt_swhid = gen_swhid(
- CONTENT,
+ ObjectType.CONTENT,
directory_file["checksums"]["sha1_git"],
metadata={
"origin": origin["url"],
- "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
- "anchor": gen_swhid(RELEASE, release_info["id"]),
+ "visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
+ "anchor": gen_swhid(ObjectType.RELEASE, release_info["id"]),
"path": f"/{directory_file['name']}",
},
)
assert_contains(resp, cnt_swhid)
dir_swhid = gen_swhid(
- DIRECTORY,
+ ObjectType.DIRECTORY,
release_info["directory"],
metadata={
"origin": origin["url"],
- "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
- "anchor": gen_swhid(RELEASE, release_info["id"]),
+ "visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
+ "anchor": gen_swhid(ObjectType.RELEASE, release_info["id"]),
},
)
assert_contains(resp, dir_swhid)
rev_swhid = gen_swhid(
- REVISION,
+ ObjectType.REVISION,
release_info["target"],
metadata={
"origin": origin["url"],
- "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
+ "visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
},
)
assert_contains(resp, rev_swhid)
rel_swhid = gen_swhid(
- RELEASE,
+ ObjectType.RELEASE,
release_info["id"],
metadata={
"origin": origin["url"],
- "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
+ "visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
},
)
assert_contains(resp, rel_swhid)
snp_swhid = gen_swhid(
- SNAPSHOT, snapshot["id"], metadata={"origin": origin["url"],},
+ ObjectType.SNAPSHOT, snapshot["id"], metadata={"origin": origin["url"],},
)
assert_contains(resp, snp_swhid)
diff --git a/swh/web/tests/browse/views/test_directory.py b/swh/web/tests/browse/views/test_directory.py
--- a/swh/web/tests/browse/views/test_directory.py
+++ b/swh/web/tests/browse/views/test_directory.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017-2020 The Software Heritage developers
+# Copyright (C) 2017-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -11,7 +11,7 @@
from swh.model.from_disk import DentryPerms
from swh.model.hashutil import hash_to_bytes, hash_to_hex
-from swh.model.identifiers import DIRECTORY, RELEASE, REVISION, SNAPSHOT
+from swh.model.identifiers import ObjectType
from swh.model.model import (
Directory,
DirectoryEntry,
@@ -236,29 +236,29 @@
assert_contains(resp, f"Branch: <strong>{branch_info['name']}</strong>")
dir_swhid = gen_swhid(
- DIRECTORY,
+ ObjectType.DIRECTORY,
directory_subdir["target"],
metadata={
"origin": origin["url"],
- "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
- "anchor": gen_swhid(REVISION, branch_info["revision"]),
+ "visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
+ "anchor": gen_swhid(ObjectType.REVISION, branch_info["revision"]),
"path": "/",
},
)
assert_contains(resp, dir_swhid)
rev_swhid = gen_swhid(
- REVISION,
+ ObjectType.REVISION,
branch_info["revision"],
metadata={
"origin": origin["url"],
- "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
+ "visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
},
)
assert_contains(resp, rev_swhid)
snp_swhid = gen_swhid(
- SNAPSHOT, snapshot["id"], metadata={"origin": origin["url"],},
+ ObjectType.SNAPSHOT, snapshot["id"], metadata={"origin": origin["url"],},
)
assert_contains(resp, snp_swhid)
@@ -300,39 +300,39 @@
assert_contains(resp, f"Release: <strong>{release_info['name']}</strong>")
dir_swhid = gen_swhid(
- DIRECTORY,
+ ObjectType.DIRECTORY,
directory_subdir["target"],
metadata={
"origin": origin["url"],
- "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
- "anchor": gen_swhid(RELEASE, release_info["id"]),
+ "visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
+ "anchor": gen_swhid(ObjectType.RELEASE, release_info["id"]),
"path": "/",
},
)
assert_contains(resp, dir_swhid)
rev_swhid = gen_swhid(
- REVISION,
+ ObjectType.REVISION,
release_info["target"],
metadata={
"origin": origin["url"],
- "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
+ "visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
},
)
assert_contains(resp, rev_swhid)
rel_swhid = gen_swhid(
- RELEASE,
+ ObjectType.RELEASE,
release_info["id"],
metadata={
"origin": origin["url"],
- "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
+ "visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
},
)
assert_contains(resp, rel_swhid)
snp_swhid = gen_swhid(
- SNAPSHOT, snapshot["id"], metadata={"origin": origin["url"],},
+ ObjectType.SNAPSHOT, snapshot["id"], metadata={"origin": origin["url"],},
)
assert_contains(resp, snp_swhid)
@@ -476,24 +476,24 @@
assert_contains(resp, "vault-cook-directory")
- swh_dir_id = gen_swhid(DIRECTORY, directory_entries[0]["dir_id"])
+ swh_dir_id = gen_swhid(ObjectType.DIRECTORY, directory_entries[0]["dir_id"])
swh_dir_id_url = reverse("browse-swhid", url_args={"swhid": swh_dir_id})
swhid_context = {}
if origin_url:
swhid_context["origin"] = origin_url
if snapshot_id:
- swhid_context["visit"] = gen_swhid(SNAPSHOT, snapshot_id)
+ swhid_context["visit"] = gen_swhid(ObjectType.SNAPSHOT, snapshot_id)
if root_directory_sha1 != directory_entries[0]["dir_id"]:
- swhid_context["anchor"] = gen_swhid(DIRECTORY, root_directory_sha1)
+ swhid_context["anchor"] = gen_swhid(ObjectType.DIRECTORY, root_directory_sha1)
if root_directory_sha1 != directory_entries[0]["dir_id"]:
- swhid_context["anchor"] = gen_swhid(DIRECTORY, root_directory_sha1)
+ swhid_context["anchor"] = gen_swhid(ObjectType.DIRECTORY, root_directory_sha1)
if revision_id:
- swhid_context["anchor"] = gen_swhid(REVISION, revision_id)
+ swhid_context["anchor"] = gen_swhid(ObjectType.REVISION, revision_id)
swhid_context["path"] = f"/{path}/" if path else None
swh_dir_id = gen_swhid(
- DIRECTORY, directory_entries[0]["dir_id"], metadata=swhid_context
+ ObjectType.DIRECTORY, directory_entries[0]["dir_id"], metadata=swhid_context
)
swh_dir_id_url = reverse("browse-swhid", url_args={"swhid": swh_dir_id})
assert_contains(resp, swh_dir_id)
diff --git a/swh/web/tests/browse/views/test_identifiers.py b/swh/web/tests/browse/views/test_identifiers.py
--- a/swh/web/tests/browse/views/test_identifiers.py
+++ b/swh/web/tests/browse/views/test_identifiers.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2020 The Software Heritage developers
+# Copyright (C) 2018-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -8,7 +8,7 @@
from hypothesis import given
-from swh.model.identifiers import CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT
+from swh.model.identifiers import ObjectType
from swh.model.model import Origin
from swh.web.common.identifiers import gen_swhid
from swh.web.common.utils import reverse
@@ -27,7 +27,7 @@
@given(content())
def test_content_id_browse(client, content):
cnt_sha1_git = content["sha1_git"]
- swhid = gen_swhid(CONTENT, cnt_sha1_git)
+ swhid = gen_swhid(ObjectType.CONTENT, cnt_sha1_git)
for swhid_ in (swhid, swhid.upper()):
url = reverse("browse-swhid", url_args={"swhid": swhid_})
@@ -43,7 +43,7 @@
@given(directory())
def test_directory_id_browse(client, directory):
- swhid = gen_swhid(DIRECTORY, directory)
+ swhid = gen_swhid(ObjectType.DIRECTORY, directory)
for swhid_ in (swhid, swhid.upper()):
url = reverse("browse-swhid", url_args={"swhid": swhid_})
@@ -58,7 +58,7 @@
@given(revision())
def test_revision_id_browse(client, revision):
- swhid = gen_swhid(REVISION, revision)
+ swhid = gen_swhid(ObjectType.REVISION, revision)
for swhid_ in (swhid, swhid.upper()):
url = reverse("browse-swhid", url_args={"swhid": swhid_})
@@ -87,7 +87,7 @@
@given(release())
def test_release_id_browse(client, release):
- swhid = gen_swhid(RELEASE, release)
+ swhid = gen_swhid(ObjectType.RELEASE, release)
for swhid_ in (swhid, swhid.upper()):
url = reverse("browse-swhid", url_args={"swhid": swhid_})
@@ -113,7 +113,7 @@
@given(snapshot())
def test_snapshot_id_browse(client, snapshot):
- swhid = gen_swhid(SNAPSHOT, snapshot)
+ swhid = gen_swhid(ObjectType.SNAPSHOT, snapshot)
for swhid_ in (swhid, swhid.upper()):
url = reverse("browse-swhid", url_args={"swhid": swhid_})
@@ -157,7 +157,9 @@
archive_data.origin_add([Origin(url=origin_url)])
swhid = gen_swhid(
- CONTENT, cnt_sha1_git, metadata={"lines": "4-20", "origin": origin_url},
+ ObjectType.CONTENT,
+ cnt_sha1_git,
+ metadata={"lines": "4-20", "origin": origin_url},
)
url = reverse("browse-swhid", url_args={"swhid": swhid})
@@ -191,7 +193,7 @@
[e for e in directory_content if e["type"] == "file"]
)
legacy_swhid = gen_swhid(
- CONTENT,
+ ObjectType.CONTENT,
directory_file["checksums"]["sha1_git"],
metadata={"origin": origin["url"]},
)
@@ -204,12 +206,12 @@
)
swhid = gen_swhid(
- CONTENT,
+ ObjectType.CONTENT,
directory_file["checksums"]["sha1_git"],
metadata={
"origin": origin["url"],
- "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
- "anchor": gen_swhid(REVISION, revision),
+ "visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
+ "anchor": gen_swhid(ObjectType.REVISION, revision),
},
)
@@ -232,7 +234,9 @@
archive_data.origin_add([Origin(url=origin)])
origin_swhid_escaped = quote(origin, safe="/?:@&")
origin_swhid_url_escaped = quote(origin, safe="/:@;")
- swhid = gen_swhid(DIRECTORY, directory, metadata={"origin": origin_swhid_escaped})
+ swhid = gen_swhid(
+ ObjectType.DIRECTORY, directory, metadata={"origin": origin_swhid_escaped}
+ )
url = reverse("browse-swhid", url_args={"swhid": swhid})
resp = check_html_get_response(client, url, status_code=302)
diff --git a/swh/web/tests/browse/views/test_origin.py b/swh/web/tests/browse/views/test_origin.py
--- a/swh/web/tests/browse/views/test_origin.py
+++ b/swh/web/tests/browse/views/test_origin.py
@@ -12,7 +12,7 @@
from django.utils.html import escape
from swh.model.hashutil import hash_to_bytes
-from swh.model.identifiers import CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT
+from swh.model.identifiers import ObjectType
from swh.model.model import (
OriginVisit,
OriginVisitStatus,
@@ -754,12 +754,12 @@
swhid_context = {
"origin": origin["url"],
- "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
- "anchor": gen_swhid(RELEASE, release_data["id"]),
+ "visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
+ "anchor": gen_swhid(ObjectType.RELEASE, release_data["id"]),
}
swh_dir_id = gen_swhid(
- DIRECTORY, revision_data["directory"], metadata=swhid_context
+ ObjectType.DIRECTORY, revision_data["directory"], metadata=swhid_context
)
swh_dir_id_url = reverse("browse-swhid", url_args={"swhid": swh_dir_id})
assert_contains(resp, swh_dir_id)
@@ -986,12 +986,14 @@
swhid_context = {
"origin": origin_info["url"],
- "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
- "anchor": gen_swhid(REVISION, head_rev_id),
+ "visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
+ "anchor": gen_swhid(ObjectType.REVISION, head_rev_id),
"path": f"/{content_path}",
}
- swh_cnt_id = gen_swhid(CONTENT, content["sha1_git"], metadata=swhid_context)
+ swh_cnt_id = gen_swhid(
+ ObjectType.CONTENT, content["sha1_git"], metadata=swhid_context
+ )
swh_cnt_id_url = reverse("browse-swhid", url_args={"swhid": swh_cnt_id})
assert_contains(resp, swh_cnt_id)
assert_contains(resp, swh_cnt_id_url)
@@ -1126,13 +1128,13 @@
swhid_context = {
"origin": origin_info["url"],
- "visit": gen_swhid(SNAPSHOT, snapshot["id"]),
- "anchor": gen_swhid(REVISION, head_rev_id),
+ "visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
+ "anchor": gen_swhid(ObjectType.REVISION, head_rev_id),
"path": f"/{path}" if path else None,
}
swh_dir_id = gen_swhid(
- DIRECTORY, directory_entries[0]["dir_id"], metadata=swhid_context
+ ObjectType.DIRECTORY, directory_entries[0]["dir_id"], metadata=swhid_context
)
swh_dir_id_url = reverse("browse-swhid", url_args={"swhid": swh_dir_id})
assert_contains(resp, swh_dir_id)
diff --git a/swh/web/tests/browse/views/test_release.py b/swh/web/tests/browse/views/test_release.py
--- a/swh/web/tests/browse/views/test_release.py
+++ b/swh/web/tests/browse/views/test_release.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2020 The Software Heritage developers
+# Copyright (C) 2018-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -9,7 +9,7 @@
from django.utils.html import escape
-from swh.model.identifiers import DIRECTORY, RELEASE, REVISION, SNAPSHOT
+from swh.model.identifiers import ObjectType
from swh.web.common.identifiers import gen_swhid
from swh.web.common.utils import format_utc_iso_date, reverse
from swh.web.tests.django_asserts import assert_contains
@@ -107,7 +107,7 @@
assert_contains(resp, target_type)
assert_contains(resp, '<a href="%s">%s</a>' % (escape(target_url), target))
- swh_rel_id = gen_swhid(RELEASE, release_id)
+ swh_rel_id = gen_swhid(ObjectType.RELEASE, release_id)
swh_rel_id_url = reverse("browse-swhid", url_args={"swhid": swh_rel_id})
assert_contains(resp, swh_rel_id)
assert_contains(resp, swh_rel_id_url)
@@ -118,7 +118,7 @@
)
assert_contains(resp, f'href="{browse_origin_url}"')
elif snapshot_id:
- swh_snp_id = gen_swhid(SNAPSHOT, snapshot_id)
+ swh_snp_id = gen_swhid(ObjectType.SNAPSHOT, snapshot_id)
swh_snp_id_url = reverse("browse-swhid", url_args={"swhid": swh_snp_id})
assert_contains(resp, f'href="{swh_snp_id_url}"')
@@ -139,9 +139,9 @@
rev_metadata["origin"] = dir_metadata["origin"] = origin_url
snapshot = archive_data.snapshot_get_latest(origin_url)
rev_metadata["visit"] = dir_metadata["visit"] = gen_swhid(
- SNAPSHOT, snapshot["id"]
+ ObjectType.SNAPSHOT, snapshot["id"]
)
- dir_metadata["anchor"] = gen_swhid(RELEASE, release_id)
+ dir_metadata["anchor"] = gen_swhid(ObjectType.RELEASE, release_id)
elif snapshot_id:
directory_url = reverse(
@@ -150,17 +150,17 @@
query_params={"release": release_data["name"],},
)
rev_metadata["visit"] = dir_metadata["visit"] = gen_swhid(
- SNAPSHOT, snapshot_id
+ ObjectType.SNAPSHOT, snapshot_id
)
- dir_metadata["anchor"] = gen_swhid(RELEASE, release_id)
+ dir_metadata["anchor"] = gen_swhid(ObjectType.RELEASE, release_id)
else:
directory_url = reverse("browse-directory", url_args={"sha1_git": rev_dir})
assert_contains(resp, escape(directory_url))
- swh_rev_id = gen_swhid(REVISION, rev["id"], metadata=rev_metadata)
+ swh_rev_id = gen_swhid(ObjectType.REVISION, rev["id"], metadata=rev_metadata)
swh_rev_id_url = reverse("browse-swhid", url_args={"swhid": swh_rev_id})
assert_contains(resp, swh_rev_id_url)
- swh_dir_id = gen_swhid(DIRECTORY, rev_dir, metadata=dir_metadata)
+ swh_dir_id = gen_swhid(ObjectType.DIRECTORY, rev_dir, metadata=dir_metadata)
swh_dir_id_url = reverse("browse-swhid", url_args={"swhid": swh_dir_id})
assert_contains(resp, swh_dir_id_url)
diff --git a/swh/web/tests/browse/views/test_revision.py b/swh/web/tests/browse/views/test_revision.py
--- a/swh/web/tests/browse/views/test_revision.py
+++ b/swh/web/tests/browse/views/test_revision.py
@@ -11,7 +11,7 @@
from django.utils.html import escape
from swh.model.hashutil import hash_to_bytes, hash_to_hex
-from swh.model.identifiers import DIRECTORY, REVISION, SNAPSHOT
+from swh.model.identifiers import ObjectType
from swh.model.model import Revision, RevisionType, TimestampWithTimezone
from swh.web.common.identifiers import gen_swhid
from swh.web.common.utils import format_utc_iso_date, parse_iso8601_date_to_utc, reverse
@@ -259,12 +259,12 @@
assert_contains(resp, "vault-cook-directory")
assert_contains(resp, "vault-cook-revision")
- swh_rev_id = gen_swhid("revision", revision)
+ swh_rev_id = gen_swhid(ObjectType.REVISION, revision)
swh_rev_id_url = reverse("browse-swhid", url_args={"swhid": swh_rev_id})
assert_contains(resp, swh_rev_id)
assert_contains(resp, swh_rev_id_url)
- swh_dir_id = gen_swhid("directory", dir_id)
+ swh_dir_id = gen_swhid(ObjectType.DIRECTORY, dir_id)
swh_dir_id_url = reverse("browse-swhid", url_args={"swhid": swh_dir_id})
assert_contains(resp, swh_dir_id)
assert_contains(resp, swh_dir_id_url)
@@ -272,7 +272,7 @@
if origin_url:
assert_contains(resp, "swh-take-new-snapshot")
- swh_rev_id = gen_swhid(REVISION, revision)
+ swh_rev_id = gen_swhid(ObjectType.REVISION, revision)
swh_rev_id_url = reverse("browse-swhid", url_args={"swhid": swh_rev_id})
if origin_url:
@@ -281,7 +281,7 @@
)
assert_contains(resp, f'href="{browse_origin_url}"')
elif snapshot:
- swh_snp_id = gen_swhid("snapshot", snapshot["id"])
+ swh_snp_id = gen_swhid(ObjectType.SNAPSHOT, snapshot["id"])
swh_snp_id_url = reverse("browse-swhid", url_args={"swhid": swh_snp_id})
assert_contains(resp, f'href="{swh_snp_id_url}"')
@@ -289,16 +289,16 @@
if origin_url:
swhid_context["origin"] = origin_url
if snapshot:
- swhid_context["visit"] = gen_swhid(SNAPSHOT, snapshot["id"])
+ swhid_context["visit"] = gen_swhid(ObjectType.SNAPSHOT, snapshot["id"])
- swh_rev_id = gen_swhid(REVISION, revision, metadata=swhid_context)
+ swh_rev_id = gen_swhid(ObjectType.REVISION, revision, metadata=swhid_context)
swh_rev_id_url = reverse("browse-swhid", url_args={"swhid": swh_rev_id})
assert_contains(resp, swh_rev_id)
assert_contains(resp, swh_rev_id_url)
- swhid_context["anchor"] = gen_swhid(REVISION, revision)
+ swhid_context["anchor"] = gen_swhid(ObjectType.REVISION, revision)
- swh_dir_id = gen_swhid(DIRECTORY, dir_id, metadata=swhid_context)
+ swh_dir_id = gen_swhid(ObjectType.DIRECTORY, dir_id, metadata=swhid_context)
swh_dir_id_url = reverse("browse-swhid", url_args={"swhid": swh_dir_id})
assert_contains(resp, swh_dir_id)
assert_contains(resp, swh_dir_id_url)
diff --git a/swh/web/tests/common/test_archive.py b/swh/web/tests/common/test_archive.py
--- a/swh/web/tests/common/test_archive.py
+++ b/swh/web/tests/common/test_archive.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2020 The Software Heritage developers
+# Copyright (C) 2015-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -14,7 +14,7 @@
from swh.model.from_disk import DentryPerms
from swh.model.hashutil import hash_to_bytes, hash_to_hex
-from swh.model.identifiers import CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT
+from swh.model.identifiers import ObjectType
from swh.model.model import (
Directory,
DirectoryEntry,
@@ -857,19 +857,19 @@
archive_data, content, directory, release, revision, snapshot
):
expected = archive_data.content_find(content)
- assert archive.lookup_object(CONTENT, content["sha1_git"]) == expected
+ assert archive.lookup_object(ObjectType.CONTENT, content["sha1_git"]) == expected
expected = archive_data.directory_get(directory)
- assert archive.lookup_object(DIRECTORY, directory) == expected
+ assert archive.lookup_object(ObjectType.DIRECTORY, directory) == expected
expected = archive_data.release_get(release)
- assert archive.lookup_object(RELEASE, release) == expected
+ assert archive.lookup_object(ObjectType.RELEASE, release) == expected
expected = archive_data.revision_get(revision)
- assert archive.lookup_object(REVISION, revision) == expected
+ assert archive.lookup_object(ObjectType.REVISION, revision) == expected
expected = {**archive_data.snapshot_get(snapshot), "next_branch": None}
- assert archive.lookup_object(SNAPSHOT, snapshot) == expected
+ assert archive.lookup_object(ObjectType.SNAPSHOT, snapshot) == expected
@given(
@@ -887,23 +887,23 @@
unknown_snapshot,
):
with pytest.raises(NotFoundExc) as e:
- archive.lookup_object(CONTENT, unknown_content["sha1_git"])
+ archive.lookup_object(ObjectType.CONTENT, unknown_content["sha1_git"])
assert e.match(r"Content.*not found")
with pytest.raises(NotFoundExc) as e:
- archive.lookup_object(DIRECTORY, unknown_directory)
+ archive.lookup_object(ObjectType.DIRECTORY, unknown_directory)
assert e.match(r"Directory.*not found")
with pytest.raises(NotFoundExc) as e:
- archive.lookup_object(RELEASE, unknown_release)
+ archive.lookup_object(ObjectType.RELEASE, unknown_release)
assert e.match(r"Release.*not found")
with pytest.raises(NotFoundExc) as e:
- archive.lookup_object(REVISION, unknown_revision)
+ archive.lookup_object(ObjectType.REVISION, unknown_revision)
assert e.match(r"Revision.*not found")
with pytest.raises(NotFoundExc) as e:
- archive.lookup_object(SNAPSHOT, unknown_snapshot)
+ archive.lookup_object(ObjectType.SNAPSHOT, unknown_snapshot)
assert e.match(r"Snapshot.*not found")
@@ -911,27 +911,23 @@
def test_lookup_invalid_objects(invalid_sha1):
with pytest.raises(BadInputExc) as e:
- archive.lookup_object("foo", invalid_sha1)
- assert e.match("Invalid swh object type")
-
- with pytest.raises(BadInputExc) as e:
- archive.lookup_object(CONTENT, invalid_sha1)
+ archive.lookup_object(ObjectType.CONTENT, invalid_sha1)
assert e.match("Invalid hash")
with pytest.raises(BadInputExc) as e:
- archive.lookup_object(DIRECTORY, invalid_sha1)
+ archive.lookup_object(ObjectType.DIRECTORY, invalid_sha1)
assert e.match("Invalid checksum")
with pytest.raises(BadInputExc) as e:
- archive.lookup_object(RELEASE, invalid_sha1)
+ archive.lookup_object(ObjectType.RELEASE, invalid_sha1)
assert e.match("Invalid checksum")
with pytest.raises(BadInputExc) as e:
- archive.lookup_object(REVISION, invalid_sha1)
+ archive.lookup_object(ObjectType.REVISION, invalid_sha1)
assert e.match("Invalid checksum")
with pytest.raises(BadInputExc) as e:
- archive.lookup_object(SNAPSHOT, invalid_sha1)
+ archive.lookup_object(ObjectType.SNAPSHOT, invalid_sha1)
assert e.match("Invalid checksum")
@@ -943,11 +939,11 @@
missing_snp = random_sha1()
grouped_swhids = {
- CONTENT: [hash_to_bytes(missing_cnt)],
- DIRECTORY: [hash_to_bytes(missing_dir)],
- REVISION: [hash_to_bytes(missing_rev)],
- RELEASE: [hash_to_bytes(missing_rel)],
- SNAPSHOT: [hash_to_bytes(missing_snp)],
+ ObjectType.CONTENT: [hash_to_bytes(missing_cnt)],
+ ObjectType.DIRECTORY: [hash_to_bytes(missing_dir)],
+ ObjectType.REVISION: [hash_to_bytes(missing_rev)],
+ ObjectType.RELEASE: [hash_to_bytes(missing_rel)],
+ ObjectType.SNAPSHOT: [hash_to_bytes(missing_snp)],
}
actual_result = archive.lookup_missing_hashes(grouped_swhids)
@@ -968,11 +964,11 @@
missing_snp = random_sha1()
grouped_swhids = {
- CONTENT: [hash_to_bytes(content["sha1_git"])],
- DIRECTORY: [hash_to_bytes(directory)],
- REVISION: [hash_to_bytes(missing_rev)],
- RELEASE: [hash_to_bytes(missing_rel)],
- SNAPSHOT: [hash_to_bytes(missing_snp)],
+ ObjectType.CONTENT: [hash_to_bytes(content["sha1_git"])],
+ ObjectType.DIRECTORY: [hash_to_bytes(directory)],
+ ObjectType.REVISION: [hash_to_bytes(missing_rev)],
+ ObjectType.RELEASE: [hash_to_bytes(missing_rel)],
+ ObjectType.SNAPSHOT: [hash_to_bytes(missing_snp)],
}
actual_result = archive.lookup_missing_hashes(grouped_swhids)
@@ -1204,8 +1200,8 @@
branches_count = nb_branches_by_target_type // 2
for target_type in (
- DIRECTORY,
- REVISION,
+ ObjectType.DIRECTORY.name.lower(),
+ ObjectType.REVISION.name.lower(),
):
partial_branches = archive.lookup_snapshot(
hash_to_hex(snapshot.id),
diff --git a/swh/web/tests/common/test_identifiers.py b/swh/web/tests/common/test_identifiers.py
--- a/swh/web/tests/common/test_identifiers.py
+++ b/swh/web/tests/common/test_identifiers.py
@@ -10,14 +10,7 @@
import pytest
from swh.model.hashutil import hash_to_bytes
-from swh.model.identifiers import (
- CONTENT,
- DIRECTORY,
- RELEASE,
- REVISION,
- SNAPSHOT,
- QualifiedSWHID,
-)
+from swh.model.identifiers import ObjectType, QualifiedSWHID
from swh.model.model import Origin
from swh.web.browse.snapshot_context import get_snapshot_context
from swh.web.common.exc import BadInputExc
@@ -26,6 +19,7 @@
get_swhid,
get_swhids_info,
group_swhids,
+ parse_object_type,
resolve_swhid,
)
from swh.web.common.typing import SWHObjectInfo
@@ -46,7 +40,7 @@
@given(content())
def test_gen_swhid(content):
- swh_object_type = CONTENT
+ swh_object_type = ObjectType.CONTENT
sha1_git = content["sha1_git"]
expected_swhid = "swh:1:cnt:" + sha1_git
@@ -64,36 +58,46 @@
)
with pytest.raises(BadInputExc) as e:
- gen_swhid("foo", sha1_git)
+ gen_swhid(swh_object_type, "not a valid id")
assert e.match("Invalid object")
+
+def test_parse_object_type():
+ assert parse_object_type("content") == ObjectType.CONTENT
+ assert parse_object_type("directory") == ObjectType.DIRECTORY
+ assert parse_object_type("revision") == ObjectType.REVISION
+ assert parse_object_type("release") == ObjectType.RELEASE
+ assert parse_object_type("snapshot") == ObjectType.SNAPSHOT
+
with pytest.raises(BadInputExc) as e:
- gen_swhid(swh_object_type, "not a valid id")
- assert e.match("Invalid object")
+ parse_object_type("foo")
+ assert e.match("Invalid swh object type")
@given(content(), directory(), release(), revision(), snapshot())
def test_resolve_swhid_legacy(content, directory, release, revision, snapshot):
for obj_type, obj_id in (
- (CONTENT, content["sha1_git"]),
- (DIRECTORY, directory),
- (RELEASE, release),
- (REVISION, revision),
- (SNAPSHOT, snapshot),
+ (ObjectType.CONTENT, content["sha1_git"]),
+ (ObjectType.DIRECTORY, directory),
+ (ObjectType.RELEASE, release),
+ (ObjectType.REVISION, revision),
+ (ObjectType.SNAPSHOT, snapshot),
):
swhid = gen_swhid(obj_type, obj_id)
url_args = {}
- if obj_type == CONTENT:
+ if obj_type == ObjectType.CONTENT:
url_args["query_string"] = f"sha1_git:{obj_id}"
- elif obj_type == SNAPSHOT:
+ elif obj_type == ObjectType.SNAPSHOT:
url_args["snapshot_id"] = obj_id
else:
url_args["sha1_git"] = obj_id
query_params = {"origin_url": "some-origin"}
browse_url = reverse(
- f"browse-{obj_type}", url_args=url_args, query_params=query_params
+ f"browse-{obj_type.name.lower()}",
+ url_args=url_args,
+ query_params=query_params,
)
for swhid_ in (swhid, swhid.upper()):
@@ -110,11 +114,11 @@
@given(content(), directory(), release(), revision(), snapshot())
def test_get_swhid(content, directory, release, revision, snapshot):
for obj_type, obj_id in (
- (CONTENT, content["sha1_git"]),
- (DIRECTORY, directory),
- (RELEASE, release),
- (REVISION, revision),
- (SNAPSHOT, snapshot),
+ (ObjectType.CONTENT, content["sha1_git"]),
+ (ObjectType.DIRECTORY, directory),
+ (ObjectType.RELEASE, release),
+ (ObjectType.REVISION, revision),
+ (ObjectType.SNAPSHOT, snapshot),
):
swhid = gen_swhid(obj_type, obj_id)
for swhid_ in (swhid, swhid.upper()):
@@ -131,11 +135,11 @@
swhids = []
expected = {}
for obj_type, obj_id in (
- (CONTENT, content["sha1_git"]),
- (DIRECTORY, directory),
- (RELEASE, release),
- (REVISION, revision),
- (SNAPSHOT, snapshot),
+ (ObjectType.CONTENT, content["sha1_git"]),
+ (ObjectType.DIRECTORY, directory),
+ (ObjectType.RELEASE, release),
+ (ObjectType.REVISION, revision),
+ (ObjectType.SNAPSHOT, snapshot),
):
swhid = gen_swhid(obj_type, obj_id)
swhid = get_swhid(swhid)
@@ -150,14 +154,14 @@
@given(directory_with_subdirs())
def test_get_swhids_info_directory_context(archive_data, directory):
swhid = get_swhids_info(
- [SWHObjectInfo(object_type=DIRECTORY, object_id=directory)],
+ [SWHObjectInfo(object_type=ObjectType.DIRECTORY, object_id=directory)],
snapshot_context=None,
)[0]
assert swhid["swhid_with_context"] is None
# path qualifier should be discarded for a root directory
swhid = get_swhids_info(
- [SWHObjectInfo(object_type=DIRECTORY, object_id=directory)],
+ [SWHObjectInfo(object_type=ObjectType.DIRECTORY, object_id=directory)],
snapshot_context=None,
extra_context={"path": "/"},
)[0]
@@ -172,7 +176,7 @@
dir_subdir_files = [e for e in dir_subdir_content if e["type"] == "file"]
swh_objects_info = [
- SWHObjectInfo(object_type=DIRECTORY, object_id=dir_subdir["target"])
+ SWHObjectInfo(object_type=ObjectType.DIRECTORY, object_id=dir_subdir["target"])
]
extra_context = {
@@ -185,7 +189,8 @@
extra_context["filename"] = dir_subdir_file["name"]
swh_objects_info.append(
SWHObjectInfo(
- object_type=CONTENT, object_id=dir_subdir_file["checksums"]["sha1_git"]
+ object_type=ObjectType.CONTENT,
+ object_id=dir_subdir_file["checksums"]["sha1_git"],
)
)
@@ -199,7 +204,7 @@
for swhid in (swhid_lower, swhid_upper):
swhid_dir_parsed = get_swhid(swhid)
- anchor = gen_swhid(DIRECTORY, directory)
+ anchor = gen_swhid(ObjectType.DIRECTORY, directory)
assert swhid_dir_parsed.qualifiers() == {
"anchor": anchor,
@@ -223,15 +228,16 @@
dir_entry = random.choice(dir_content)
swh_objects = [
- SWHObjectInfo(object_type=REVISION, object_id=revision),
- SWHObjectInfo(object_type=DIRECTORY, object_id=directory),
+ SWHObjectInfo(object_type=ObjectType.REVISION, object_id=revision),
+ SWHObjectInfo(object_type=ObjectType.DIRECTORY, object_id=directory),
]
extra_context = {"revision": revision, "path": "/"}
if dir_entry["type"] == "file":
swh_objects.append(
SWHObjectInfo(
- object_type=CONTENT, object_id=dir_entry["checksums"]["sha1_git"]
+ object_type=ObjectType.CONTENT,
+ object_id=dir_entry["checksums"]["sha1_git"],
)
)
extra_context["filename"] = dir_entry["name"]
@@ -248,7 +254,7 @@
for swhid in (swhid_lower, swhid_upper):
swhid_dir_parsed = get_swhid(swhid)
- anchor = gen_swhid(REVISION, revision)
+ anchor = gen_swhid(ObjectType.REVISION, revision)
assert swhid_dir_parsed.qualifiers() == {
"anchor": anchor,
@@ -301,23 +307,26 @@
for snp_ctx_params, anchor_info in (
(
{"snapshot_id": snapshot_id},
- {"anchor_type": REVISION, "anchor_id": head_rev_id},
+ {"anchor_type": ObjectType.REVISION, "anchor_id": head_rev_id},
),
(
{"snapshot_id": snapshot_id, "branch_name": branch_name},
- {"anchor_type": REVISION, "anchor_id": branches[branch_name]},
+ {
+ "anchor_type": ObjectType.REVISION,
+ "anchor_id": branches[branch_name],
+ },
),
(
{"snapshot_id": snapshot_id, "release_name": release_name},
- {"anchor_type": RELEASE, "anchor_id": releases[release]},
+ {"anchor_type": ObjectType.RELEASE, "anchor_id": releases[release]},
),
(
{"snapshot_id": snapshot_id, "revision_id": revision_id},
- {"anchor_type": REVISION, "anchor_id": revision_id},
+ {"anchor_type": ObjectType.REVISION, "anchor_id": revision_id},
),
(
{"origin_url": origin["url"], "snapshot_id": snapshot_id},
- {"anchor_type": REVISION, "anchor_id": head_rev_id},
+ {"anchor_type": ObjectType.REVISION, "anchor_id": head_rev_id},
),
(
{
@@ -325,7 +334,10 @@
"snapshot_id": snapshot_id,
"branch_name": branch_name,
},
- {"anchor_type": REVISION, "anchor_id": branches[branch_name]},
+ {
+ "anchor_type": ObjectType.REVISION,
+ "anchor_id": branches[branch_name],
+ },
),
(
{
@@ -333,7 +345,7 @@
"snapshot_id": snapshot_id,
"release_name": release_name,
},
- {"anchor_type": RELEASE, "anchor_id": releases[release]},
+ {"anchor_type": ObjectType.RELEASE, "anchor_id": releases[release]},
),
(
{
@@ -341,7 +353,7 @@
"snapshot_id": snapshot_id,
"revision_id": revision_id,
},
- {"anchor_type": REVISION, "anchor_id": revision_id},
+ {"anchor_type": ObjectType.REVISION, "anchor_id": revision_id},
),
):
@@ -357,16 +369,19 @@
swh_objects = [
SWHObjectInfo(
- object_type=CONTENT, object_id=dir_file["checksums"]["sha1_git"]
+ object_type=ObjectType.CONTENT,
+ object_id=dir_file["checksums"]["sha1_git"],
),
- SWHObjectInfo(object_type=DIRECTORY, object_id=root_dir),
- SWHObjectInfo(object_type=REVISION, object_id=rev_id),
- SWHObjectInfo(object_type=SNAPSHOT, object_id=snapshot_id),
+ SWHObjectInfo(object_type=ObjectType.DIRECTORY, object_id=root_dir),
+ SWHObjectInfo(object_type=ObjectType.REVISION, object_id=rev_id),
+ SWHObjectInfo(object_type=ObjectType.SNAPSHOT, object_id=snapshot_id),
]
if "release_name" in snp_ctx_params:
swh_objects.append(
- SWHObjectInfo(object_type=RELEASE, object_id=release_data["id"])
+ SWHObjectInfo(
+ object_type=ObjectType.RELEASE, object_id=release_data["id"]
+ )
)
swhids = get_swhids_info(
@@ -392,7 +407,9 @@
object_id=anchor_info["anchor_id"],
)
- snapshot_swhid = gen_swhid(object_type=SNAPSHOT, object_id=snapshot_id)
+ snapshot_swhid = gen_swhid(
+ object_type=ObjectType.SNAPSHOT, object_id=snapshot_id
+ )
expected_cnt_context = {
"visit": snapshot_swhid,
@@ -431,7 +448,7 @@
path = "/foo;/bar%"
swhid_info = get_swhids_info(
- [SWHObjectInfo(object_type=DIRECTORY, object_id=directory)],
+ [SWHObjectInfo(object_type=ObjectType.DIRECTORY, object_id=directory)],
snapshot_context=snapshot_context,
extra_context={"path": path},
)[0]
@@ -496,7 +513,9 @@
snapshot["id"], origin["url"], **snp_ctx_params
)
- _check_resolved_swhid_browse_url(SNAPSHOT, snapshot["id"], snapshot_context)
+ _check_resolved_swhid_browse_url(
+ ObjectType.SNAPSHOT, snapshot["id"], snapshot_context
+ )
rev = head_rev_id
if "branch_name" in snp_ctx_params:
@@ -504,15 +523,15 @@
if "revision_id" in snp_ctx_params:
rev = random_rev_id
- _check_resolved_swhid_browse_url(REVISION, rev, snapshot_context)
+ _check_resolved_swhid_browse_url(ObjectType.REVISION, rev, snapshot_context)
_check_resolved_swhid_browse_url(
- DIRECTORY, directory, snapshot_context, path="/"
+ ObjectType.DIRECTORY, directory, snapshot_context, path="/"
)
if directory_subdir:
_check_resolved_swhid_browse_url(
- DIRECTORY,
+ ObjectType.DIRECTORY,
directory_subdir["target"],
snapshot_context,
path=f"/{directory_subdir['name']}/",
@@ -520,14 +539,14 @@
if directory_file:
_check_resolved_swhid_browse_url(
- CONTENT,
+ ObjectType.CONTENT,
directory_file["target"],
snapshot_context,
path=f"/{directory_file['name']}",
)
_check_resolved_swhid_browse_url(
- CONTENT,
+ ObjectType.CONTENT,
directory_file["target"],
snapshot_context,
path=f"/{directory_file['name']}",
@@ -535,7 +554,7 @@
)
_check_resolved_swhid_browse_url(
- CONTENT,
+ ObjectType.CONTENT,
directory_file["target"],
snapshot_context,
path=f"/{directory_file['name']}",
@@ -558,27 +577,31 @@
obj_context["origin"] = origin_url
query_params["origin_url"] = origin_url
- obj_context["visit"] = gen_swhid(SNAPSHOT, snapshot_id)
+ obj_context["visit"] = gen_swhid(ObjectType.SNAPSHOT, snapshot_id)
query_params["snapshot"] = snapshot_id
- if object_type in (CONTENT, DIRECTORY, REVISION):
+ if object_type in (ObjectType.CONTENT, ObjectType.DIRECTORY, ObjectType.REVISION):
if snapshot_context["release"]:
- obj_context["anchor"] = gen_swhid(RELEASE, snapshot_context["release_id"])
+ obj_context["anchor"] = gen_swhid(
+ ObjectType.RELEASE, snapshot_context["release_id"]
+ )
query_params["release"] = snapshot_context["release"]
else:
- obj_context["anchor"] = gen_swhid(REVISION, snapshot_context["revision_id"])
- if object_type != REVISION:
+ obj_context["anchor"] = gen_swhid(
+ ObjectType.REVISION, snapshot_context["revision_id"]
+ )
+ if object_type != ObjectType.REVISION:
query_params["revision"] = snapshot_context["revision_id"]
if path:
obj_context["path"] = path
if path != "/":
- if object_type == CONTENT:
+ if object_type == ObjectType.CONTENT:
query_params["path"] = path[1:]
else:
query_params["path"] = path[1:-1]
- if object_type == DIRECTORY:
+ if object_type == ObjectType.DIRECTORY:
object_id = snapshot_context["root_directory"]
if lines:
@@ -592,13 +615,15 @@
obj_swhid_resolved = resolve_swhid(obj_swhid)
url_args = {"sha1_git": object_id}
- if object_type == CONTENT:
+ if object_type == ObjectType.CONTENT:
url_args = {"query_string": f"sha1_git:{object_id}"}
- elif object_type == SNAPSHOT:
+ elif object_type == ObjectType.SNAPSHOT:
url_args = {"snapshot_id": object_id}
expected_url = reverse(
- f"browse-{object_type}", url_args=url_args, query_params=query_params,
+ f"browse-{object_type.name.lower()}",
+ url_args=url_args,
+ query_params=query_params,
)
if lines:
lines_number = lines.split("-")
@@ -615,7 +640,9 @@
archive_data.origin_add([Origin(url=origin_url)])
origin_swhid_escaped = quote(origin_url, safe="/?:@&")
origin_swhid_url_escaped = quote(origin_url, safe="/:@;")
- swhid = gen_swhid(DIRECTORY, directory, metadata={"origin": origin_swhid_escaped})
+ swhid = gen_swhid(
+ ObjectType.DIRECTORY, directory, metadata={"origin": origin_swhid_escaped}
+ )
resolved_swhid = resolve_swhid(swhid)
assert resolved_swhid["swhid_parsed"].origin == origin_swhid_escaped
assert origin_swhid_url_escaped in resolved_swhid["browse_url"]
@@ -627,9 +654,9 @@
dir_subdirs = [e for e in dir_content if e["type"] == "dir"]
dir_subdir = random.choice(dir_subdirs)
dir_subdir_path = dir_subdir["name"]
- anchor = gen_swhid(DIRECTORY, directory)
+ anchor = gen_swhid(ObjectType.DIRECTORY, directory)
swhid = gen_swhid(
- DIRECTORY,
+ ObjectType.DIRECTORY,
dir_subdir["target"],
metadata={"anchor": anchor, "path": "/" + dir_subdir_path},
)
@@ -647,7 +674,9 @@
origin_url = "http://example.org/project/abc"
malformed_origin_url = "http:/example.org/project/abc"
archive_data.origin_add([Origin(url=origin_url)])
- swhid = gen_swhid(DIRECTORY, directory, metadata={"origin": malformed_origin_url})
+ swhid = gen_swhid(
+ ObjectType.DIRECTORY, directory, metadata={"origin": malformed_origin_url}
+ )
resolved_swhid = resolve_swhid(swhid)
assert origin_url in resolved_swhid["browse_url"]
@@ -659,21 +688,21 @@
dir_content = archive_data.directory_ls(directory)
dir_entry = random.choice(dir_content)
- rev_swhid = gen_swhid(REVISION, revision)
+ rev_swhid = gen_swhid(ObjectType.REVISION, revision)
if dir_entry["type"] == "rev":
return
if dir_entry["type"] == "file":
swhid = gen_swhid(
- CONTENT,
+ ObjectType.CONTENT,
dir_entry["checksums"]["sha1_git"],
metadata={"anchor": rev_swhid, "path": f"/{dir_entry['name']}"},
)
else:
swhid = gen_swhid(
- DIRECTORY,
+ ObjectType.DIRECTORY,
dir_entry["target"],
metadata={"anchor": rev_swhid, "path": f"/{dir_entry['name']}/"},
)
@@ -696,10 +725,10 @@
[entry for entry in dir_content if entry["type"] == "dir"]
)
- dir_swhid = gen_swhid(DIRECTORY, directory)
+ dir_swhid = gen_swhid(ObjectType.DIRECTORY, directory)
swhid = gen_swhid(
- DIRECTORY,
+ ObjectType.DIRECTORY,
dir_entry["target"],
metadata={"anchor": dir_swhid, "path": f"/{dir_entry['name']}/"},
)
@@ -721,11 +750,11 @@
[entry for entry in dir_content if entry["type"] == "file"]
)
- dir_swhid = gen_swhid(DIRECTORY, directory)
+ dir_swhid = gen_swhid(ObjectType.DIRECTORY, directory)
sha1_git = file_entry["checksums"]["sha1_git"]
swhid = gen_swhid(
- CONTENT,
+ ObjectType.CONTENT,
sha1_git,
metadata={"anchor": dir_swhid, "path": f"/{file_entry['name']}"},
)

File Metadata

Mime Type
text/plain
Expires
Wed, Jul 2, 10:28 AM (2 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3216267

Event Timeline