stop_cd_recording.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python3
  2. """
  3. Copyright © 2024 Noah Vogt <noah@noahvogt.com>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. """
  15. from os import kill
  16. from signal import SIGTERM
  17. from utils import (
  18. get_yyyy_mm_dd_date,
  19. make_sure_file_exists,
  20. is_valid_cd_record_checkfile,
  21. log,
  22. error_msg,
  23. expand_dir,
  24. mark_end_of_recording,
  25. )
  26. from input import get_cachefile_content, validate_cd_record_config
  27. import config as const
  28. def stop_cd_recording() -> None:
  29. cachefile_content = get_cachefile_content(const.CD_RECORD_CACHEFILE)
  30. yyyy_mm_dd = get_yyyy_mm_dd_date()
  31. if is_valid_cd_record_checkfile(cachefile_content, yyyy_mm_dd):
  32. try:
  33. kill(int(cachefile_content[2]), SIGTERM)
  34. except ProcessLookupError:
  35. error_msg("Recording not running, cannot be stopped.")
  36. mark_end_of_recording(cachefile_content)
  37. else:
  38. error_msg("CD Record Checkfile is invalid.")
  39. def main() -> None:
  40. validate_cd_record_config()
  41. make_sure_file_exists(const.CD_RECORD_CACHEFILE)
  42. stop_cd_recording()
  43. if __name__ == "__main__":
  44. main()