You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 lines
419 B

  1. from pathlib import Path
  2. from openwrt_backup.config import HOSTNAME, NUMBER
  3. def get_all_but_last_n(p: Path, n: int, hostname):
  4. files = list(p.glob("*.tar.gz"))
  5. hostname_files = list(
  6. filter(lambda f: f.name.split("__")[HOSTNAME] == hostname, files)
  7. )
  8. sorted_files = sorted(
  9. hostname_files, key=lambda f: int(f.name.split("__")[NUMBER]), reverse=True
  10. )
  11. return sorted_files[n:]