backup.py 1.0 KB

12345678910111213141516171819202122232425
  1. # SPDX-FileCopyrightText: 2026 MOD Audio UG
  2. # SPDX-License-Identifier: AGPL-3.0-or-later
  3. """Helpers for Settings -> Backup & Restore, which runs the device's mod-backup tool."""
  4. BACKUP_FLAGS = ("-d", "-p", "-u")
  5. def backup_flags(cdata):
  6. """'<device configs>,<plugins>[,<user files>[,<browser time>]]' -> mod-backup options.
  7. The first three are '1' or '0'; two values (pages before 1.15) still work. The browser time
  8. (seconds since 1970) dates the backup: the Dwarf has no battery-backed clock."""
  9. flags = cdata.split(",")
  10. options = [flag for index, flag in enumerate(BACKUP_FLAGS) if len(flags) > index and flags[index] == "1"]
  11. if len(flags) > 3 and flags[3].isdigit() and len(flags[3]) <= 12:
  12. options.append("--time=" + flags[3])
  13. return options
  14. def backup_message(stderr):
  15. """mod-backup's stderr as one sentence for the web interface."""
  16. msg = stderr.decode("utf-8", errors="ignore").strip()
  17. if len(msg) > 1:
  18. msg = msg[0].upper() + msg[1:]
  19. if not msg.endswith("."):
  20. msg += "."
  21. return msg