query: Move 'dir' command to a function

This commit is contained in:
Franciszek Stachura 2025-02-25 23:36:03 +01:00 committed by Théo Lebrun
parent 5f9c6236a6
commit 2a93ee95fb
2 changed files with 8 additions and 7 deletions

View file

@ -110,14 +110,9 @@ class Query:
return path.strip('/') in self.file_cache[version] return path.strip('/') in self.file_cache[version]
elif cmd == 'dir': elif cmd == 'dir':
# Returns the contents (trees or blobs) of the specified directory
# Example: ./query.py dir v3.1-rc10 /arch
version = args[0] version = args[0]
path = args[1] path = args[1]
entries_str = decode(self.script('get-dir', version, path)) return self.get_dir_contents(version, path)
return entries_str.split("\n")[:-1]
elif cmd == 'file': elif cmd == 'file':
version = args[0] version = args[0]
@ -214,6 +209,12 @@ class Query:
else: else:
return decode(self.script('get-file', version, path)) 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: # Returns the list of indexed versions in the following format:
# topmenu submenu tag # topmenu submenu tag
# Example: v3 v3.1 v3.1-rc10 # Example: v3 v3.1 v3.1-rc10

View file

@ -569,7 +569,7 @@ DirectoryEntry = namedtuple('DirectoryEntry', 'type, name, path, url, size')
# path: path to the directory in the repository # path: path to the directory in the repository
def get_directory_entries(q: Query, base_url, tag: str, path: str) -> list[DirectoryEntry]: def get_directory_entries(q: Query, base_url, tag: str, path: str) -> list[DirectoryEntry]:
dir_entries = [] dir_entries = []
lines = q.query('dir', tag, path) lines = q.get_dir_contents(tag, path)
for l in lines: for l in lines:
type, name, size, perm = l.split(' ') type, name, size, perm = l.split(' ')