validate_config.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_manual_filedrop_sermon_upload_config() -> None:
  55. needed_constants: dict = {
  56. "SERMON_UPLOAD_USE_FTP": const.SERMON_UPLOAD_USE_FTP,
  57. "SERMON_UPLOAD_SUITABLE_SEGMENT_FRAMES": const.SERMON_UPLOAD_SUITABLE_SEGMENT_FRAMES,
  58. }
  59. general_config_validator(needed_constants, gui_error_out=True)
  60. if const.SERMON_UPLOAD_USE_FTP:
  61. needed_constants: dict = {
  62. "SERMON_UPLOAD_USE_FTP": const.SERMON_UPLOAD_USE_FTP,
  63. "SERMON_UPLOAD_FTP_HOSTNAME": const.SERMON_UPLOAD_FTP_HOSTNAME,
  64. "SERMON_UPLOAD_FTP_USER": const.SERMON_UPLOAD_FTP_USER,
  65. "SERMON_UPLOAD_FTP_PASSWORD": const.SERMON_UPLOAD_FTP_PASSWORD,
  66. "SERMON_UPLOAD_FTP_UPLOAD_DIR": const.SERMON_UPLOAD_FTP_UPLOAD_DIR,
  67. }
  68. general_config_validator(needed_constants, gui_error_out=True)
  69. else:
  70. needed_constants: dict = {
  71. "SERMON_UPLOAD_WPSM_API_BASE_URL": const.SERMON_UPLOAD_WPSM_API_BASE_URL,
  72. "SERMON_UPLOAD_WPSM_USER": const.SERMON_UPLOAD_WPSM_USER,
  73. "SERMON_UPLOAD_WPSM_PASSWORD": const.SERMON_UPLOAD_WPSM_PASSWORD,
  74. }
  75. general_config_validator(needed_constants, gui_error_out=True)
  76. def validate_sermon_upload_config() -> None:
  77. validate_cd_burn_config()
  78. validate_manual_filedrop_sermon_upload_config()
  79. def general_config_validator(
  80. needed_constants: dict, gui_error_out=False
  81. ) -> None:
  82. for key in needed_constants:
  83. if needed_constants.get(key) == "":
  84. msg = "needed config entry '{}' is empty".format(key)
  85. if not gui_error_out:
  86. error_msg(msg)
  87. app = QApplication
  88. InfoMsgBox(QMessageBox.Critical, "Error", msg)
  89. del app
  90. sys.exit(1)
  91. log("configuration initialised")