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-2020 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 | ||||
from django.http import HttpResponse | from django.http import HttpResponse | ||||
from django.shortcuts import render, redirect | from django.shortcuts import render, redirect | ||||
from django.template.defaultfilters import filesizeformat | from django.template.defaultfilters import filesizeformat | ||||
import sentry_sdk | import sentry_sdk | ||||
from swh.model.identifiers import DIRECTORY | |||||
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 ( | from swh.web.browse.utils import ( | ||||
get_directory_entries, | get_directory_entries, | ||||
get_readme_to_display, | get_readme_to_display, | ||||
get_swh_persistent_ids, | get_swh_persistent_ids, | ||||
gen_link, | gen_link, | ||||
) | ) | ||||
from swh.web.common import service | from swh.web.common import service | ||||
from swh.web.common.exc import handle_view_exception, NotFoundExc | from swh.web.common.exc import handle_view_exception, NotFoundExc | ||||
from swh.web.common.typing import DirectoryMetadata | |||||
from swh.web.common.utils import reverse, gen_path_info | from swh.web.common.utils import reverse, gen_path_info | ||||
def _directory_browse(request, sha1_git, path=None): | def _directory_browse(request, sha1_git, path=None): | ||||
root_sha1_git = sha1_git | root_sha1_git = sha1_git | ||||
try: | try: | ||||
if path: | if path: | ||||
dir_info = service.lookup_directory_with_path(sha1_git, path) | dir_info = service.lookup_directory_with_path(sha1_git, path) | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | for f in files: | ||||
f["length"] = filesizeformat(f["length"]) | f["length"] = filesizeformat(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) | ||||
sum_file_sizes = filesizeformat(sum_file_sizes) | sum_file_sizes = filesizeformat(sum_file_sizes) | ||||
dir_metadata = { | dir_metadata = DirectoryMetadata( | ||||
"directory": sha1_git, | object_type=DIRECTORY, | ||||
"number of regular files": len(files), | directory=sha1_git, | ||||
"number of subdirectories": len(dirs), | nb_files=len(files), | ||||
"sum of regular file sizes": sum_file_sizes, | nb_dirs=len(dirs), | ||||
} | sum_file_sizes=sum_file_sizes, | ||||
vlorentz: `path=path or None` | |||||
path=path or None, | |||||
revision=None, | |||||
revision_found=None, | |||||
release=None, | |||||
snapshot=None, | |||||
) | |||||
vault_cooking = { | vault_cooking = { | ||||
"directory_context": True, | "directory_context": True, | ||||
"directory_id": sha1_git, | "directory_id": sha1_git, | ||||
"revision_context": False, | "revision_context": False, | ||||
"revision_id": None, | "revision_id": None, | ||||
} | } | ||||
▲ Show 20 Lines • Show All 87 Lines • Show Last 20 Lines |
path=path or None