mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Get catalog builder code to pass the automated tests
This commit is contained in:
parent
36939fbfe0
commit
1b6ee88d8f
@ -7,7 +7,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os, shutil, sys, time
|
import os, shutil
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
from calibre import strftime
|
from calibre import strftime
|
||||||
@ -334,7 +334,7 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
log.info(" Begin catalog source generation")
|
log.info(" Begin catalog source generation")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
catalog_source_built = catalog.build_sources()
|
catalog.build_sources()
|
||||||
if opts.verbose:
|
if opts.verbose:
|
||||||
log.info(" Completed catalog source generation\n")
|
log.info(" Completed catalog source generation\n")
|
||||||
except (AuthorSortMismatchException, EmptyCatalogException), e:
|
except (AuthorSortMismatchException, EmptyCatalogException), e:
|
||||||
|
@ -56,77 +56,14 @@ class CatalogBuilder(object):
|
|||||||
|
|
||||||
""" property decorators for attributes """
|
""" property decorators for attributes """
|
||||||
if True:
|
if True:
|
||||||
''' list of unique authors '''
|
|
||||||
@property
|
|
||||||
def authors(self):
|
|
||||||
return self.__authors
|
|
||||||
@authors.setter
|
|
||||||
def authors(self, val):
|
|
||||||
self.__authors = val
|
|
||||||
|
|
||||||
''' dict of bookmarked books '''
|
|
||||||
@property
|
|
||||||
def bookmarked_books(self):
|
|
||||||
return self.__bookmarked_books
|
|
||||||
@bookmarked_books.setter
|
|
||||||
def bookmarked_books(self, val):
|
|
||||||
self.__bookmarked_books = val
|
|
||||||
|
|
||||||
''' list of bookmarked books, sorted by date read '''
|
|
||||||
@property
|
|
||||||
def bookmarked_books_by_date_read(self):
|
|
||||||
return self.__bookmarked_books_by_date_read
|
|
||||||
@bookmarked_books_by_date_read.setter
|
|
||||||
def bookmarked_books_by_date_read(self, val):
|
|
||||||
self.__bookmarked_books_by_date_read = val
|
|
||||||
|
|
||||||
''' list of books, sorted by author '''
|
|
||||||
@property
|
|
||||||
def books_by_author(self):
|
|
||||||
return self.__books_by_author
|
|
||||||
@books_by_author.setter
|
|
||||||
def books_by_author(self, val):
|
|
||||||
self.__books_by_author = val
|
|
||||||
|
|
||||||
''' list of books, grouped by date range (30 days) '''
|
|
||||||
@property
|
|
||||||
def books_by_date_range(self):
|
|
||||||
return self.__books_by_date_range
|
|
||||||
@books_by_date_range.setter
|
|
||||||
def books_by_date_range(self, val):
|
|
||||||
self.__books_by_date_range = val
|
|
||||||
|
|
||||||
''' list of books, by date added reverse (most recent first) '''
|
|
||||||
@property
|
|
||||||
def books_by_month(self):
|
|
||||||
return self.__books_by_month
|
|
||||||
@books_by_month.setter
|
|
||||||
def books_by_month(self, val):
|
|
||||||
self.__books_by_month = val
|
|
||||||
|
|
||||||
''' list of books in series '''
|
|
||||||
@property
|
|
||||||
def books_by_series(self):
|
|
||||||
return self.__books_by_series
|
|
||||||
@books_by_series.setter
|
|
||||||
def books_by_series(self, val):
|
|
||||||
self.__books_by_series = val
|
|
||||||
|
|
||||||
''' list of books, sorted by title '''
|
|
||||||
@property
|
|
||||||
def books_by_title(self):
|
|
||||||
return self.__books_by_title
|
|
||||||
@books_by_title.setter
|
|
||||||
def books_by_title(self, val):
|
|
||||||
self.__books_by_title = val
|
|
||||||
|
|
||||||
''' list of books in series, without series prefix '''
|
|
||||||
@property
|
|
||||||
def books_by_title_no_series_prefix(self):
|
|
||||||
return self.__books_by_title_no_series_prefix
|
|
||||||
@books_by_title_no_series_prefix.setter
|
|
||||||
def books_by_title_no_series_prefix(self, val):
|
|
||||||
self.__books_by_title_no_series_prefix = val
|
|
||||||
|
|
||||||
''' directory to store cached thumbs '''
|
''' directory to store cached thumbs '''
|
||||||
@property
|
@property
|
||||||
@ -143,26 +80,12 @@ class CatalogBuilder(object):
|
|||||||
def content_dir(self):
|
def content_dir(self):
|
||||||
return self.__content_dir
|
return self.__content_dir
|
||||||
|
|
||||||
''' track Job progress '''
|
|
||||||
@property
|
|
||||||
def current_step(self):
|
|
||||||
return self.__current_step
|
|
||||||
@current_step.setter
|
|
||||||
def current_step(self, val):
|
|
||||||
self.__current_step = val
|
|
||||||
|
|
||||||
''' active database '''
|
''' active database '''
|
||||||
@property
|
@property
|
||||||
def db(self):
|
def db(self):
|
||||||
return self.__db
|
return self.__db
|
||||||
|
|
||||||
''' cumulative error messages to report at conclusion '''
|
|
||||||
@property
|
|
||||||
def error(self):
|
|
||||||
return self.__error
|
|
||||||
@error.setter
|
|
||||||
def error(self, val):
|
|
||||||
self.__error = val
|
|
||||||
|
|
||||||
''' tags to exclude as genres '''
|
''' tags to exclude as genres '''
|
||||||
@property
|
@property
|
||||||
@ -179,50 +102,15 @@ class CatalogBuilder(object):
|
|||||||
def generate_recently_read(self):
|
def generate_recently_read(self):
|
||||||
return self.__generate_recently_read
|
return self.__generate_recently_read
|
||||||
|
|
||||||
''' list of dicts with books by genre '''
|
|
||||||
@property
|
|
||||||
def genres(self):
|
|
||||||
return self.__genres
|
|
||||||
@genres.setter
|
|
||||||
def genres(self, val):
|
|
||||||
self.__genres = val
|
|
||||||
|
|
||||||
''' dict of enabled genre tags '''
|
|
||||||
@property
|
|
||||||
def genre_tags_dict(self):
|
|
||||||
return self.__genre_tags_dict
|
|
||||||
@genre_tags_dict.setter
|
|
||||||
def genre_tags_dict(self, val):
|
|
||||||
self.__genre_tags_dict = val
|
|
||||||
|
|
||||||
''' Author, Title, Series sections '''
|
|
||||||
@property
|
|
||||||
def html_filelist_1(self):
|
|
||||||
return self.__html_filelist_1
|
|
||||||
@html_filelist_1.setter
|
|
||||||
def html_filelist_1(self, val):
|
|
||||||
self.__html_filelist_1 = val
|
|
||||||
|
|
||||||
''' Date Added, Date Read '''
|
|
||||||
@property
|
|
||||||
def html_filelist_2(self):
|
|
||||||
return self.__html_filelist_2
|
|
||||||
@html_filelist_2.setter
|
|
||||||
def html_filelist_2(self, val):
|
|
||||||
self.__html_filelist_2 = val
|
|
||||||
|
|
||||||
''' additional field to include before/after comments '''
|
''' additional field to include before/after comments '''
|
||||||
@property
|
@property
|
||||||
def merge_comments_rule(self):
|
def merge_comments_rule(self):
|
||||||
return self.__merge_comments_rule
|
return self.__merge_comments_rule
|
||||||
|
|
||||||
''' cumulative HTML for NCX file '''
|
|
||||||
@property
|
|
||||||
def ncx_soup(self):
|
|
||||||
return self.__ncx_soup
|
|
||||||
@ncx_soup.setter
|
|
||||||
def ncx_soup(self, val):
|
|
||||||
self.__ncx_soup = val
|
|
||||||
|
|
||||||
''' opts passed from gui2.catalog.catalog_epub_mobi.py '''
|
''' opts passed from gui2.catalog.catalog_epub_mobi.py '''
|
||||||
@property
|
@property
|
||||||
@ -234,42 +122,14 @@ class CatalogBuilder(object):
|
|||||||
def output_profile(self):
|
def output_profile(self):
|
||||||
return self.__output_profile
|
return self.__output_profile
|
||||||
|
|
||||||
''' playOrder value for building NCX '''
|
|
||||||
@property
|
|
||||||
def play_order(self):
|
|
||||||
return self.__play_order
|
|
||||||
@play_order.setter
|
|
||||||
def play_order(self, val):
|
|
||||||
self.__play_order = val
|
|
||||||
|
|
||||||
''' catalog??? device??? '''
|
''' catalog??? device??? '''
|
||||||
@property
|
@property
|
||||||
def plugin(self):
|
def plugin(self):
|
||||||
return self.__plugin
|
return self.__plugin
|
||||||
|
|
||||||
''' dict of prefix rules '''
|
|
||||||
@property
|
|
||||||
def prefix_rules(self):
|
|
||||||
return self.__prefix_rules
|
|
||||||
@prefix_rules.setter
|
|
||||||
def prefix_rules(self, val):
|
|
||||||
self.__prefix_rules = val
|
|
||||||
|
|
||||||
''' used with ProgressReporter() '''
|
|
||||||
@property
|
|
||||||
def progress_int(self):
|
|
||||||
return self.__progress_int
|
|
||||||
@progress_int.setter
|
|
||||||
def progress_int(self, val):
|
|
||||||
self.__progress_int = val
|
|
||||||
|
|
||||||
''' used with ProgressReporter() '''
|
|
||||||
@property
|
|
||||||
def progress_string(self):
|
|
||||||
return self.__progress_string
|
|
||||||
@progress_string.setter
|
|
||||||
def progress_string(self, val):
|
|
||||||
self.__progress_string = val
|
|
||||||
|
|
||||||
''' Progress Reporter for Jobs '''
|
''' Progress Reporter for Jobs '''
|
||||||
@property
|
@property
|
||||||
@ -315,40 +175,12 @@ class CatalogBuilder(object):
|
|||||||
else:
|
else:
|
||||||
return self.format_prefix(' ')
|
return self.format_prefix(' ')
|
||||||
|
|
||||||
@property
|
|
||||||
def thumb_height(self):
|
|
||||||
return self.__thumb_height
|
|
||||||
@thumb_height.setter
|
|
||||||
def thumb_height(self, val):
|
|
||||||
self.__thumb_height = val
|
|
||||||
|
|
||||||
@property
|
|
||||||
def thumb_width(self):
|
|
||||||
return self.__thumb_width
|
|
||||||
@thumb_width.setter
|
|
||||||
def thumb_width(self, val):
|
|
||||||
self.__thumb_width = val
|
|
||||||
|
|
||||||
''' list of generated thumbs '''
|
|
||||||
@property
|
|
||||||
def thumbs(self):
|
|
||||||
return self.__thumbs
|
|
||||||
@thumbs.setter
|
|
||||||
def thumbs(self, val):
|
|
||||||
self.__thumbs = val
|
|
||||||
|
|
||||||
''' full path to thumbs archive '''
|
''' full path to thumbs archive '''
|
||||||
@property
|
@property
|
||||||
def thumbs_path(self):
|
def thumbs_path(self):
|
||||||
return self.__thumbs_path
|
return self.__thumbs_path
|
||||||
|
|
||||||
''' used with ProgressReporter() '''
|
|
||||||
@property
|
|
||||||
def total_steps(self):
|
|
||||||
return self.__total_steps
|
|
||||||
@total_steps.setter
|
|
||||||
def total_steps(self, val):
|
|
||||||
self.__total_steps = val
|
|
||||||
|
|
||||||
''' switch controlling format of series books in Titles section '''
|
''' switch controlling format of series books in Titles section '''
|
||||||
@property
|
@property
|
||||||
@ -371,39 +203,63 @@ class CatalogBuilder(object):
|
|||||||
_opts.output_profile and
|
_opts.output_profile and
|
||||||
_opts.output_profile.startswith("kindle")) else False
|
_opts.output_profile.startswith("kindle")) else False
|
||||||
|
|
||||||
self.__authors = None
|
''' list of unique authors '''
|
||||||
self.__bookmarked_books = None
|
self.authors = None
|
||||||
self.__bookmarked_books_by_date_read = None
|
''' dict of bookmarked books '''
|
||||||
self.__books_by_author = None
|
self.bookmarked_books = None
|
||||||
self.__books_by_date_range = None
|
''' list of bookmarked books, sorted by date read '''
|
||||||
self.__books_by_month = None
|
self.bookmarked_books_by_date_read = None
|
||||||
self.__books_by_series = None
|
''' list of books, sorted by author '''
|
||||||
self.__books_by_title = None
|
self.books_by_author = None
|
||||||
self.__books_by_title_no_series_prefix = None
|
''' list of books, grouped by date range (30 days) '''
|
||||||
|
self.books_by_date_range = None
|
||||||
|
''' list of books, by date added reverse (most recent first) '''
|
||||||
|
self.books_by_month = None
|
||||||
|
''' list of books in series '''
|
||||||
|
self.books_by_series = None
|
||||||
|
''' list of books, sorted by title '''
|
||||||
|
self.books_by_title = None
|
||||||
|
''' list of books in series, without series prefix '''
|
||||||
|
self.books_by_title_no_series_prefix = None
|
||||||
self.__content_dir = os.path.join(self.catalog_path, "content")
|
self.__content_dir = os.path.join(self.catalog_path, "content")
|
||||||
self.__current_step = 0.0
|
''' track Job progress '''
|
||||||
self.__error = []
|
self.current_step = 0.0
|
||||||
|
''' cumulative error messages to report at conclusion '''
|
||||||
|
self.error = []
|
||||||
self.__excluded_tags = self.get_excluded_tags()
|
self.__excluded_tags = self.get_excluded_tags()
|
||||||
self.__generate_recently_read = True if (_opts.generate_recently_added and
|
self.__generate_recently_read = True if (_opts.generate_recently_added and
|
||||||
_opts.connected_kindle and
|
_opts.connected_kindle and
|
||||||
self.generate_for_kindle) else False
|
self.generate_for_kindle) else False
|
||||||
self.__genres = []
|
''' list of dicts with books by genre '''
|
||||||
self.__genre_tags_dict = None
|
self.genres = []
|
||||||
self.__html_filelist_1 = []
|
''' dict of enabled genre tags '''
|
||||||
self.__html_filelist_2 = []
|
self.genre_tags_dict = None
|
||||||
|
''' Author, Title, Series sections '''
|
||||||
|
self.html_filelist_1 = []
|
||||||
|
''' Date Added, Date Read '''
|
||||||
|
self.html_filelist_2 = []
|
||||||
self.__merge_comments_rule = dict(zip(['field','position','hr'],_opts.merge_comments_rule.split(':')))
|
self.__merge_comments_rule = dict(zip(['field','position','hr'],_opts.merge_comments_rule.split(':')))
|
||||||
self.__ncx_soup = None
|
''' cumulative HTML for NCX file '''
|
||||||
|
self.ncx_soup = None
|
||||||
self.__output_profile = None
|
self.__output_profile = None
|
||||||
self.__output_profile = self.get_output_profile(_opts)
|
self.__output_profile = self.get_output_profile(_opts)
|
||||||
self.__play_order = 1
|
''' playOrder value for building NCX '''
|
||||||
self.__prefix_rules = self.get_prefix_rules()
|
self.play_order = 1
|
||||||
self.__progress_int = 0.0
|
''' dict of prefix rules '''
|
||||||
self.__progress_string = ''
|
self.prefix_rules = self.get_prefix_rules()
|
||||||
|
''' used with ProgressReporter() '''
|
||||||
|
self.progress_int = 0.0
|
||||||
|
''' used with ProgressReporter() '''
|
||||||
|
self.progress_string = ''
|
||||||
|
|
||||||
self.__thumb_height = 0
|
self.__thumb_height = 0
|
||||||
|
|
||||||
self.__thumb_width = 0
|
self.__thumb_width = 0
|
||||||
self.__thumbs = None
|
''' list of generated thumbs '''
|
||||||
|
self.thumbs = None
|
||||||
self.__thumbs_path = os.path.join(self.cache_dir, "thumbs.zip")
|
self.__thumbs_path = os.path.join(self.cache_dir, "thumbs.zip")
|
||||||
self.__total_steps = 6.0
|
''' used with ProgressReporter() '''
|
||||||
|
self.total_steps = 6.0
|
||||||
self.__use_series_prefix_in_titles_section = False
|
self.__use_series_prefix_in_titles_section = False
|
||||||
|
|
||||||
self.compute_total_steps()
|
self.compute_total_steps()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user