From 2a93ee95fbbfce5bf3a007619b38d8fcd288822f Mon Sep 17 00:00:00 2001 From: Franciszek Stachura Date: Tue, 25 Feb 2025 23:36:03 +0100 Subject: [PATCH] query: Move 'dir' command to a function --- elixir/query.py | 13 +++++++------ elixir/web.py | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/elixir/query.py b/elixir/query.py index c71347d..ec44e75 100755 --- a/elixir/query.py +++ b/elixir/query.py @@ -110,14 +110,9 @@ class Query: return path.strip('/') in self.file_cache[version] elif cmd == 'dir': - - # Returns the contents (trees or blobs) of the specified directory - # Example: ./query.py dir v3.1-rc10 /arch - version = args[0] path = args[1] - entries_str = decode(self.script('get-dir', version, path)) - return entries_str.split("\n")[:-1] + return self.get_dir_contents(version, path) elif cmd == 'file': version = args[0] @@ -214,6 +209,12 @@ class Query: else: return decode(self.script('get-file', version, path)) + # Returns the contents (trees or blobs) of the specified directory + # Example: v3.1-rc10 /arch + def get_dir_contents(self, version, path): + entries_str = decode(self.script('get-dir', version, path)) + return entries_str.split("\n")[:-1] + # Returns the list of indexed versions in the following format: # topmenu submenu tag # Example: v3 v3.1 v3.1-rc10 diff --git a/elixir/web.py b/elixir/web.py index ad3211f..23b1265 100755 --- a/elixir/web.py +++ b/elixir/web.py @@ -569,7 +569,7 @@ DirectoryEntry = namedtuple('DirectoryEntry', 'type, name, path, url, size') # path: path to the directory in the repository def get_directory_entries(q: Query, base_url, tag: str, path: str) -> list[DirectoryEntry]: dir_entries = [] - lines = q.query('dir', tag, path) + lines = q.get_dir_contents(tag, path) for l in lines: type, name, size, perm = l.split(' ')