query: Move 'dir' command to a function
This commit is contained in:
parent
5f9c6236a6
commit
2a93ee95fb
2 changed files with 8 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(' ')
|
||||
|
|
|
|||
Loading…
Reference in a new issue