choose_cd_dialog.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python3
  2. """
  3. Copyright © 2024 Noah Vogt <noah@noahvogt.com>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. """
  15. import sys
  16. from os import listdir
  17. from PyQt5.QtWidgets import ( # pylint: disable=no-name-in-module
  18. QApplication,
  19. QDialog,
  20. QMessageBox,
  21. )
  22. from utils import (
  23. burn_cd_of_day,
  24. log,
  25. )
  26. from input import (
  27. validate_cd_record_config,
  28. RadioButtonDialog,
  29. InfoMsgBox,
  30. )
  31. import config as const
  32. def choose_cd() -> list[str]:
  33. # pylint: disable=unused-variable
  34. app = QApplication([])
  35. try:
  36. dirs = sorted(listdir(const.CD_RECORD_OUTPUT_BASEDIR))
  37. dirs.reverse()
  38. if not dirs:
  39. return [
  40. f"Did not find any CD's in: {const.CD_RECORD_OUTPUT_BASEDIR}.",
  41. "",
  42. ]
  43. dialog = RadioButtonDialog(dirs, "Choose a CD to Burn")
  44. if dialog.exec_() == QDialog.Accepted:
  45. log(f"Burning CD for day: {dialog.chosen}")
  46. return ["", dialog.chosen]
  47. return ["ignore", ""]
  48. except (FileNotFoundError, PermissionError, IOError):
  49. pass
  50. return [
  51. f"Failed to access directory: {const.CD_RECORD_OUTPUT_BASEDIR}.",
  52. "",
  53. ]
  54. def choose_and_burn_cd():
  55. msg, yyyy_mm_dd = choose_cd()
  56. if msg == "":
  57. burn_cd_of_day(yyyy_mm_dd)
  58. elif msg != "ignore":
  59. InfoMsgBox(QMessageBox.Critical, "Error", msg)
  60. if __name__ == "__main__":
  61. validate_cd_record_config()
  62. choose_and_burn_cd()