mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Allow automatic series increment algorithm to be tweaked by editing the config file tweaks.py
This commit is contained in:
parent
08e0fbf7e9
commit
3b28deb26e
18
resources/default_tweaks.py
Normal file
18
resources/default_tweaks.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||||
|
__license__ = 'GPL v3'
|
||||||
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
'''
|
||||||
|
Contains various tweaks that affect calibre behavior. Only edit this file if
|
||||||
|
you know what you are dong. If you delete this file, it will be recreated from
|
||||||
|
defaults.
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
# The algorithm used to assign a new book in an existing series a series number.
|
||||||
|
# Possible values are:
|
||||||
|
# next - Next available number
|
||||||
|
# const - Assign the number 1 always
|
||||||
|
series_index_auto_increment = 'next'
|
@ -28,7 +28,7 @@ from calibre.ebooks.metadata import authors_to_sort_string, string_to_authors, \
|
|||||||
from calibre.ebooks.metadata.library_thing import cover_from_isbn
|
from calibre.ebooks.metadata.library_thing import cover_from_isbn
|
||||||
from calibre import islinux
|
from calibre import islinux
|
||||||
from calibre.ebooks.metadata.meta import get_metadata
|
from calibre.ebooks.metadata.meta import get_metadata
|
||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs, tweaks
|
||||||
from calibre.customize.ui import run_plugins_on_import, get_isbndb_key
|
from calibre.customize.ui import run_plugins_on_import, get_isbndb_key
|
||||||
from calibre.gui2.dialogs.config.social import SocialMetadata
|
from calibre.gui2.dialogs.config.social import SocialMetadata
|
||||||
|
|
||||||
@ -399,6 +399,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
if not pm.isNull():
|
if not pm.isNull():
|
||||||
self.cover.setPixmap(pm)
|
self.cover.setPixmap(pm)
|
||||||
self.cover_data = cover
|
self.cover_data = cover
|
||||||
|
self.original_series_name = unicode(self.series.text()).strip()
|
||||||
|
|
||||||
def validate_isbn(self, isbn):
|
def validate_isbn(self, isbn):
|
||||||
isbn = unicode(isbn).strip()
|
isbn = unicode(isbn).strip()
|
||||||
@ -610,10 +611,13 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
def increment_series_index(self):
|
def increment_series_index(self):
|
||||||
if self.db is not None:
|
if self.db is not None:
|
||||||
try:
|
try:
|
||||||
series = unicode(self.series.text())
|
series = unicode(self.series.text()).strip()
|
||||||
if series:
|
if series and series != self.original_series_name:
|
||||||
ns = self.db.get_next_series_num_for(series)
|
ns = 1
|
||||||
|
if tweaks['series_index_auto_increment'] == 'next':
|
||||||
|
ns = self.db.get_next_series_num_for(series)
|
||||||
self.series_index.setValue(ns)
|
self.series_index.setValue(ns)
|
||||||
|
self.original_series_name = series
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ from calibre.gui2.widgets import EnLineEdit, TagsLineEdit
|
|||||||
from calibre.utils.search_query_parser import SearchQueryParser
|
from calibre.utils.search_query_parser import SearchQueryParser
|
||||||
from calibre.ebooks.metadata.meta import set_metadata as _set_metadata
|
from calibre.ebooks.metadata.meta import set_metadata as _set_metadata
|
||||||
from calibre.ebooks.metadata import string_to_authors, fmt_sidx
|
from calibre.ebooks.metadata import string_to_authors, fmt_sidx
|
||||||
|
from calibre.utils.config import tweaks
|
||||||
|
|
||||||
class LibraryDelegate(QItemDelegate):
|
class LibraryDelegate(QItemDelegate):
|
||||||
COLOR = QColor("blue")
|
COLOR = QColor("blue")
|
||||||
@ -660,9 +661,10 @@ class BooksModel(QAbstractTableModel):
|
|||||||
self.db.set_series_index(id, float(match.group(1)))
|
self.db.set_series_index(id, float(match.group(1)))
|
||||||
val = pat.sub('', val).strip()
|
val = pat.sub('', val).strip()
|
||||||
elif val:
|
elif val:
|
||||||
ni = self.db.get_next_series_num_for(val)
|
if tweaks['series_index_auto_increment'] == 'next':
|
||||||
if ni != 1:
|
ni = self.db.get_next_series_num_for(val)
|
||||||
self.db.set_series_index(id, ni)
|
if ni != 1:
|
||||||
|
self.db.set_series_index(id, ni)
|
||||||
if val:
|
if val:
|
||||||
self.db.set_series(id, val)
|
self.db.set_series(id, val)
|
||||||
elif column == 'timestamp':
|
elif column == 'timestamp':
|
||||||
|
@ -6,7 +6,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
'''
|
'''
|
||||||
Manage application-wide preferences.
|
Manage application-wide preferences.
|
||||||
'''
|
'''
|
||||||
import os, re, cPickle, textwrap, traceback, plistlib, json
|
import os, re, cPickle, textwrap, traceback, plistlib, json, shutil
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from optparse import OptionParser as _OptionParser
|
from optparse import OptionParser as _OptionParser
|
||||||
@ -676,6 +676,24 @@ def _prefs():
|
|||||||
|
|
||||||
prefs = ConfigProxy(_prefs())
|
prefs = ConfigProxy(_prefs())
|
||||||
|
|
||||||
|
# Read tweaks
|
||||||
|
def read_tweaks():
|
||||||
|
tweaks_file = os.path.join(config_dir, 'tweaks.py')
|
||||||
|
if not os.path.exists(tweaks_file):
|
||||||
|
shutil.copyfile(P('default_tweaks.py'), tweaks_file)
|
||||||
|
l, g = {}, {}
|
||||||
|
try:
|
||||||
|
exec open(tweaks_file, 'rb') in g, l
|
||||||
|
except:
|
||||||
|
print 'Failed to load custom tweaks file'
|
||||||
|
traceback.print_exc()
|
||||||
|
dl, dg = {}, {}
|
||||||
|
exec P('default_tweaks.py', data=True) in dg, dl
|
||||||
|
dl.update(l)
|
||||||
|
return dl
|
||||||
|
|
||||||
|
tweaks = read_tweaks()
|
||||||
|
|
||||||
def migrate():
|
def migrate():
|
||||||
if hasattr(os, 'geteuid') and os.geteuid() == 0:
|
if hasattr(os, 'geteuid') and os.geteuid() == 0:
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user