validate_config.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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
  18. from input import InfoMsgBox
  19. import config as const
  20. def validate_ssync_config() -> None:
  21. needed_constants: dict = {
  22. "RCLONE_LOCAL_DIR": const.RCLONE_LOCAL_DIR,
  23. "RCLONE_REMOTE_DIR": const.RCLONE_REMOTE_DIR,
  24. "SSYNC_CHECKFILE_NAMING": const.SSYNC_CHECKFILE_NAMING,
  25. "SSYNC_CACHEFILE_NAMING": const.SSYNC_CACHEFILE_NAMING,
  26. "SSYNC_CACHE_DIR": const.SSYNC_CACHE_DIR,
  27. "OBS_SLIDES_DIR": const.OBS_SLIDES_DIR,
  28. "OBS_SUBDIR_NAMING": const.OBS_SUBDIR_NAMING,
  29. "OBS_MIN_SUBDIRS": const.OBS_MIN_SUBDIRS,
  30. "SSYNC_CHOSEN_FILE_NAMING": const.SSYNC_CHOSEN_FILE_NAMING,
  31. }
  32. general_config_validator(needed_constants)
  33. def validate_obs_song_scene_switcher_config() -> None:
  34. needed_constants: dict = {
  35. "NEXTSONG_CACHE_FILE": const.NEXTSONG_CACHE_FILE,
  36. "OBS_MIN_SUBDIRS": const.OBS_MIN_SUBDIRS,
  37. "OBS_TRANSITION_HOTKEY": const.OBS_TRANSITION_HOTKEY,
  38. "OBS_SWITCH_TO_SCENE_HOTKEY_PREFIX": const.OBS_SWITCH_TO_SCENE_HOTKEY_PREFIX,
  39. }
  40. general_config_validator(needed_constants, gui_error_out=True)
  41. def validate_cd_burn_config() -> None:
  42. needed_constants: dict = {
  43. "CD_RECORD_CACHEFILE": const.CD_RECORD_CACHEFILE,
  44. "CD_RECORD_OUTPUT_BASEDIR": const.CD_RECORD_OUTPUT_BASEDIR,
  45. }
  46. general_config_validator(needed_constants, gui_error_out=True)
  47. def validate_cd_record_config() -> None:
  48. validate_cd_burn_config()
  49. needed_constants: dict = {
  50. "CD_RECORD_FFMPEG_INPUT_ARGS": const.CD_RECORD_FFMPEG_INPUT_ARGS,
  51. "CD_RECORD_MAX_SECONDS": const.CD_RECORD_MAX_SECONDS,
  52. "CD_RECORD_MIN_TRACK_MILIS": const.CD_RECORD_MIN_TRACK_MILIS,
  53. }
  54. general_config_validator(needed_constants, gui_error_out=True)
  55. def validate_sermon_upload_config() -> None:
  56. validate_cd_burn_config()
  57. needed_constants: dict = {
  58. "SERMON_UPLOAD_FTP_HOSTNAME": const.SERMON_UPLOAD_FTP_HOSTNAME,
  59. "SERMON_UPLOAD_FTP_USER": const.SERMON_UPLOAD_FTP_USER,
  60. "SERMON_UPLOAD_FTP_PASSWORD": const.SERMON_UPLOAD_FTP_PASSWORD,
  61. "SERMON_UPLOAD_FTP_UPLOAD_DIR": const.SERMON_UPLOAD_FTP_UPLOAD_DIR,
  62. "SERMON_UPLOAD_SUITABLE_SEGMENT_FRAMES": const.SERMON_UPLOAD_SUITABLE_SEGMENT_FRAMES,
  63. }
  64. general_config_validator(needed_constants, gui_error_out=True)
  65. def general_config_validator(
  66. needed_constants: dict, gui_error_out=False
  67. ) -> None:
  68. for key in needed_constants:
  69. if needed_constants.get(key) == "":
  70. msg = "needed config entry '{}' is empty".format(key)
  71. if not gui_error_out:
  72. error_msg(msg)
  73. app = QApplication
  74. InfoMsgBox(QMessageBox.Critical, "Error", msg)
  75. del app
  76. sys.exit(1)
  77. log("configuration initialised")