Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add temp file cleanup, and protect on saving problems #2

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Model/ImageWriter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from iptcinfo3 import IPTCInfo
import os

class ImageWriter:
def writeTagsFromPredictionsInImages(self, predictions):
Expand All @@ -14,5 +15,10 @@ def writeTagsFromPredictionsInImages(self, predictions):
for category in prediction.m_categories:
if category not in iptcInfo['keywords']:
iptcInfo['keywords'].append(category)

iptcInfo.save()
try:
iptcInfo.save()
tempFilename = filename + "~"
if os.path.exists(tempFilename):
os.remove(tempFilename)
except Exception as e:
print('Error in file "'+filename+'" : \n\t', e)