Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/views/directory.py
Show All 15 Lines | |||||
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, | ||||
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.identifiers import get_swh_persistent_ids | from swh.web.common.identifiers import get_swhids_info | ||||
from swh.web.common.typing import DirectoryMetadata | from swh.web.common.typing import DirectoryMetadata, SWHObjectInfo | ||||
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 91 Lines • ▼ Show 20 Lines | for f in files: | ||||
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 = DirectoryMetadata( | dir_metadata = DirectoryMetadata( | ||||
object_type=DIRECTORY, | object_type=DIRECTORY, | ||||
object_id=sha1_git, | |||||
directory=sha1_git, | directory=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, | ||||
path=path or None, | root_directory=root_sha1_git, | ||||
path=f"/{path}" if path else "", | |||||
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_id": sha1_git, | "directory_id": sha1_git, | ||||
"revision_context": False, | "revision_context": False, | ||||
"revision_id": None, | "revision_id": None, | ||||
} | } | ||||
swh_objects = [{"type": "directory", "id": sha1_git}] | swh_objects = [SWHObjectInfo(object_type=DIRECTORY, object_id=sha1_git)] | ||||
swh_ids = get_swh_persistent_ids( | swhids_info = get_swhids_info(swh_objects, snapshot_context, dir_metadata) | ||||
swh_objects=swh_objects, snapshot_context=snapshot_context | |||||
) | |||||
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]) + "/" | ||||
heading += " - %s" % dir_path | heading += " - %s" % dir_path | ||||
return render( | return render( | ||||
request, | request, | ||||
"browse/directory.html", | "browse/directory.html", | ||||
{ | { | ||||
"heading": heading, | "heading": heading, | ||||
"swh_object_id": swh_ids[0]["swh_id"], | "swh_object_id": swhids_info[0]["swhid"], | ||||
"swh_object_name": "Directory", | "swh_object_name": "Directory", | ||||
"swh_object_metadata": dir_metadata, | "swh_object_metadata": dir_metadata, | ||||
"dirs": dirs, | "dirs": dirs, | ||||
"files": files, | "files": files, | ||||
"breadcrumbs": breadcrumbs, | "breadcrumbs": breadcrumbs, | ||||
"top_right_link": None, | "top_right_link": None, | ||||
"readme_name": readme_name, | "readme_name": readme_name, | ||||
"readme_url": readme_url, | "readme_url": readme_url, | ||||
"readme_html": readme_html, | "readme_html": readme_html, | ||||
"snapshot_context": snapshot_context, | "snapshot_context": snapshot_context, | ||||
"vault_cooking": vault_cooking, | "vault_cooking": vault_cooking, | ||||
"show_actions_menu": True, | "show_actions_menu": True, | ||||
"swh_ids": swh_ids, | "swhids_info": swhids_info, | ||||
}, | }, | ||||
) | ) | ||||
@browse_route( | @browse_route( | ||||
r"directory/(?P<sha1_git>[0-9a-f]+)/", | r"directory/(?P<sha1_git>[0-9a-f]+)/", | ||||
view_name="browse-directory", | view_name="browse-directory", | ||||
checksum_args=["sha1_git"], | checksum_args=["sha1_git"], | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |