From ccf76d2ba3dfd7cd89202353cd2f802c54b945f7 Mon Sep 17 00:00:00 2001 From: insolor <2442833+insolor@users.noreply.github.com> Date: Sun, 19 Jan 2025 00:33:02 +0300 Subject: [PATCH] Sort file names by lang, os, variant, version --- app.py | 13 ++++++++++++- package_build/file_list.py | 6 ++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index e30b155..07e0262 100644 --- a/app.py +++ b/app.py @@ -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) diff --git a/package_build/file_list.py b/package_build/file_list.py index 848ffd4..6e0a887 100644 --- a/package_build/file_list.py +++ b/package_build/file_list.py @@ -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 @@ -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)] @@ -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