From 9bc76f0d8d2832f2b6a13248b25b669f8d0fc1f6 Mon Sep 17 00:00:00 2001 From: Franciszek Stachura Date: Tue, 25 Feb 2025 23:25:17 +0100 Subject: [PATCH] query: Move 'type' command to a function --- elixir/query.py | 19 ++++++++++--------- elixir/web.py | 4 ++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/elixir/query.py b/elixir/query.py index 50ab1aa..b82a487 100755 --- a/elixir/query.py +++ b/elixir/query.py @@ -87,17 +87,9 @@ class Query: return self.get_latest_tag() elif cmd == 'type': - - # Returns the type (blob or tree) associated to - # the given path. Example: - # > ./query.py type v3.1-rc10 /Makefile - # blob - # > ./query.py type v3.1-rc10 /arch - # tree - version = args[0] path = args[1] - return decode(self.script('get-type', version, path)).strip() + return self.get_file_type(version, path) elif cmd == 'exist': version = args[0] @@ -251,6 +243,15 @@ class Query: return versions + # Returns the type (blob or tree) associated to + # the given path. Example: + # > ./query.py type v3.1-rc10 /Makefile + # blob + # > ./query.py type v3.1-rc10 /arch + # tree + def get_file_type(self, version, path): + return decode(self.script('get-type', version, path)).strip() + # Returns identifier search results def search_ident(self, version, ident, family): # DT bindings compatible strings are handled differently diff --git a/elixir/web.py b/elixir/web.py index 3080c64..fe2a270 100755 --- a/elixir/web.py +++ b/elixir/web.py @@ -469,7 +469,7 @@ def get_layout_template_context(q: Query, ctx: RequestContext, get_url_with_new_ # Generate raw source response def generate_raw_source(resp, query, project, version, path): - type = query.query('type', version, path) + type = query.get_file_type(version, path) if type != 'blob': raise ElixirProjectError('File not found', 'This file does not exist.', query=query, project=project, version=version) @@ -597,7 +597,7 @@ def generate_source_page(ctx: RequestContext, q: Query, status = falcon.HTTP_OK source_base_url = get_source_base_url(project, version) - type = q.query('type', version, path) + type = q.get_file_type(version, path) # Generate breadcrumbs path_split = path.split('/')[1:]