From 716c14856ac8884f9b520bf67088b0df915e1393 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Fri, 11 Oct 2013 17:22:47 +0000 Subject: [PATCH] Update media checksums in the check and repair tool svn: r23307 --- gramps/plugins/tool/check.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/gramps/plugins/tool/check.py b/gramps/plugins/tool/check.py index 040fef266..820f14297 100644 --- a/gramps/plugins/tool/check.py +++ b/gramps/plugins/tool/check.py @@ -71,7 +71,7 @@ from gramps.gen.utils.unknown import make_unknown from gramps.gen.utils.file import (media_path_full, find_file, fix_encoding, get_unicode_path_from_file_chooser) from gramps.gui.managedwindow import ManagedWindow - +from gramps.gen.utils.file import create_checksum from gramps.gui.plug import tool from gramps.gui.dialog import OkDialog, MissingMediaDialog from gramps.gen.display.name import displayer as _nd @@ -202,6 +202,7 @@ class Check(tool.BatchTool): checker.check_repo_references() checker.check_note_references() checker.check_tag_references() + checker.check_checksum() self.db.enable_signals() self.db.request_rebuild() @@ -1787,6 +1788,23 @@ class CheckIntegrity(object): if not missing_references: self.db.add_note(self.explanation, self.trans, set_gid=True) + def check_checksum(self): + self.progress.set_pass(_('Updating checksums on media'), + len(self.db.get_media_object_handles())) + for bObjectId in self.db.get_media_object_handles(): + self.progress.step() + ObjectId = handle2internal(bObjectId) + obj = self.db.get_object_from_handle(ObjectId) + if os.path.isabs(obj.path): + full_path = obj.path + else: + full_path = os.path.join(self.db.get_mediapath(), obj.path) + new_checksum = create_checksum(full_path) + if new_checksum != obj.checksum: + logging.info('checksum: updating ' + obj.gramps_id) + obj.checksum = new_checksum + self.db.commit_media_object(obj, self.trans) + def check_tag_references(self): known_handles = [handle2internal(key) for key in self.db.get_tag_handles()]