diff options
Diffstat (limited to 'trunk/dimbola/plugins/checksum_plugin.py')
-rw-r--r-- | trunk/dimbola/plugins/checksum_plugin.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/trunk/dimbola/plugins/checksum_plugin.py b/trunk/dimbola/plugins/checksum_plugin.py new file mode 100644 index 0000000..e58abf1 --- /dev/null +++ b/trunk/dimbola/plugins/checksum_plugin.py @@ -0,0 +1,78 @@ +# Copyright (C) 2009 Lars Wirzenius <liw@liw.fi> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + + +# This is necessary for running under Python 2.5, which we need to +# do on Debian, for now. +from __future__ import with_statement + + +import datetime +import hashlib +import os +import subprocess + +import gtk +import pyexiv2 + +import dimbola + + +class ChecksumResult(dimbola.BackgroundStatus): + + def __init__(self, action, description, photoid, sha1): + dimbola.BackgroundStatus.__init__(self, action, description) + self.photoid = photoid + self.sha1 = sha1 + + def process_result(self, mwc): + with mwc.db: + mwc.db.set_sha1(self.photoid, self.sha1) + + +class ComputeChecksumJob(dimbola.BackgroundJob): + + '''Compute checksum for a specific photo.''' + + def __init__(self, photoid, pathname): + self.photoid = photoid + self.pathname = pathname + + def run(self): + return ChecksumResult('stop', 'Checksum for %s' % self.pathname, + self.photoid, dimbola.sha1(self.pathname)) + + +class ComputeChecksums(dimbola.Plugin): + + '''Compute checksums for original photo files.''' + + def __init__(self, mwc): + self.mwc = mwc + + def enable(self): + self.mwc.add_to_menu('file_menu', 'missing_checksums_menuitem', + 'Compute missing checksums') + + def disable(self): + self.mwc.remove_from_menu('file_menu', 'missing_checksums_menuitem') + + def on_missing_checksums_menuitem_activate(self, *args): + with self.mwc.db: + photoids = self.mwc.db.find_photos_without_checksum() + for photoid in photoids: + pathname = self.mwc.db.get_photo_pathname(photoid) + self.mwc.add_bgjob(ComputeChecksumJob(photoid, pathname)) + |