Skip to content

Commit

Permalink
Sort file names by lang, os, variant, version
Browse files Browse the repository at this point in the history
  • Loading branch information
insolor committed Jan 18, 2025
1 parent dfd3556 commit ccf76d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 12 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,15 @@ def get_language_priority(language_code: str) -> int:
enable_filter = st.checkbox(label=_("Filter available files by DF variant, operating system, language"), value=True)
glob_filter = f"*_{df_variant}_{operating_system}_{dict_entry.code}.zip" if enable_filter else "*.zip"

show_file_list(root_dir, glob_filter=glob_filter)

def file_sort_key(file_path: Path) -> tuple[str, str, str, str]:
_, version, variant, os, language = file_path.name.split("_")
return (
language,
os,
variant,
version,
)


show_file_list(root_dir, glob_filter=glob_filter, sort_key=file_sort_key)
6 changes: 4 additions & 2 deletions package_build/file_list.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from collections.abc import Callable
from datetime import datetime, timezone
from pathlib import Path
from typing import Any

import streamlit as st

Expand All @@ -8,7 +10,7 @@
from package_build.package import get_file_modification_datetime, package_up_to_date


def show_file_list(root_dir: Path, glob_filter: str) -> None:
def show_file_list(root_dir: Path, glob_filter: str, sort_key: Callable[[Path], Any] | None=None) -> None:
st.subheader(_("Package files available to download"))

file_list = [file for file in root_dir.glob(glob_filter) if package_up_to_date(file)]
Expand All @@ -21,7 +23,7 @@ def show_file_list(root_dir: Path, glob_filter: str) -> None:
column1.write("**{}**".format(_("Package name")))
column2.write("**{}**".format(_("When created")))

for package_path in sorted(file_list):
for package_path in sorted(file_list, key=sort_key):
column1, column2, column3 = st.columns([4, 3, 2], vertical_alignment="center")
column1.write(package_path.relative_to(root_dir).name)
hours_ago = (datetime.now(tz=timezone.utc) - get_file_modification_datetime(package_path)).seconds // 3600
Expand Down

0 comments on commit ccf76d2

Please sign in to comment.