From 71b7f434636d402ad672c53ecef0a808e316fd8a Mon Sep 17 00:00:00 2001 From: GRiker Date: Fri, 29 Jan 2010 13:23:59 -0700 Subject: [PATCH 1/3] Multiple catalog tweaks, NCX optimization for Kindle DX, tweaked formatting of Recently Added --- resources/catalog/stylesheet.css | 2 +- src/calibre/library/catalog.py | 110 +++++++++++++------------------ 2 files changed, 48 insertions(+), 64 deletions(-) diff --git a/resources/catalog/stylesheet.css b/resources/catalog/stylesheet.css index eb2352d26a..7bfbbd22cc 100644 --- a/resources/catalog/stylesheet.css +++ b/resources/catalog/stylesheet.css @@ -33,7 +33,7 @@ p.description { p.date_index { font-size:x-large; - text-align:center; + text-align:right; font-weight:bold; margin-top:1em; margin-bottom:0px; diff --git a/src/calibre/library/catalog.py b/src/calibre/library/catalog.py index a10ce56959..3dda46864a 100644 --- a/src/calibre/library/catalog.py +++ b/src/calibre/library/catalog.py @@ -486,7 +486,7 @@ class EPUB_MOBI(CatalogPlugin): # Number of discrete steps to catalog creation current_step = 0.0 - total_steps = 13.0 + total_steps = 14.0 # Used to xlate pubdate to friendly format MONTHS = ['','January', 'February','March','April','May','June', @@ -804,7 +804,7 @@ class EPUB_MOBI(CatalogPlugin): self.generateNCXByDateAdded("Recently Added") if getattr(self.reporter, 'cancel_requested', False): return 1 - self.generateNCXByTags("Genres") + self.generateNCXByGenre("Genres") if getattr(self.reporter, 'cancel_requested', False): return 1 self.writeNCX() @@ -1336,7 +1336,6 @@ class EPUB_MOBI(CatalogPlugin): key=lambda x:(x['title_sort'], x['title_sort'])) this_months_list = sorted(this_months_list, key=lambda x:(x['author_sort'], x['author_sort'])) - print "Books added in %s %s" % (self.MONTHS[current_date.month], current_date.year) # Create a new month anchor pIndexTag = Tag(soup, "p") @@ -1344,19 +1343,16 @@ class EPUB_MOBI(CatalogPlugin): aTag = Tag(soup, "a") aTag['name'] = "%s-%s" % (current_date.year, current_date.month) pIndexTag.insert(0,aTag) - pIndexTag.insert(1,NavigableString('Books added in %s %s' % \ + pIndexTag.insert(1,NavigableString('%s %s' % \ (self.MONTHS[current_date.month],current_date.year))) divTag.insert(dtc,pIndexTag) dtc += 1 current_author = None - for purchase in this_months_list: - print " %-40s \t %-20s \t %s" % (purchase['title'], purchase['author'], purchase['timestamp']) - - - if purchase['author'] != current_author: + for new_entry in this_months_list: + if new_entry['author'] != current_author: # Start a new author - current_author = purchase['author'] + current_author = new_entry['author'] pAuthorTag = Tag(soup, "p") pAuthorTag['class'] = "author_index" emTag = Tag(soup, "em") @@ -1373,7 +1369,7 @@ class EPUB_MOBI(CatalogPlugin): ptc = 0 # Prefix book with read/unread symbol - if purchase['read']: + if new_entry['read']: # check mark pBookTag.insert(ptc,NavigableString(self.READ_SYMBOL)) pBookTag['class'] = "read_book" @@ -1385,8 +1381,8 @@ class EPUB_MOBI(CatalogPlugin): ptc += 1 aTag = Tag(soup, "a") - aTag['href'] = "book_%d.html" % (int(float(purchase['id']))) - aTag.insert(0,escape(purchase['title'])) + aTag['href'] = "book_%d.html" % (int(float(new_entry['id']))) + aTag.insert(0,escape(new_entry['title'])) pBookTag.insert(ptc, aTag) ptc += 1 @@ -1855,9 +1851,13 @@ class EPUB_MOBI(CatalogPlugin): self.ncxSoup = ncx_soup def generateNCXByTitle(self, tocTitle): - self.opts.log.info(self.updateProgressFullStep("generateNCXByTitle()")) + def add_to_books_by_letter(current_book_list): + current_book_list = " • ".join(current_book_list) + current_book_list = self.generateShortDescription(self.formatNCXText(current_book_list)) + books_by_letter.append(current_book_list) + soup = self.ncxSoup output = "ByAlphaTitle" body = soup.find("navPoint") @@ -1891,9 +1891,7 @@ class EPUB_MOBI(CatalogPlugin): for book in self.booksByTitle: if self.letter_or_symbol(book['title_sort'][0]) != current_letter: # Save the old list - book_list = " • ".join(current_book_list) - short_description = self.generateShortDescription(self.formatNCXText(book_list)) - books_by_letter.append(short_description) + add_to_books_by_letter(current_book_list) # Start the new list current_letter = self.letter_or_symbol(book['title_sort'][0]) @@ -1907,9 +1905,7 @@ class EPUB_MOBI(CatalogPlugin): current_book_list.append(book['title']) # Add the last book list - book_list = " • ".join(current_book_list) - short_description = self.generateShortDescription(self.formatNCXText(book_list)) - books_by_letter.append(short_description) + add_to_books_by_letter(current_book_list) # Add *article* entries for each populated title letter for (i,books) in enumerate(books_by_letter): @@ -1944,9 +1940,13 @@ class EPUB_MOBI(CatalogPlugin): self.ncxSoup = soup def generateNCXByAuthor(self, tocTitle): - self.opts.log.info(self.updateProgressFullStep("generateNCXByAuthor()")) + def add_to_author_list(current_author_list, current_letter): + current_author_list = " • ".join(current_author_list) + current_author_list = self.generateShortDescription(self.formatNCXText(current_author_list)) + master_author_list.append((current_author_list, current_letter)) + soup = self.ncxSoup HTML_file = "content/ByAlphaAuthor.html" body = soup.find("navPoint") @@ -1983,14 +1983,7 @@ class EPUB_MOBI(CatalogPlugin): for author in self.authors: if author[1][0] != current_letter: # Save the old list - author_list = " • ".join(current_author_list) - if len(current_author_list) == self.descriptionClip: - author_list += " …" - - author_list = self.formatNCXText(author_list) - if False and self.verbose: - self.opts.log.info(" adding '%s' to master_author_list" % current_letter) - master_author_list.append((author_list, current_letter)) + add_to_author_list(current_author_list, current_letter) # Start the new list current_letter = author[1][0] @@ -2000,13 +1993,7 @@ class EPUB_MOBI(CatalogPlugin): current_author_list.append(author[0]) # Add the last author list - author_list = " • ".join(current_author_list) - if len(current_author_list) == self.descriptionClip: - author_list += " …" - author_list = self.formatNCXText(author_list) - if False and self.verbose: - self.opts.log.info(" adding '%s' to master_author_list" % current_letter) - master_author_list.append((author_list, current_letter)) + add_to_author_list(current_author_list, current_letter) # Add *article* entries for each populated author initial letter # master_author_list{}: [0]:author list [1]:Initial letter @@ -2042,9 +2029,13 @@ class EPUB_MOBI(CatalogPlugin): self.ncxSoup = soup def generateNCXByDateAdded(self, tocTitle): - self.opts.log.info(self.updateProgressFullStep("generateNCXByDateAdded()")) + def add_to_master_month_list(current_titles_list): + current_titles_list = " • ".join(current_titles_list) + current_titles_list = self.generateShortDescription(self.formatNCXText(current_titles_list)) + master_month_list.append((current_titles_list, current_date)) + soup = self.ncxSoup HTML_file = "content/ByDateAdded.html" body = soup.find("navPoint") @@ -2083,31 +2074,23 @@ class EPUB_MOBI(CatalogPlugin): if book['timestamp'].month != current_date.month or \ book['timestamp'].year != current_date.year: # Save the old lists - current_titles_list = " • ".join(current_titles_list) - if len(current_titles_list) == self.descriptionClip: - title_list += " …" - - current_titles_list = self.formatNCXText(current_titles_list) - master_month_list.append((current_titles_list, current_date)) + add_to_master_month_list(current_titles_list) # Start the new list current_date = book['timestamp'].date() current_titles_list = [book['title']] else: - if len(current_titles_list) < self.descriptionClip: - current_titles_list.append(book['title']) + current_titles_list.append(book['title']) - # Add the last author list - current_titles_list = " • ".join(current_titles_list) - master_month_list.append((current_titles_list, current_date)) + # Add the last month list + add_to_master_month_list(current_titles_list) - # Add *article* entries for each populated author initial letter + # Add *article* entries for each populated month # master_months_list{}: [0]:titles list [1]:date for books_by_month in master_month_list: - print "titles:%s \ndate:%s" % books_by_month - navPointByLetterTag = Tag(soup, 'navPoint') - navPointByLetterTag['class'] = "article" - navPointByLetterTag['id'] = "%s-%s-ID" % (books_by_month[1].year,books_by_month[1].month ) + navPointByMonthTag = Tag(soup, 'navPoint') + navPointByMonthTag['class'] = "article" + navPointByMonthTag['id'] = "%s-%s-ID" % (books_by_month[1].year,books_by_month[1].month ) navPointTag['playOrder'] = self.playOrder self.playOrder += 1 navLabelTag = Tag(soup, 'navLabel') @@ -2115,20 +2098,20 @@ class EPUB_MOBI(CatalogPlugin): textTag.insert(0, NavigableString("Books added in %s %s" % \ (self.MONTHS[books_by_month[1].month], books_by_month[1].year))) navLabelTag.insert(0, textTag) - navPointByLetterTag.insert(0,navLabelTag) + navPointByMonthTag.insert(0,navLabelTag) contentTag = Tag(soup, 'content') contentTag['src'] = "%s#%s-%s" % (HTML_file, books_by_month[1].year,books_by_month[1].month) - navPointByLetterTag.insert(1,contentTag) + navPointByMonthTag.insert(1,contentTag) if self.generateForKindle: cmTag = Tag(soup, '%s' % 'calibre:meta') cmTag['name'] = "description" cmTag.insert(0, NavigableString(books_by_month[0])) - navPointByLetterTag.insert(2, cmTag) + navPointByMonthTag.insert(2, cmTag) - navPointTag.insert(nptc, navPointByLetterTag) + navPointTag.insert(nptc, navPointByMonthTag) nptc += 1 # Add this section to the body @@ -2136,12 +2119,15 @@ class EPUB_MOBI(CatalogPlugin): btc += 1 self.ncxSoup = soup - def generateNCXByTags(self, tocTitle): + def generateNCXByGenre(self, tocTitle): # Create an NCX section for 'By Genre' # Add each genre as an article # 'tag', 'file', 'authors' - self.opts.log.info(self.updateProgressFullStep("generateNCXByTags()")) + self.opts.log.info(self.updateProgressFullStep("generateNCXByGenre()")) + + + if not len(self.genres): self.opts.log.warn(" No genres found in tags.\n" @@ -2239,7 +2225,6 @@ class EPUB_MOBI(CatalogPlugin): self.ncxSoup = ncx_soup def writeNCX(self): - self.opts.log.info(self.updateProgressFullStep("writeNCX()")) outfile = open("%s/%s.ncx" % (self.catalogPath, self.basename), 'w') @@ -2533,7 +2518,6 @@ class EPUB_MOBI(CatalogPlugin): def generateShortDescription(self, description): # Truncate the description to description_clip, on word boundaries if necessary - if not description: return None @@ -2545,7 +2529,7 @@ class EPUB_MOBI(CatalogPlugin): # Start adding words until we reach description_clip short_description = "" - words = description.split(" ") + words = description.split() for word in words: short_description += word + " " if len(short_description) > self.descriptionClip: @@ -2667,7 +2651,7 @@ class EPUB_MOBI(CatalogPlugin): # Add local options opts.creator = "calibre" - opts.descriptionClip = 250 + opts.descriptionClip = 380 if self.opts.output_profile.endswith('dx') else 90 opts.basename = "Catalog" opts.plugin_path = self.plugin_path From 1ce23c231468dc03709ee76c7da814fa41c6e4a7 Mon Sep 17 00:00:00 2001 From: GRiker Date: Fri, 29 Jan 2010 15:36:21 -0700 Subject: [PATCH 2/3] Catalog housecleaning, progress reporting fixed --- src/calibre/library/catalog.py | 128 ++++++++++++--------------------- 1 file changed, 44 insertions(+), 84 deletions(-) diff --git a/src/calibre/library/catalog.py b/src/calibre/library/catalog.py index a8b3442dfd..3826aa55ec 100644 --- a/src/calibre/library/catalog.py +++ b/src/calibre/library/catalog.py @@ -502,7 +502,7 @@ class EPUB_MOBI(CatalogPlugin): # verbosity level of diagnostic printout def __init__(self, db, opts, plugin, - notification=DummyReporter(), + report_progress=DummyReporter(), stylesheet="content/stylesheet.css"): self.__opts = opts self.__authors = None @@ -527,16 +527,12 @@ class EPUB_MOBI(CatalogPlugin): self.__plugin_path = opts.plugin_path self.__progressInt = 0.0 self.__progressString = '' - self.__reporter = notification + self.__reporter = report_progress self.__stylesheet = stylesheet self.__thumbs = None self.__title = opts.catalog_title self.__verbose = opts.verbose - self.opts.log.info("CatalogBuilder(): Generating %s %s"% \ - (self.opts.fmt, - "for %s" % self.opts.output_profile if self.opts.output_profile \ - else '')) # Accessors ''' @dynamic_property @@ -755,59 +751,27 @@ class EPUB_MOBI(CatalogPlugin): # Methods def buildSources(self): - if getattr(self.reporter, 'cancel_requested', False): return 1 - if not self.booksByTitle: - self.fetchBooksByTitle() - - if getattr(self.reporter, 'cancel_requested', False): return 1 + self.fetchBooksByTitle() self.fetchBooksByAuthor() - - if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateHTMLDescriptions() - - if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateHTMLByAuthor() - - if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateHTMLByTitle() - - if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateHTMLByDateAdded() - - if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateHTMLByTags() - if getattr(self.reporter, 'cancel_requested', False): return 1 from calibre.utils.PythonMagickWand import ImageMagick with ImageMagick(): self.generateThumbnails() - if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateOPF() - - if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateNCXHeader() - - if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateNCXDescriptions("Descriptions") - - if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateNCXByAuthor("Authors") - - if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateNCXByTitle("Titles") - - if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateNCXByDateAdded("Recently Added") - - if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateNCXByGenre("Genres") - - if getattr(self.reporter, 'cancel_requested', False): return 1 self.writeNCX() - return 0 - def cleanUp(self): pass @@ -828,7 +792,7 @@ class EPUB_MOBI(CatalogPlugin): os.path.join(self.catalogPath, file[0])) def fetchBooksByTitle(self): - self.opts.log.info(self.updateProgressFullStep("fetchBooksByTitle()")) + self.updateProgressFullStep("Fetching database") # Get the database as a dictionary # Sort by title @@ -875,7 +839,7 @@ class EPUB_MOBI(CatalogPlugin): this_title['publisher'] = re.sub('&', '&', record['publisher']) this_title['rating'] = record['rating'] if record['rating'] else 0 - this_title['date'] = strftime(u'%b %Y', record['pubdate'].timetuple()) + this_title['date'] = strftime(u'%B %Y', record['pubdate'].timetuple()) this_title['timestamp'] = record['timestamp'] if record['comments']: this_title['description'] = re.sub('&', '&', record['comments']) @@ -912,7 +876,7 @@ class EPUB_MOBI(CatalogPlugin): def fetchBooksByAuthor(self): # Generate a list of titles sorted by author from the database - self.opts.log.info(self.updateProgressFullStep("fetchBooksByAuthor()")) + self.updateProgressFullStep("Sorting database by author") # Sort titles case-insensitive self.booksByAuthor = sorted(self.booksByTitle, @@ -965,14 +929,15 @@ class EPUB_MOBI(CatalogPlugin): def generateHTMLDescriptions(self): # Write each title to a separate HTML file in contentdir - self.opts.log.info(self.updateProgressFullStep("generateHTMLDescriptions()")) + self.updateProgressFullStep("Description") for (title_num, title) in enumerate(self.booksByTitle): if False: self.opts.log.info("%3s: %s - %s" % (title['id'], title['title'], title['author'])) - self.updateProgressMicroStep("generating book descriptions ...", - float(title_num*100/len(self.booksByTitle))/100) + self.updateProgressMicroStep("Description %d of %d" % \ + (title_num, len(self.booksByTitle)), + float(title_num*100/len(self.booksByTitle))/100) # Generate the header soup = self.generateHTMLDescriptionHeader("%s" % title['title']) @@ -1093,7 +1058,7 @@ class EPUB_MOBI(CatalogPlugin): def generateHTMLByTitle(self): # Write books by title A-Z to HTML file - self.opts.log.info(self.updateProgressFullStep("generateHTMLByTitle()")) + self.updateProgressFullStep("Books by Title") soup = self.generateHTMLEmptyHeader("Books By Alpha Title") body = soup.find('body') @@ -1195,7 +1160,7 @@ class EPUB_MOBI(CatalogPlugin): def generateHTMLByAuthor(self): # Write books by author A-Z - self.opts.log.info(self.updateProgressFullStep("generateHTMLByAuthor()")) + self.updateProgressFullStep("Books by Author") friendly_name = "By Author" @@ -1324,10 +1289,12 @@ class EPUB_MOBI(CatalogPlugin): self.htmlFileList.append("content/ByAlphaAuthor.html") def generateHTMLByDateAdded(self): + # Write books by reverse chronological order + self.updateProgressFullStep("Recently Added") def add_books_to_HTML(this_months_list, dtc): if len(this_months_list): - date_string = strftime(u'%b %Y', current_date.timetuple()) + date_string = strftime(u'%B %Y', current_date.timetuple()) this_months_list = sorted(this_months_list, key=lambda x:(x['title_sort'], x['title_sort'])) this_months_list = sorted(this_months_list, @@ -1338,8 +1305,7 @@ class EPUB_MOBI(CatalogPlugin): aTag = Tag(soup, "a") aTag['name'] = "%s-%s" % (current_date.year, current_date.month) pIndexTag.insert(0,aTag) - pIndexTag.insert(1,NavigableString('%s %s' % \ - (self.MONTHS[current_date.month],current_date.year))) + pIndexTag.insert(1,NavigableString(date_string)) divTag.insert(dtc,pIndexTag) dtc += 1 current_author = None @@ -1385,8 +1351,6 @@ class EPUB_MOBI(CatalogPlugin): dtc += 1 return dtc - # Write books by reverse chronological order - self.opts.log.info(self.updateProgressFullStep("generateHTMLByDateAdded()")) # Sort titles case-insensitive self.booksByDate = sorted(self.booksByTitle, @@ -1458,7 +1422,7 @@ class EPUB_MOBI(CatalogPlugin): # Generate individual HTML files for each tag, e.g. Fiction, Nonfiction ... # Note that special tags - ~+*[] - have already been filtered from books[] - self.opts.log.info(self.updateProgressFullStep("generateHTMLByTags()")) + self.updateProgressFullStep("Generating Genres") # Filter out REMOVE_TAGS, sort filtered_tags = self.filterDbTags(self.db.all_tags()) @@ -1539,7 +1503,8 @@ class EPUB_MOBI(CatalogPlugin): for (i,title) in enumerate(self.booksByTitle): # Update status - self.updateProgressMicroStep("generating thumbnails ...", + self.updateProgressMicroStep("Thumbnail %d of %d" % \ + (i,len(self.booksByTitle)), i/float(len(self.booksByTitle))) # Check to see if source file exists if 'cover' in title and os.path.isfile(title['cover']): @@ -1561,7 +1526,7 @@ class EPUB_MOBI(CatalogPlugin): self.generateThumbnail(title, image_dir, thumb_file) else: # Use default cover - if self.verbose: + if False and self.verbose: self.opts.log.warn(" using default cover for '%s'" % \ (title['title'])) # Check to make sure default is current @@ -1594,13 +1559,13 @@ class EPUB_MOBI(CatalogPlugin): cover_timestamp = os.path.getmtime(cover) thumb_timestamp = os.path.getmtime(thumb_fp) if thumb_timestamp < cover_timestamp: - if self.verbose: + if False and self.verbose: self.opts.log.warn("updating thumbnail_default for %s" % title['title']) #title['cover'] = "%s/DefaultCover.jpg" % self.catalogPath title['cover'] = cover self.generateThumbnail(title, image_dir, "thumbnail_default.jpg") else: - if self.verbose: + if False and self.verbose: self.opts.log.warn(" generating new thumbnail_default.jpg") #title['cover'] = "%s/DefaultCover.jpg" % self.catalogPath title['cover'] = cover @@ -1610,7 +1575,7 @@ class EPUB_MOBI(CatalogPlugin): def generateOPF(self): - self.opts.log.info(self.updateProgressFullStep("generateOPF()")) + self.updateProgressFullStep("Generating OPF") header = ''' @@ -1742,7 +1707,7 @@ class EPUB_MOBI(CatalogPlugin): def generateNCXHeader(self): - self.opts.log.info(self.updateProgressFullStep("generateNCXHeader()")) + self.updateProgressFullStep("NCX header") header = ''' @@ -1778,7 +1743,7 @@ class EPUB_MOBI(CatalogPlugin): def generateNCXDescriptions(self, tocTitle): - self.opts.log.info(self.updateProgressFullStep("generateNCXDescriptions()")) + self.updateProgressFullStep("NCX descriptions") # --- Construct the 'Books by Title' section --- ncx_soup = self.ncxSoup @@ -1845,7 +1810,7 @@ class EPUB_MOBI(CatalogPlugin): self.ncxSoup = ncx_soup def generateNCXByTitle(self, tocTitle): - self.opts.log.info(self.updateProgressFullStep("generateNCXByTitle()")) + self.updateProgressFullStep("NCX Titles") def add_to_books_by_letter(current_book_list): current_book_list = " • ".join(current_book_list) @@ -1934,7 +1899,7 @@ class EPUB_MOBI(CatalogPlugin): self.ncxSoup = soup def generateNCXByAuthor(self, tocTitle): - self.opts.log.info(self.updateProgressFullStep("generateNCXByAuthor()")) + self.updateProgressFullStep("NCX Authors") def add_to_author_list(current_author_list, current_letter): current_author_list = " • ".join(current_author_list) @@ -2023,7 +1988,7 @@ class EPUB_MOBI(CatalogPlugin): self.ncxSoup = soup def generateNCXByDateAdded(self, tocTitle): - self.opts.log.info(self.updateProgressFullStep("generateNCXByDateAdded()")) + self.updateProgressFullStep("NCX Recently Added") def add_to_master_month_list(current_titles_list): current_titles_list = " • ".join(current_titles_list) @@ -2081,7 +2046,7 @@ class EPUB_MOBI(CatalogPlugin): # Add *article* entries for each populated month # master_months_list{}: [0]:titles list [1]:date for books_by_month in master_month_list: - datestr = strftime(u'%b %Y', books_by_month[1].timetuple()) + datestr = strftime(u'%B %Y', books_by_month[1].timetuple()) navPointByMonthTag = Tag(soup, 'navPoint') navPointByMonthTag['class'] = "article" navPointByMonthTag['id'] = "%s-%s-ID" % (books_by_month[1].year,books_by_month[1].month ) @@ -2089,7 +2054,7 @@ class EPUB_MOBI(CatalogPlugin): self.playOrder += 1 navLabelTag = Tag(soup, 'navLabel') textTag = Tag(soup, 'text') - textTag.insert(0, NavigableString("Books added in " + datestr)) + textTag.insert(0, NavigableString(datestr)) navLabelTag.insert(0, textTag) navPointByMonthTag.insert(0,navLabelTag) contentTag = Tag(soup, 'content') @@ -2117,7 +2082,7 @@ class EPUB_MOBI(CatalogPlugin): # Add each genre as an article # 'tag', 'file', 'authors' - self.opts.log.info(self.updateProgressFullStep("generateNCXByGenre()")) + self.updateProgressFullStep("NCX by Genre") @@ -2218,7 +2183,7 @@ class EPUB_MOBI(CatalogPlugin): self.ncxSoup = ncx_soup def writeNCX(self): - self.opts.log.info(self.updateProgressFullStep("writeNCX()")) + self.updateProgressFullStep("Writing NCX") outfile = open("%s/%s.ncx" % (self.catalogPath, self.basename), 'w') outfile.write(self.ncxSoup.prettify()) @@ -2305,7 +2270,7 @@ class EPUB_MOBI(CatalogPlugin): else: continue if self.verbose: - self.opts.log.info(' %d Genre tags in database (exclude_genre: %s):' % \ + self.opts.log.info(' %d Genre tags (exclude_genre: %s):' % \ (len(filtered_tags), self.opts.exclude_genre)) self.opts.log.info(' %s' % ', '.join(filtered_tags)) @@ -2620,12 +2585,10 @@ class EPUB_MOBI(CatalogPlugin): self.opts.log.info('%s not implemented' % self.error) def updateProgressFullStep(self, description): - self.current_step += 1 self.progressString = description self.progressInt = float((self.current_step-1)/self.total_steps) - self.reporter(self.progressInt/100., self.progressString) - return u"%.2f%% %s" % (self.progressInt, self.progressString) + self.reporter(self.progressInt, self.progressString) def updateProgressMicroStep(self, description, micro_step_pct): step_range = 100/self.total_steps @@ -2633,11 +2596,9 @@ class EPUB_MOBI(CatalogPlugin): coarse_progress = float((self.current_step-1)/self.total_steps) fine_progress = float((micro_step_pct*step_range)/100) self.progressInt = coarse_progress + fine_progress - self.reporter(self.progressInt/100., self.progressString) - return u"%.2f%% %s" % (self.progressInt, self.progressString) + self.reporter(self.progressInt, self.progressString) def run(self, path_to_output, opts, db, notification=DummyReporter()): - opts.log = log = Log() opts.fmt = self.fmt = path_to_output.rpartition('.')[2] self.opts = opts @@ -2650,29 +2611,28 @@ class EPUB_MOBI(CatalogPlugin): if opts.verbose: opts_dict = vars(opts) - log("%s:run" % self.name) - log(" path_to_output: %s" % path_to_output) - log(" Output format: %s" % self.fmt) + log("%s(): Generating %s for %s" % (self.name,self.fmt,opts.output_profile)) if opts_dict['ids']: log(" Book count: %d" % len(opts_dict['ids'])) # Display opts keys = opts_dict.keys() keys.sort() log(" opts:") + for key in keys: - if key == 'ids': - if opts_dict[key]: - continue - else: - log(" %s: (all)" % key) - log(" %s: %s" % (key, opts_dict[key])) + if key in ['catalog_title','exclude_genre','exclude_tags','note_tag', + 'numbers_as_text','read_tag','search_text','sort_by']: + log(" %s: %s" % (key, opts_dict[key])) # Launch the Catalog builder - catalog = self.CatalogBuilder(db, opts, self, notification=notification) + catalog = self.CatalogBuilder(db, opts, self, report_progress=notification) catalog.createDirectoryStructure() catalog.copyResources() catalog.buildSources() + if opts.verbose: + log.info("Catalog source generation complete") + recommendations = [] dp = getattr(opts, 'debug_pipeline', None) From 28d5317c8f7df8d3fddcd529d3ce1554cacdef6e Mon Sep 17 00:00:00 2001 From: GRiker Date: Fri, 29 Jan 2010 16:21:50 -0700 Subject: [PATCH 3/3] Catalog housecleaning, progress reporting fixed, CSV cleanup --- src/calibre/customize/__init__.py | 2 +- src/calibre/library/catalog.py | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/calibre/customize/__init__.py b/src/calibre/customize/__init__.py index 68d94bf178..42b379fa0b 100644 --- a/src/calibre/customize/__init__.py +++ b/src/calibre/customize/__init__.py @@ -288,7 +288,7 @@ class CatalogPlugin(Plugin): fields = list(all_fields) fields.sort() - if opts.sort_by: + if opts.sort_by and opts.sort_by in fields: fields.insert(0,fields.pop(int(fields.index(opts.sort_by)))) return fields diff --git a/src/calibre/library/catalog.py b/src/calibre/library/catalog.py index 3826aa55ec..debe8487cc 100644 --- a/src/calibre/library/catalog.py +++ b/src/calibre/library/catalog.py @@ -51,18 +51,23 @@ class CSV_XML(CatalogPlugin): self.fmt = path_to_output.rpartition('.')[2] self.notification = notification - if False and opts.verbose: - log("%s:run" % self.name) - log(" path_to_output: %s" % path_to_output) - log(" Output format: %s" % self.fmt) - - # Display opts + if opts.verbose: opts_dict = vars(opts) - keys = opts_dict.keys() - keys.sort() - log(" opts:") - for key in keys: - log(" %s: %s" % (key, opts_dict[key])) + log("%s(): Generating %s" % (self.name,self.fmt)) + if opts_dict['search_text']: + log(" --search='%s'" % opts_dict['search_text']) + + if opts_dict['ids']: + log(" Book count: %d" % len(opts_dict['ids'])) + if opts_dict['search_text']: + log(" (--search ignored when a subset of the database is specified)") + + if opts_dict['fields']: + if opts_dict['fields'] == 'all': + log(" Fields: %s" % ', '.join(FIELDS[1:])) + else: + log(" Fields: %s" % opts_dict['fields']) + # If a list of ids are provided, don't use search_text if opts.ids: