Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/snapshot_context.py
Show All 14 Lines | |||||
from django.template.defaultfilters import filesizeformat | from django.template.defaultfilters import filesizeformat | ||||
from django.utils.html import escape | from django.utils.html import escape | ||||
import sentry_sdk | import sentry_sdk | ||||
from swh.model.identifiers import ( | from swh.model.identifiers import ( | ||||
persistent_identifier, | persistent_identifier, | ||||
snapshot_identifier, | snapshot_identifier, | ||||
CONTENT, | CONTENT, | ||||
DIRECTORY, | |||||
) | ) | ||||
from swh.web.browse.utils import ( | from swh.web.browse.utils import ( | ||||
get_directory_entries, | get_directory_entries, | ||||
gen_directory_link, | gen_directory_link, | ||||
gen_revision_link, | gen_revision_link, | ||||
request_content, | request_content, | ||||
gen_content_link, | gen_content_link, | ||||
Show All 11 Lines | |||||
from swh.web.common.exc import handle_view_exception, NotFoundExc, BadInputExc | from swh.web.common.exc import handle_view_exception, NotFoundExc, BadInputExc | ||||
from swh.web.common.origin_visits import get_origin_visit | from swh.web.common.origin_visits import get_origin_visit | ||||
from swh.web.common.typing import ( | from swh.web.common.typing import ( | ||||
OriginInfo, | OriginInfo, | ||||
SnapshotBranchInfo, | SnapshotBranchInfo, | ||||
SnapshotReleaseInfo, | SnapshotReleaseInfo, | ||||
SnapshotContext, | SnapshotContext, | ||||
ContentMetadata, | ContentMetadata, | ||||
DirectoryMetadata, | |||||
) | ) | ||||
from swh.web.common.utils import ( | from swh.web.common.utils import ( | ||||
reverse, | reverse, | ||||
gen_path_info, | gen_path_info, | ||||
format_utc_iso_date, | format_utc_iso_date, | ||||
swh_object_icons, | swh_object_icons, | ||||
) | ) | ||||
from swh.web.config import get_config | from swh.web.config import get_config | ||||
▲ Show 20 Lines • Show All 685 Lines • ▼ Show 20 Lines | ): | ||||
revision_found = True | revision_found = True | ||||
if sha1_git is None and revision_id is not None: | if sha1_git is None and revision_id is not None: | ||||
try: | try: | ||||
service.lookup_revision(revision_id) | service.lookup_revision(revision_id) | ||||
except NotFoundExc: | except NotFoundExc: | ||||
revision_found = False | revision_found = False | ||||
dir_metadata = { | |||||
"directory": sha1_git, | |||||
"context-independent directory": browse_dir_link, | |||||
"number of regular files": nb_files, | |||||
"number of subdirectories": nb_dirs, | |||||
"sum of regular file sizes": sum_file_sizes, | |||||
"path": dir_path, | |||||
"revision": revision_id, | |||||
"revision_found": revision_found, | |||||
"context-independent revision": browse_rev_link, | |||||
"snapshot": snapshot_id, | |||||
"context-independent snapshot": browse_snp_link, | |||||
} | |||||
if origin_info: | |||||
dir_metadata["origin url"] = origin_info["url"] | |||||
dir_metadata["origin visit date"] = format_utc_iso_date(visit_info["date"]) | |||||
dir_metadata["origin visit type"] = visit_info["type"] | |||||
vault_cooking = { | |||||
"directory_context": True, | |||||
"directory_id": sha1_git, | |||||
"revision_context": True, | |||||
"revision_id": revision_id, | |||||
} | |||||
swh_objects = [ | swh_objects = [ | ||||
{"type": "directory", "id": sha1_git}, | {"type": "directory", "id": sha1_git}, | ||||
{"type": "revision", "id": revision_id}, | {"type": "revision", "id": revision_id}, | ||||
{"type": "snapshot", "id": snapshot_id}, | {"type": "snapshot", "id": snapshot_id}, | ||||
] | ] | ||||
visit_date = None | |||||
visit_type = None | |||||
if visit_info: | |||||
visit_date = format_utc_iso_date(visit_info["date"]) | |||||
visit_type = visit_info["type"] | |||||
release_id = snapshot_context["release_id"] | release_id = snapshot_context["release_id"] | ||||
browse_rel_link = None | |||||
if release_id: | if release_id: | ||||
swh_objects.append({"type": "release", "id": release_id}) | swh_objects.append({"type": "release", "id": release_id}) | ||||
browse_rel_link = gen_release_link(release_id) | browse_rel_link = gen_release_link(release_id) | ||||
dir_metadata["release"] = release_id | |||||
dir_metadata["context-independent release"] = browse_rel_link | dir_metadata = DirectoryMetadata( | ||||
object_type=DIRECTORY, | |||||
directory=sha1_git, | |||||
directory_url=browse_dir_link, | |||||
nb_files=nb_files, | |||||
nb_dirs=nb_dirs, | |||||
sum_file_sizes=sum_file_sizes, | |||||
path=dir_path, | |||||
revision=revision_id, | |||||
revision_found=revision_found, | |||||
revision_url=browse_rev_link, | |||||
release=release_id, | |||||
release_url=browse_rel_link, | |||||
snapshot=snapshot_id, | |||||
snapshot_url=browse_snp_link, | |||||
origin_url=origin_url, | |||||
visit_date=visit_date, | |||||
visit_type=visit_type, | |||||
) | |||||
vault_cooking = { | |||||
"directory_context": True, | |||||
"directory_id": sha1_git, | |||||
"revision_context": True, | |||||
"revision_id": revision_id, | |||||
} | |||||
swh_ids = get_swh_persistent_ids(swh_objects, snapshot_context) | swh_ids = get_swh_persistent_ids(swh_objects, snapshot_context) | ||||
dir_path = "/".join([bc["name"] for bc in breadcrumbs]) + "/" | dir_path = "/".join([bc["name"] for bc in breadcrumbs]) + "/" | ||||
context_found = "snapshot: %s" % snapshot_context["snapshot_id"] | context_found = "snapshot: %s" % snapshot_context["snapshot_id"] | ||||
if origin_info: | if origin_info: | ||||
context_found = "origin: %s" % origin_info["url"] | context_found = "origin: %s" % origin_info["url"] | ||||
heading = "Directory - %s - %s - %s" % ( | heading = "Directory - %s - %s - %s" % ( | ||||
▲ Show 20 Lines • Show All 615 Lines • Show Last 20 Lines |