validate_config.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. # Copyright © 2025 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. "SSYNC_SLIDESHOW_INPUT_NAMING": const.SSYNC_SLIDESHOW_INPUT_NAMING,
  31. "OBS_WEBSOCKET_HOSTNAME": const.OBS_WEBSOCKET_HOSTNAME,
  32. "OBS_WEBSOCKET_PORT": const.OBS_WEBSOCKET_PORT,
  33. }
  34. general_config_validator(needed_constants)
  35. def validate_obs_song_scene_switcher_config() -> None:
  36. needed_constants: dict = {
  37. "NEXTSONG_CACHE_FILE": const.NEXTSONG_CACHE_FILE,
  38. "OBS_MIN_SUBDIRS": const.OBS_MIN_SUBDIRS,
  39. "OBS_WEBSOCKET_HOSTNAME": const.OBS_WEBSOCKET_HOSTNAME,
  40. "OBS_WEBSOCKET_PORT": const.OBS_WEBSOCKET_PORT,
  41. "OBS_SONG_SCENE_PREFIX": const.OBS_SONG_SCENE_PREFIX,
  42. }
  43. general_config_validator(needed_constants, gui_error_out=True)
  44. def validate_obs_song_slides_switcher_config() -> None:
  45. needed_constants: dict = {
  46. "NEXTSONG_CACHE_FILE": const.NEXTSONG_CACHE_FILE,
  47. "SSYNC_SLIDESHOW_INPUT_NAMING": const.SSYNC_SLIDESHOW_INPUT_NAMING,
  48. "OBS_WEBSOCKET_HOSTNAME": const.OBS_WEBSOCKET_HOSTNAME,
  49. "OBS_WEBSOCKET_PORT": const.OBS_WEBSOCKET_PORT,
  50. "OBS_SONG_SCENE_PREFIX": const.OBS_SONG_SCENE_PREFIX,
  51. }
  52. general_config_validator(needed_constants, gui_error_out=True)
  53. def validate_autoprint_infomail_config() -> None:
  54. needed_constants: dict = {
  55. "AUTOPRINT_INFOMAIL_CMD": const.AUTOPRINT_INFOMAIL_CMD,
  56. "AUTOPRINT_INFOMAIL_DATEFILE": const.AUTOPRINT_INFOMAIL_DATEFILE,
  57. }
  58. general_config_validator(needed_constants, gui_error_out=True)
  59. def validate_cd_burn_config() -> None:
  60. needed_constants: dict = {
  61. "CD_RECORD_CACHEFILE": const.CD_RECORD_CACHEFILE,
  62. "CD_RECORD_OUTPUT_BASEDIR": const.CD_RECORD_OUTPUT_BASEDIR,
  63. }
  64. general_config_validator(needed_constants, gui_error_out=True)
  65. def validate_cd_record_config() -> None:
  66. validate_cd_burn_config()
  67. needed_constants: dict = {
  68. "CD_RECORD_FFMPEG_INPUT_ARGS": const.CD_RECORD_FFMPEG_INPUT_ARGS,
  69. "CD_RECORD_MAX_SECONDS": const.CD_RECORD_MAX_SECONDS,
  70. "CD_RECORD_MIN_TRACK_MILIS": const.CD_RECORD_MIN_TRACK_MILIS,
  71. }
  72. general_config_validator(needed_constants, gui_error_out=True)
  73. def validate_manual_filedrop_sermon_upload_config() -> None:
  74. needed_constants: dict = {
  75. "SERMON_UPLOAD_USE_FTP": const.SERMON_UPLOAD_USE_FTP,
  76. "SERMON_UPLOAD_SUITABLE_SEGMENT_FRAMES": const.SERMON_UPLOAD_SUITABLE_SEGMENT_FRAMES,
  77. }
  78. general_config_validator(needed_constants, gui_error_out=True)
  79. if const.SERMON_UPLOAD_USE_FTP:
  80. needed_constants: dict = {
  81. "SERMON_UPLOAD_USE_FTP": const.SERMON_UPLOAD_USE_FTP,
  82. "SERMON_UPLOAD_FTP_HOSTNAME": const.SERMON_UPLOAD_FTP_HOSTNAME,
  83. "SERMON_UPLOAD_FTP_USER": const.SERMON_UPLOAD_FTP_USER,
  84. "SERMON_UPLOAD_FTP_PASSWORD": const.SERMON_UPLOAD_FTP_PASSWORD,
  85. "SERMON_UPLOAD_FTP_UPLOAD_DIR": const.SERMON_UPLOAD_FTP_UPLOAD_DIR,
  86. }
  87. general_config_validator(needed_constants, gui_error_out=True)
  88. else:
  89. needed_constants: dict = {
  90. "SERMON_UPLOAD_WPSM_API_BASE_URL": const.SERMON_UPLOAD_WPSM_API_BASE_URL,
  91. "SERMON_UPLOAD_WPSM_USER": const.SERMON_UPLOAD_WPSM_USER,
  92. "SERMON_UPLOAD_WPSM_PASSWORD": const.SERMON_UPLOAD_WPSM_PASSWORD,
  93. }
  94. general_config_validator(needed_constants, gui_error_out=True)
  95. def validate_sermon_upload_config() -> None:
  96. validate_cd_burn_config()
  97. validate_manual_filedrop_sermon_upload_config()
  98. def general_config_validator(
  99. needed_constants: dict, gui_error_out=False
  100. ) -> None:
  101. for key in needed_constants:
  102. if needed_constants.get(key) == "":
  103. msg = "needed config entry '{}' is empty".format(key)
  104. if not gui_error_out:
  105. error_msg(msg)
  106. app = QApplication
  107. InfoMsgBox(QMessageBox.Critical, "Error", msg)
  108. del app
  109. sys.exit(1)
  110. log("configuration initialised")