save_new_checkfile.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. from os import system, path
  13. import shutil
  14. from utils import log, expand_dir, error_msg
  15. import config as const
  16. def save_new_checkfile() -> None:
  17. cache_dir = expand_dir(const.SSYNC_CACHE_DIR)
  18. log("saving new checkfile...")
  19. system(
  20. 'rclone md5sum "{}" > "{}"'.format(
  21. const.RCLONE_REMOTE_DIR,
  22. path.join(cache_dir, const.SSYNC_CHECKFILE_NAMING),
  23. )
  24. )
  25. try:
  26. if not path.isfile(path.join(cache_dir, const.SSYNC_CACHEFILE_NAMING)):
  27. shutil.copyfile(
  28. path.join(cache_dir, const.SSYNC_CHECKFILE_NAMING),
  29. path.join(cache_dir, const.SSYNC_CACHEFILE_NAMING),
  30. )
  31. except (FileNotFoundError, PermissionError, IOError) as error:
  32. error_msg("Failed to save new checkfile. Reason: {}".format(error))