mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
API for kiwidude
This commit is contained in:
parent
28be8a15f1
commit
45cf24206d
@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
The database used to store ebook metadata
|
The database used to store ebook metadata
|
||||||
'''
|
'''
|
||||||
import os, sys, shutil, cStringIO, glob, time, functools, traceback, re, \
|
import os, sys, shutil, cStringIO, glob, time, functools, traceback, re, \
|
||||||
json, uuid, tempfile
|
json, uuid, tempfile, hashlib
|
||||||
import threading, random
|
import threading, random
|
||||||
from itertools import repeat
|
from itertools import repeat
|
||||||
from math import ceil
|
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
|
return self.format_abspath(index, format, index_is_id) is not None
|
||||||
|
|
||||||
def format_last_modified(self, id_, fmt):
|
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)
|
path = self.format_abspath(id_, fmt, index_is_id=True)
|
||||||
|
ans = {}
|
||||||
if path is not None:
|
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):
|
def format_abspath(self, index, format, index_is_id=False):
|
||||||
'''
|
'''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user