GwR fix for options passable as lists or strings

This commit is contained in:
GRiker 2010-01-22 14:24:26 -07:00
commit e90d19775c
7 changed files with 96 additions and 47 deletions

View File

@ -122,6 +122,9 @@
- title: Editor and Publisher
author: XanthanGum
- title: The Week (free)
author: Darko Miletic
improved recipes:
- Physics Today
- Wall Street Journal

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 B

View File

@ -0,0 +1,49 @@
__license__ = 'GPL v3'
__copyright__ = '2010, Darko Miletic <darko.miletic at gmail.com>'
'''
www.theweek.com
'''
from calibre.web.feeds.news import BasicNewsRecipe
class TheWeekFree(BasicNewsRecipe):
title = 'The Week Magazine - Free content'
__author__ = 'Darko Miletic'
description = "The best of the US and international media. Daily coverage of commentary and analysis of the day's events, as well as arts, entertainment, people and gossip, and political cartoons."
publisher = 'The Week Publications, Inc.'
category = 'news, politics, USA'
oldest_article = 7
max_articles_per_feed = 100
no_stylesheets = True
encoding = 'utf-8'
use_embedded_content = False
language = 'en'
conversion_options = {
'comment' : description
, 'tags' : category
, 'publisher' : publisher
, 'language' : language
}
keep_only_tags = [
dict(name=['h1','h2'])
, dict(name='div', attrs={'class':'basefont'})
, dict(name='div', attrs={'id':'slideshowLoader'})
]
remove_tags = [
dict(name='div', attrs={'id':['digg_dugg','articleRight','dateHeader']})
,dict(name=['object','embed','iframe'])
]
feeds = [
(u'News & Opinions' , u'http://www.theweek.com/section/index/news_opinion.rss')
,(u'Arts & Leisure' , u'http://www.theweek.com/section/index/arts_leisure.rss')
,(u'Business' , u'http://www.theweek.com/section/index/business.rss' )
,(u'Cartoon & Short takes' , u'http://www.theweek.com/section/index/cartoons_wit.rss')
]

View File

@ -44,7 +44,8 @@ class PluginWidget(QWidget,Ui_Form):
for opt in self.OPTION_FIELDS:
opt_value = unicode(getattr(self, opt[0]).text())
gprefs.set(self.name + '_' + opt[0], opt_value)
opt_value = opt_value.split(',')
if opt[0] != 'exclude_genre':
opt_value = opt_value.split(',')
opts_dict[opt[0]] = opt_value
opts_dict['output_profile'] = [load_defaults('page_setup')['output_profile']]

View File

@ -49,7 +49,10 @@ def gui_catalog(fmt, title, dbspec, ids, out_file_name, fmt_options,
# Extract the option dictionary to comma-separated lists
for option in fmt_options:
setattr(opts,option, ','.join(fmt_options[option]))
if isinstance(fmt_options[option],list):
setattr(opts,option, ','.join(fmt_options[option]))
else:
setattr(opts,option, fmt_options[option])
# Fetch and run the plugin for fmt
plugin = plugin_for_catalog_format(fmt)

View File

@ -36,9 +36,6 @@ class Catalog(QDialog, Ui_Dialog):
self.title.setText(dynamic.get('catalog_last_used_title',
_('My Books')))
# GwR *** Add option tabs for built-in formats
# This code models #69 in calibre/gui2/dialogs/config/__init__.py
self.fmts, self.widgets = [], []
from calibre.customize.builtins import plugins as builtin_plugins

View File

@ -6,7 +6,7 @@ from calibre.ebooks.BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, Tag,
from calibre.customize import CatalogPlugin
from calibre.ptempfile import PersistentTemporaryDirectory
from calibre.customize.conversion import OptionRecommendation, DummyReporter
from calibre import filesystem_encoding
FIELDS = ['all', 'author_sort', 'authors', 'comments',
'cover', 'formats', 'id', 'isbn', 'pubdate', 'publisher', 'rating',
@ -663,47 +663,47 @@ class EPUB_MOBI(CatalogPlugin):
# Methods
def buildSources(self):
if self.reporter.cancel_requested: return 1
if getattr(self.reporter, 'cancel_requested', False): return 1
if not self.booksByTitle:
self.fetchBooksByTitle()
if self.reporter.cancel_requested: return 1
if getattr(self.reporter, 'cancel_requested', False): return 1
self.fetchBooksByAuthor()
if self.reporter.cancel_requested: return 1
if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateHTMLDescriptions()
if self.reporter.cancel_requested: return 1
if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateHTMLByTitle()
if self.reporter.cancel_requested: return 1
if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateHTMLByAuthor()
if self.reporter.cancel_requested: return 1
if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateHTMLByTags()
if self.reporter.cancel_requested: return 1
if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateThumbnails()
if self.reporter.cancel_requested: return 1
if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateOPF()
if self.reporter.cancel_requested: return 1
if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateNCXHeader()
if self.reporter.cancel_requested: return 1
if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateNCXDescriptions("Descriptions")
if self.reporter.cancel_requested: return 1
if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateNCXByTitle("Titles", single_article_per_section=False)
if self.reporter.cancel_requested: return 1
if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateNCXByAuthor("Authors", single_article_per_section=False)
if self.reporter.cancel_requested: return 1
if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateNCXByTags("Genres")
if self.reporter.cancel_requested: return 1
if getattr(self.reporter, 'cancel_requested', False): return 1
self.writeNCX()
return 0
@ -1350,7 +1350,7 @@ class EPUB_MOBI(CatalogPlugin):
for (i,title) in enumerate(self.booksByTitle):
# Update status
self.updateProgressMicroStep("generating thumbnails ...",
100*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']):
# print "cover found for %s" % title['title']
@ -2456,42 +2456,38 @@ class EPUB_MOBI(CatalogPlugin):
def generateThumbnail(self, title, image_dir, thumb_file):
import calibre.utils.PythonMagickWand as pw
try:
img = pw.NewMagickWand()
if img < 0:
raise RuntimeError('generate_thumbnail(): Cannot create wand')
# Read the cover
if not pw.MagickReadImage(img, title['cover']):
print 'Failed to read cover image from: %s' % title['cover']
raise IOError
thumb = pw.CloneMagickWand(img)
if thumb < 0:
print 'generate_thumbnail(): Cannot clone cover'
raise RuntimeError
# img, width, height
pw.MagickThumbnailImage(thumb, 75, 100)
pw.MagickWriteImage(thumb, os.path.join(image_dir, thumb_file))
pw.DestroyMagickWand(thumb)
except IOError:
print "generate_thumbnail() IOError with %s" % title['title']
except RuntimeError:
print "generate_thumbnail() RuntimeError with %s" % title['title']
with pw.ImageMagick():
try:
img = pw.NewMagickWand()
if img < 0:
raise RuntimeError('generate_thumbnail(): Cannot create wand')
# Read the cover
if not pw.MagickReadImage(img,
title['cover'].encode(filesystem_encoding)):
print 'Failed to read cover image from: %s' % title['cover']
raise IOError
thumb = pw.CloneMagickWand(img)
if thumb < 0:
print 'generate_thumbnail(): Cannot clone cover'
raise RuntimeError
# img, width, height
pw.MagickThumbnailImage(thumb, 75, 100)
pw.MagickWriteImage(thumb, os.path.join(image_dir, thumb_file))
pw.DestroyMagickWand(thumb)
except IOError:
print "generate_thumbnail() IOError with %s" % title['title']
except RuntimeError:
print "generate_thumbnail() RuntimeError with %s" % title['title']
def processSpecialTags(self, tags, this_title, opts):
tag_list = []
for tag in tags:
tag = self.convertHTMLEntities(tag)
if tag.startswith(opts.note_tag):
# if opts.verbose:
# print "%s has a note: %s" % (this_title['title'], tag[1:])
this_title['notes'] = tag[1:]
elif tag == opts.read_tag:
# if opts.verbose:
# print "%s marked as read" % this_title['title']
this_title['read'] = True
elif re.search(opts.exclude_genre, tag):
# if opts.verbose:
# print "'%s' matches exclude_genre regex, skipping" % tag
continue
else:
tag_list.append(tag)