Skip to content

Commit

Permalink
Refactor to get the document time once
Browse files Browse the repository at this point in the history
  • Loading branch information
CkuT committed May 8, 2017
1 parent da71eab commit 3f13927
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/documents/management/commands/document_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,14 @@ def dump(self):

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

t = int(time.mktime(document.created.timetuple()))
with open(target, "wb") as f:
f.write(GnuPG.decrypted(document.source_file))
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))
os.utime(thumbnail_target, times=(t, t))

manifest += json.loads(
serializers.serialize("json", Correspondent.objects.all()))
Expand Down
2 changes: 2 additions & 0 deletions src/documents/management/commands/document_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ def _import_files_from_manifest(self):
doc_file = record[EXPORTER_FILE_NAME]
thumb_file = record[EXPORTER_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(
Expand Down

0 comments on commit 3f13927

Please sign in to comment.