From 45cf24206d986119ed529e5cadc524682ee3a470 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 22 Jun 2011 12:58:49 -0600 Subject: [PATCH] API for kiwidude --- src/calibre/library/database2.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 4c61438e35..6848e3c6ae 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en' The database used to store ebook metadata ''' import os, sys, shutil, cStringIO, glob, time, functools, traceback, re, \ - json, uuid, tempfile + json, uuid, tempfile, hashlib import threading, random from itertools import repeat from math import ceil @@ -1118,9 +1118,26 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): return self.format_abspath(index, format, index_is_id) is not None def format_last_modified(self, id_, fmt): + m = self.format_metadata(id_, fmt) + if m: + return m['mtime'] + + def format_metadata(self, id_, fmt): path = self.format_abspath(id_, fmt, index_is_id=True) + ans = {} if path is not None: - return utcfromtimestamp(os.stat(path).st_mtime) + stat = os.stat(path) + ans['size'] = stat.st_size + ans['mtime'] = utcfromtimestamp(stat.st_mtime) + return ans + + def format_hash(self, id_, fmt): + data = self.format(id_, fmt, index_is_id=True) + if data is None: + raise NoSuchFormat('Record %d has no fmt: %s'%(id_, fmt)) + sha = hashlib.sha256() + sha.update(data) + return sha.hexdigest() def format_abspath(self, index, format, index_is_id=False): '''