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 | ||||
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 django.template.defaultfilters import filesizeformat | |||||
from swh.model.identifiers import DIRECTORY, RELEASE, REVISION, SNAPSHOT | from swh.model.identifiers import DIRECTORY, RELEASE, REVISION, SNAPSHOT | ||||
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 | ||||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | for f in files: | ||||
url_args={"query_string": query_string}, | url_args={"query_string": query_string}, | ||||
query_params={ | query_params={ | ||||
**query_params, | **query_params, | ||||
"path": root_sha1_git + "/" + path + f["name"], | "path": root_sha1_git + "/" + path + f["name"], | ||||
}, | }, | ||||
) | ) | ||||
if f["length"] is not None: | if f["length"] is not None: | ||||
sum_file_sizes += f["length"] | sum_file_sizes += 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) | |||||
dir_metadata = DirectoryMetadata( | dir_metadata = DirectoryMetadata( | ||||
object_type=DIRECTORY, | object_type=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, | ||||
▲ Show 20 Lines • Show All 134 Lines • Show Last 20 Lines |