archive_2.py 690 B

12345678910111213141516171819202122232425
  1. def create_archive_info(filepath, extracted_path, archive_sha=None):
  2. """
  3. Saves archive info to a json file
  4. :param str filepath: Path to directory of archive
  5. :param str extracted_path: Path to directory of archive
  6. :param str archive_sha: SHA string created when archive was extracted from zip
  7. """
  8. archive_info = {
  9. "sha1": archive_sha,
  10. "filename": os.path.split(filepath)[1],
  11. }
  12. with io.open(
  13. os.path.join(
  14. extracted_path,
  15. ".slackviewer_archive_info.json",
  16. ), 'w+', encoding="utf-8"
  17. ) as f:
  18. s = json.dumps(archive_info, ensure_ascii=False)
  19. s = to_unicode(s)
  20. f.write(s)