Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/views/directory.py
# 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 | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import os | import os | ||||
import sentry_sdk | import sentry_sdk | ||||
from django.http import HttpResponse | from django.http import HttpResponse | ||||
from django.shortcuts import redirect, render | 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.browseurls import browse_route | ||||
from swh.web.browse.snapshot_context import get_snapshot_context | 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 | from swh.web.browse.utils import gen_link, get_directory_entries, get_readme_to_display | ||||
from swh.web.common import archive | from swh.web.common import archive | ||||
from swh.web.common.exc import NotFoundExc, http_status_code_message | from swh.web.common.exc import NotFoundExc, http_status_code_message | ||||
from swh.web.common.identifiers import get_swhids_info | from swh.web.common.identifiers import get_swhids_info | ||||
from swh.web.common.typing import DirectoryMetadata, SWHObjectInfo | from swh.web.common.typing import DirectoryMetadata, SWHObjectInfo | ||||
from swh.web.common.utils import gen_path_info, reverse, swh_object_icons | from swh.web.common.utils import gen_path_info, reverse, swh_object_icons | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | for f in files: | ||||
if f["length"] is not None: | if f["length"] is not None: | ||||
sum_file_sizes += f["length"] | sum_file_sizes += f["length"] | ||||
if f["name"].lower().startswith("readme"): | if f["name"].lower().startswith("readme"): | ||||
readmes[f["name"]] = f["checksums"]["sha1"] | readmes[f["name"]] = f["checksums"]["sha1"] | ||||
readme_name, readme_url, readme_html = get_readme_to_display(readmes) | readme_name, readme_url, readme_html = get_readme_to_display(readmes) | ||||
dir_metadata = DirectoryMetadata( | dir_metadata = DirectoryMetadata( | ||||
object_type=DIRECTORY, | object_type=ObjectType.DIRECTORY, | ||||
object_id=sha1_git, | object_id=sha1_git, | ||||
directory=root_sha1_git, | directory=root_sha1_git, | ||||
nb_files=len(files), | nb_files=len(files), | ||||
nb_dirs=len(dirs), | nb_dirs=len(dirs), | ||||
sum_file_sizes=sum_file_sizes, | sum_file_sizes=sum_file_sizes, | ||||
root_directory=root_sha1_git, | root_directory=root_sha1_git, | ||||
path=f"/{path}" if path else None, | path=f"/{path}" if path else None, | ||||
revision=None, | revision=None, | ||||
revision_found=None, | revision_found=None, | ||||
release=None, | release=None, | ||||
snapshot=None, | snapshot=None, | ||||
) | ) | ||||
vault_cooking = { | vault_cooking = { | ||||
"directory_context": True, | "directory_context": True, | ||||
"directory_swhid": f"swh:1:dir:{sha1_git}", | "directory_swhid": f"swh:1:dir:{sha1_git}", | ||||
"revision_context": False, | "revision_context": False, | ||||
"revision_swhid": None, | "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: | if snapshot_context: | ||||
swh_objects.append( | swh_objects.append( | ||||
SWHObjectInfo( | SWHObjectInfo( | ||||
object_type=REVISION, object_id=snapshot_context["revision_id"] | object_type=ObjectType.REVISION, | ||||
object_id=snapshot_context["revision_id"], | |||||
) | ) | ||||
) | ) | ||||
swh_objects.append( | swh_objects.append( | ||||
SWHObjectInfo( | 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"]: | if snapshot_context["release_id"]: | ||||
swh_objects.append( | swh_objects.append( | ||||
SWHObjectInfo( | SWHObjectInfo( | ||||
object_type=RELEASE, object_id=snapshot_context["release_id"] | object_type=ObjectType.RELEASE, | ||||
object_id=snapshot_context["release_id"], | |||||
) | ) | ||||
) | ) | ||||
swhids_info = get_swhids_info(swh_objects, snapshot_context, dir_metadata) | swhids_info = get_swhids_info(swh_objects, snapshot_context, dir_metadata) | ||||
heading = "Directory - %s" % sha1_git | heading = "Directory - %s" % sha1_git | ||||
if breadcrumbs: | if breadcrumbs: | ||||
dir_path = "/".join([bc["name"] for bc in breadcrumbs]) + "/" | dir_path = "/".join([bc["name"] for bc in breadcrumbs]) + "/" | ||||
▲ Show 20 Lines • Show All 95 Lines • Show Last 20 Lines |