validate_config.py 4.6 KB

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