choose_cd_dialog.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_cds_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_day() -> 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. # TODO: update text for possibly mutliple CD's
  46. log(f"Burning CD for day: {dialog.chosen}")
  47. return ["", dialog.chosen]
  48. return ["ignore", ""]
  49. except (FileNotFoundError, PermissionError, IOError):
  50. pass
  51. return [
  52. f"Failed to access directory: {const.CD_RECORD_OUTPUT_BASEDIR}.",
  53. "",
  54. ]
  55. def choose_and_burn_cd():
  56. msg, yyyy_mm_dd = choose_cd_day()
  57. if msg == "":
  58. burn_cds_of_day(yyyy_mm_dd)
  59. elif msg != "ignore":
  60. InfoMsgBox(QMessageBox.Critical, "Error", msg)
  61. if __name__ == "__main__":
  62. validate_cd_record_config()
  63. choose_and_burn_cd()