mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-11 09:13:57 -04:00
Add some private API
This commit is contained in:
parent
c01b8ea033
commit
262d5031fd
@ -9,6 +9,50 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
SPOOL_SIZE = 30*1024*1024
|
||||
|
||||
def _get_next_series_num_for_list(series_indices):
|
||||
from calibre.utils.config_base import tweaks
|
||||
from math import ceil, floor
|
||||
if not series_indices:
|
||||
if isinstance(tweaks['series_index_auto_increment'], (int, float)):
|
||||
return float(tweaks['series_index_auto_increment'])
|
||||
return 1.0
|
||||
series_indices = [x[0] for x in series_indices]
|
||||
if tweaks['series_index_auto_increment'] == 'next':
|
||||
return floor(series_indices[-1]) + 1
|
||||
if tweaks['series_index_auto_increment'] == 'first_free':
|
||||
for i in xrange(1, 10000):
|
||||
if i not in series_indices:
|
||||
return i
|
||||
# really shouldn't get here.
|
||||
if tweaks['series_index_auto_increment'] == 'next_free':
|
||||
for i in xrange(int(ceil(series_indices[0])), 10000):
|
||||
if i not in series_indices:
|
||||
return i
|
||||
# really shouldn't get here.
|
||||
if tweaks['series_index_auto_increment'] == 'last_free':
|
||||
for i in xrange(int(ceil(series_indices[-1])), 0, -1):
|
||||
if i not in series_indices:
|
||||
return i
|
||||
return series_indices[-1] + 1
|
||||
if isinstance(tweaks['series_index_auto_increment'], (int, float)):
|
||||
return float(tweaks['series_index_auto_increment'])
|
||||
return 1.0
|
||||
|
||||
def _get_series_values(val):
|
||||
import re
|
||||
series_index_pat = re.compile(r'(.*)\s+\[([.0-9]+)\]$')
|
||||
if not val:
|
||||
return (val, None)
|
||||
match = series_index_pat.match(val.strip())
|
||||
if match is not None:
|
||||
idx = match.group(2)
|
||||
try:
|
||||
idx = float(idx)
|
||||
return (match.group(1).strip(), idx)
|
||||
except:
|
||||
pass
|
||||
return (val, None)
|
||||
|
||||
'''
|
||||
Rewrite of the calibre database backend.
|
||||
|
||||
|
@ -9,6 +9,7 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
import os, traceback
|
||||
from functools import partial
|
||||
|
||||
from calibre.db import _get_next_series_num_for_list, _get_series_values
|
||||
from calibre.db.backend import DB
|
||||
from calibre.db.cache import Cache
|
||||
from calibre.db.categories import CATEGORY_SORTS
|
||||
@ -153,7 +154,17 @@ class LibraryDatabase(object):
|
||||
os.makedirs(path)
|
||||
return path
|
||||
|
||||
# Private interface {{{
|
||||
|
||||
def __iter__(self):
|
||||
for row in self.data.iterall():
|
||||
yield row
|
||||
|
||||
def _get_next_series_num_for_list(self, series_indices):
|
||||
return _get_next_series_num_for_list(series_indices)
|
||||
|
||||
def _get_series_values(self, val):
|
||||
return _get_series_values(val)
|
||||
|
||||
# }}}
|
||||
|
||||
|
@ -6,6 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import inspect
|
||||
from calibre.db.tests.base import BaseTest
|
||||
|
||||
class LegacyTest(BaseTest):
|
||||
@ -108,11 +109,25 @@ class LegacyTest(BaseTest):
|
||||
db = self.init_old(cl)
|
||||
ndb = self.init_legacy()
|
||||
|
||||
SKIP_ATTRS = {'TCat_Tag'}
|
||||
SKIP_ATTRS = {
|
||||
'TCat_Tag', '_add_newbook_tag', '_clean_identifier', '_library_id_', '_set_authors',
|
||||
'_set_title', '_set_custom', '_update_author_in_cache',
|
||||
}
|
||||
SKIP_ARGSPEC = {
|
||||
'__init__',
|
||||
}
|
||||
|
||||
for attr in dir(db):
|
||||
if attr in SKIP_ATTRS:
|
||||
continue
|
||||
self.assertTrue(hasattr(ndb, attr), 'The attribute %s is missing' % attr)
|
||||
# obj = getattr(db, attr)
|
||||
obj, nobj = getattr(db, attr), getattr(ndb, attr)
|
||||
if attr not in SKIP_ARGSPEC:
|
||||
try:
|
||||
argspec = inspect.getargspec(obj)
|
||||
except TypeError:
|
||||
pass
|
||||
else:
|
||||
self.assertEqual(argspec, inspect.getargspec(nobj), 'argspec for %s not the same' % attr)
|
||||
# }}}
|
||||
|
||||
|
@ -11,7 +11,6 @@ import os, sys, shutil, cStringIO, glob, time, functools, traceback, re, \
|
||||
from collections import defaultdict
|
||||
import threading, random
|
||||
from itertools import repeat
|
||||
from math import ceil, floor
|
||||
|
||||
from calibre import prints, force_unicode
|
||||
from calibre.ebooks.metadata import (title_sort, author_to_author_sort,
|
||||
@ -42,6 +41,7 @@ from calibre.ebooks import BOOK_EXTENSIONS, check_ebook_format
|
||||
from calibre.utils.magick.draw import save_cover_data_to
|
||||
from calibre.utils.recycle_bin import delete_file, delete_tree
|
||||
from calibre.utils.formatter_functions import load_user_template_functions
|
||||
from calibre.db import _get_next_series_num_for_list, _get_series_values
|
||||
from calibre.db.errors import NoSuchFormat
|
||||
from calibre.db.lazy import FormatMetadata, FormatsList
|
||||
from calibre.db.categories import Tag, CATEGORY_SORTS
|
||||
@ -2194,31 +2194,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
||||
return self._get_next_series_num_for_list(series_indices)
|
||||
|
||||
def _get_next_series_num_for_list(self, series_indices):
|
||||
if not series_indices:
|
||||
if isinstance(tweaks['series_index_auto_increment'], (int, float)):
|
||||
return float(tweaks['series_index_auto_increment'])
|
||||
return 1.0
|
||||
series_indices = [x[0] for x in series_indices]
|
||||
if tweaks['series_index_auto_increment'] == 'next':
|
||||
return floor(series_indices[-1]) + 1
|
||||
if tweaks['series_index_auto_increment'] == 'first_free':
|
||||
for i in range(1, 10000):
|
||||
if i not in series_indices:
|
||||
return i
|
||||
# really shouldn't get here.
|
||||
if tweaks['series_index_auto_increment'] == 'next_free':
|
||||
for i in range(int(ceil(series_indices[0])), 10000):
|
||||
if i not in series_indices:
|
||||
return i
|
||||
# really shouldn't get here.
|
||||
if tweaks['series_index_auto_increment'] == 'last_free':
|
||||
for i in range(int(ceil(series_indices[-1])), 0, -1):
|
||||
if i not in series_indices:
|
||||
return i
|
||||
return series_indices[-1] + 1
|
||||
if isinstance(tweaks['series_index_auto_increment'], (int, float)):
|
||||
return float(tweaks['series_index_auto_increment'])
|
||||
return 1.0
|
||||
return _get_next_series_num_for_list(series_indices)
|
||||
|
||||
def set(self, row, column, val, allow_case_change=False):
|
||||
'''
|
||||
@ -3156,17 +3132,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
||||
series_index_pat = re.compile(r'(.*)\s+\[([.0-9]+)\]$')
|
||||
|
||||
def _get_series_values(self, val):
|
||||
if not val:
|
||||
return (val, None)
|
||||
match = self.series_index_pat.match(val.strip())
|
||||
if match is not None:
|
||||
idx = match.group(2)
|
||||
try:
|
||||
idx = float(idx)
|
||||
return (match.group(1).strip(), idx)
|
||||
except:
|
||||
pass
|
||||
return (val, None)
|
||||
return _get_series_values(val)
|
||||
|
||||
def set_series(self, id, series, notify=True, commit=True, allow_case_change=True):
|
||||
self.conn.execute('DELETE FROM books_series_link WHERE book=?',(id,))
|
||||
|
Loading…
x
Reference in New Issue
Block a user