validate_config.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # Copyright © 2024 Noah Vogt <noah@noahvogt.com>
  2. # This program is free software: you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation, either version 3 of the License, or
  5. # (at your option) any later version.
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. # You should have received a copy of the GNU General Public License
  11. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. import sys
  13. from PyQt5.QtWidgets import ( # pylint: disable=no-name-in-module
  14. QApplication,
  15. QMessageBox,
  16. )
  17. from utils import log, error_msg, InfoMsgBox
  18. import config as const
  19. def validate_ssync_config() -> None:
  20. needed_constants: dict = {
  21. "RCLONE_LOCAL_DIR": const.RCLONE_LOCAL_DIR,
  22. "RCLONE_REMOTE_DIR": const.RCLONE_REMOTE_DIR,
  23. "SSYNC_CHECKFILE_NAMING": const.SSYNC_CHECKFILE_NAMING,
  24. "SSYNC_CACHEFILE_NAMING": const.SSYNC_CACHEFILE_NAMING,
  25. "SSYNC_CACHE_DIR": const.SSYNC_CACHE_DIR,
  26. "OBS_SLIDES_DIR": const.OBS_SLIDES_DIR,
  27. "OBS_SUBDIR_NAMING": const.OBS_SUBDIR_NAMING,
  28. "OBS_MIN_SUBDIRS": const.OBS_MIN_SUBDIRS,
  29. "SSYNC_CHOSEN_FILE_NAMING": const.SSYNC_CHOSEN_FILE_NAMING,
  30. }
  31. general_config_validator(needed_constants)
  32. def validate_obs_song_scene_switcher_config() -> None:
  33. needed_constants: dict = {
  34. "NEXTSONG_CACHE_FILE": const.NEXTSONG_CACHE_FILE,
  35. "OBS_MIN_SUBDIRS": const.OBS_MIN_SUBDIRS,
  36. "OBS_TRANSITION_HOTKEY": const.OBS_TRANSITION_HOTKEY,
  37. "OBS_SWITCH_TO_SCENE_HOTKEY_PREFIX": const.OBS_SWITCH_TO_SCENE_HOTKEY_PREFIX,
  38. }
  39. general_config_validator(needed_constants, gui_error_out=True)
  40. def validate_cd_burn_config() -> None:
  41. needed_constants: dict = {
  42. "CD_RECORD_CACHEFILE": const.CD_RECORD_CACHEFILE,
  43. "CD_RECORD_OUTPUT_BASEDIR": const.CD_RECORD_OUTPUT_BASEDIR,
  44. }
  45. general_config_validator(needed_constants, gui_error_out=True)
  46. def validate_cd_record_config() -> None:
  47. validate_cd_burn_config()
  48. needed_constants: dict = {
  49. "CD_RECORD_FFMPEG_INPUT_ARGS": const.CD_RECORD_FFMPEG_INPUT_ARGS,
  50. "CD_RECORD_MAX_SECONDS": const.CD_RECORD_MAX_SECONDS,
  51. "CD_RECORD_MIN_TRACK_MILIS": const.CD_RECORD_MIN_TRACK_MILIS,
  52. }
  53. general_config_validator(needed_constants, gui_error_out=True)
  54. def validate_sermon_upload_config() -> None:
  55. validate_cd_burn_config()
  56. needed_constants: dict = {
  57. "SERMON_UPLOAD_FTP_HOSTNAME": const.SERMON_UPLOAD_FTP_HOSTNAME,
  58. "SERMON_UPLOAD_FTP_USER": const.SERMON_UPLOAD_FTP_USER,
  59. "SERMON_UPLOAD_FTP_PASSWORD": const.SERMON_UPLOAD_FTP_PASSWORD,
  60. "SERMON_UPLOAD_FTP_UPLOAD_DIR": const.SERMON_UPLOAD_FTP_UPLOAD_DIR,
  61. "SERMON_UPLOAD_SUITABLE_SEGMENT_FRAMES": const.SERMON_UPLOAD_SUITABLE_SEGMENT_FRAMES,
  62. }
  63. general_config_validator(needed_constants, gui_error_out=True)
  64. def general_config_validator(
  65. needed_constants: dict, gui_error_out=False
  66. ) -> None:
  67. for key in needed_constants:
  68. if needed_constants.get(key) == "":
  69. msg = "needed config entry '{}' is empty".format(key)
  70. if not gui_error_out:
  71. error_msg(msg)
  72. app = QApplication
  73. InfoMsgBox(QMessageBox.Critical, "Error", msg)
  74. del app
  75. sys.exit(1)
  76. log("configuration initialised")