Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/views/content.py
Show First 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | def content_display(request, query_string): | ||||
The url that points to it is | The url that points to it is | ||||
:http:get:`/browse/content/[(algo_hash):](hash)/` | :http:get:`/browse/content/[(algo_hash):](hash)/` | ||||
""" | """ | ||||
try: | try: | ||||
algo, checksum = query.parse_hash(query_string) | algo, checksum = query.parse_hash(query_string) | ||||
checksum = hash_to_hex(checksum) | checksum = hash_to_hex(checksum) | ||||
content_data = request_content(query_string, raise_if_unavailable=False) | content_data = request_content(query_string, raise_if_unavailable=False) | ||||
origin_url = request.GET.get("origin_url", None) | origin_url = request.GET.get("origin_url") | ||||
selected_language = request.GET.get("language", None) | selected_language = request.GET.get("language") | ||||
if not origin_url: | if not origin_url: | ||||
origin_url = request.GET.get("origin", None) | origin_url = request.GET.get("origin") | ||||
snapshot_id = request.GET.get("snapshot") | |||||
snapshot_context = None | snapshot_context = None | ||||
if origin_url: | if origin_url is not None or snapshot_id is not None: | ||||
try: | try: | ||||
snapshot_context = get_snapshot_context(origin_url=origin_url) | snapshot_context = get_snapshot_context( | ||||
except NotFoundExc: | origin_url=origin_url, | ||||
snapshot_id=snapshot_id, | |||||
branch_name=request.GET.get("branch"), | |||||
release_name=request.GET.get("release"), | |||||
revision_id=request.GET.get("revision"), | |||||
) | |||||
except NotFoundExc as e: | |||||
raw_cnt_url = reverse( | raw_cnt_url = reverse( | ||||
"browse-content", url_args={"query_string": query_string} | "browse-content", url_args={"query_string": query_string} | ||||
) | ) | ||||
error_message = ( | error_message = ( | ||||
"The Software Heritage archive has a content " | "The Software Heritage archive has a content " | ||||
"with the hash you provided but the origin " | "with the hash you provided but the origin " | ||||
"mentioned in your request appears broken: %s. " | "mentioned in your request appears broken: %s. " | ||||
"Please check the URL and try again.\n\n" | "Please check the URL and try again.\n\n" | ||||
"Nevertheless, you can still browse the content " | "Nevertheless, you can still browse the content " | ||||
"without origin information: %s" | "without origin information: %s" | ||||
% (gen_link(origin_url), gen_link(raw_cnt_url)) | % (gen_link(origin_url), gen_link(raw_cnt_url)) | ||||
) | ) | ||||
if str(e).startswith("Origin"): | |||||
raise NotFoundExc(error_message) | raise NotFoundExc(error_message) | ||||
if snapshot_context: | else: | ||||
snapshot_context["visit_info"] = None | raise e | ||||
except Exception as exc: | except Exception as exc: | ||||
vlorentz: none of this is covered | |||||
return handle_view_exception(request, exc) | return handle_view_exception(request, exc) | ||||
path = request.GET.get("path", None) | path = request.GET.get("path", None) | ||||
content = None | content = None | ||||
language = None | language = None | ||||
mimetype = None | mimetype = None | ||||
if content_data["raw_data"] is not None: | if content_data["raw_data"] is not None: | ||||
Show All 14 Lines | if mimetype and "text/" in mimetype: | ||||
available_languages = highlightjs.get_supported_languages() | available_languages = highlightjs.get_supported_languages() | ||||
root_dir = None | root_dir = None | ||||
filename = None | filename = None | ||||
path_info = None | path_info = None | ||||
directory_id = None | directory_id = None | ||||
directory_url = None | directory_url = None | ||||
query_params = {"origin_url": origin_url} | query_params = snapshot_context["query_params"] if snapshot_context else {} | ||||
breadcrumbs = [] | breadcrumbs = [] | ||||
if path: | if path: | ||||
split_path = path.split("/") | split_path = path.split("/") | ||||
root_dir = split_path[0] | root_dir = split_path[0] | ||||
filename = split_path[-1] | filename = split_path[-1] | ||||
if root_dir != path: | if root_dir != path: | ||||
▲ Show 20 Lines • Show All 114 Lines • Show Last 20 Lines |
none of this is covered