Skip to content

Commit

Permalink
Add thumbnail export
Browse files Browse the repository at this point in the history
  • Loading branch information
CkuT committed May 6, 2017
1 parent 1f145c6 commit 2e0e6bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/documents/management/commands/document_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def dump(self):
document = document_map[document_dict["pk"]]

target = os.path.join(self.target, document.file_name)
thumbnail_target = target + "-tumbnail.png"
document_dict["__exported_file_name__"] = target
document_dict["__exported_thumbnail_name__"] = thumbnail_target

print("Exporting: {}".format(target))

Expand All @@ -71,6 +73,11 @@ def dump(self):
t = int(time.mktime(document.created.timetuple()))
os.utime(target, times=(t, t))

with open(thumbnail_target, "wb") as f:
f.write(GnuPG.decrypted(document.thumbnail_file))
t = int(time.mktime(document.created.timetuple()))
os.utime(target, times=(t, t))

manifest += json.loads(
serializers.serialize("json", Correspondent.objects.all()))

Expand Down
6 changes: 6 additions & 0 deletions src/documents/management/commands/document_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,15 @@ def _import_files_from_manifest(self):
continue

doc_file = record["__exported_file_name__"]
thumb_file = record["__exported_thumbnail_name__"]
document = Document.objects.get(pk=record["pk"])
with open(doc_file, "rb") as unencrypted:
with open(document.source_path, "wb") as encrypted:
print("Encrypting {} and saving it to {}".format(
doc_file, document.source_path))
encrypted.write(GnuPG.encrypted(unencrypted))
with open(thumb_file, "rb") as unencrypted:
with open(document.thumbnail_path, "wb") as encrypted:
print("Encrypting {} and saving it to {}".format(
thumb_file, document.thumbnail_path))
encrypted.write(GnuPG.encrypted(unencrypted))

0 comments on commit 2e0e6bb

Please sign in to comment.