mirror of
https://github.com/release-engineering/repo-autoindex.git
synced 2025-02-23 13:42:52 +00:00
Merge pull request #77 from rohanpm/sort-listings
Ensure directories appear first in listings [RHELDST-21890]
This commit is contained in:
commit
5dacb650ae
5 changed files with 439 additions and 376 deletions
769
poetry.lock
generated
769
poetry.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -56,6 +56,23 @@ class IndexEntry:
|
||||||
padding: str = ""
|
padding: str = ""
|
||||||
icon: str = ICON_OTHER
|
icon: str = ICON_OTHER
|
||||||
|
|
||||||
|
@property
|
||||||
|
def sort_key(self):
|
||||||
|
# Returns a suggested sort key for displaying entries in
|
||||||
|
# a UI.
|
||||||
|
|
||||||
|
priority = 0
|
||||||
|
|
||||||
|
# Folders should come first
|
||||||
|
if self.href.endswith("/"):
|
||||||
|
priority -= 1
|
||||||
|
# And special folders like ".." even earlier
|
||||||
|
if self.href.startswith("."):
|
||||||
|
priority -= 1
|
||||||
|
|
||||||
|
# Entries sort by the priority we calculated, and then by name
|
||||||
|
return (priority, self.href)
|
||||||
|
|
||||||
|
|
||||||
class Repo(ABC):
|
class Repo(ABC):
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
|
@ -70,4 +70,6 @@ def treeify(
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
out.entries.sort(key=lambda entry: entry.sort_key)
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
|
@ -101,7 +101,7 @@ class PackagesParser(ContentHandler):
|
||||||
|
|
||||||
return self.packages
|
return self.packages
|
||||||
|
|
||||||
def startElement(self, name: str, attrs: Mapping[str, Any]):
|
def startElement(self, name: str, attrs: Mapping[str, Any]): # type: ignore
|
||||||
self.current_path.append(name)
|
self.current_path.append(name)
|
||||||
LOG.debug("entering element %s", self.current_path)
|
LOG.debug("entering element %s", self.current_path)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import io
|
import io
|
||||||
|
import re
|
||||||
from typing import BinaryIO, Optional
|
from typing import BinaryIO, Optional
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
|
@ -619,6 +620,30 @@ async def test_typical_index():
|
||||||
|
|
||||||
assert '<a href="vmlinuz">' in by_relative_dir["images/pxeboot"].content
|
assert '<a href="vmlinuz">' in by_relative_dir["images/pxeboot"].content
|
||||||
|
|
||||||
|
# Sample the order of entries in some of the listings.
|
||||||
|
# Directories are expected to come first.
|
||||||
|
links = re.findall(r'<a href="([^"]+)"', by_relative_dir[""].content)
|
||||||
|
assert links == [
|
||||||
|
"images/",
|
||||||
|
"packages/",
|
||||||
|
"repodata/",
|
||||||
|
"EULA",
|
||||||
|
"GPL",
|
||||||
|
"RPM-GPG-KEY-redhat-beta",
|
||||||
|
"RPM-GPG-KEY-redhat-release",
|
||||||
|
"extra_files.json",
|
||||||
|
"treeinfo",
|
||||||
|
]
|
||||||
|
|
||||||
|
links = re.findall(r'<a href="([^"]+)"', by_relative_dir["images"].content)
|
||||||
|
assert links == [
|
||||||
|
"../",
|
||||||
|
"pxeboot/",
|
||||||
|
"boot.iso",
|
||||||
|
"efiboot.img",
|
||||||
|
"install.img",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
async def test_typical_appstream_index():
|
async def test_typical_appstream_index():
|
||||||
fetcher = StaticFetcher()
|
fetcher = StaticFetcher()
|
||||||
|
|
Loading…
Add table
Reference in a new issue