From 6fba434b43bde2e6e0eb646c920f9d167c54ab2d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 31 Jul 2009 09:29:08 -0600 Subject: [PATCH 1/8] Fix #3009 (PRS500 won't connect) --- src/calibre/devices/prs500/driver.py | 1 + src/calibre/web/feeds/recipes/recipe_economist.py | 1 + 2 files changed, 2 insertions(+) diff --git a/src/calibre/devices/prs500/driver.py b/src/calibre/devices/prs500/driver.py index aba8a9d088..5c97144049 100644 --- a/src/calibre/devices/prs500/driver.py +++ b/src/calibre/devices/prs500/driver.py @@ -87,6 +87,7 @@ class PRS500(DeviceConfig, DevicePlugin): description = _('Communicate with the Sony PRS-500 eBook reader.') author = _('Kovid Goyal') supported_platforms = ['windows', 'osx', 'linux'] + log_packets = False VENDOR_ID = 0x054c #: SONY Vendor Id PRODUCT_ID = 0x029b #: Product Id for the PRS-500 diff --git a/src/calibre/web/feeds/recipes/recipe_economist.py b/src/calibre/web/feeds/recipes/recipe_economist.py index 9997c5fce9..c88554ad27 100644 --- a/src/calibre/web/feeds/recipes/recipe_economist.py +++ b/src/calibre/web/feeds/recipes/recipe_economist.py @@ -20,6 +20,7 @@ class Economist(BasicNewsRecipe): oldest_article = 7.0 needs_subscription = False # Strange but true INDEX = 'http://www.economist.com/printedition' + cover_url = 'http://www.economist.com/images/covers/currentcovereu_large.jpg' remove_tags = [dict(name=['script', 'noscript', 'title'])] remove_tags_before = dict(name=lambda tag: tag.name=='title' and tag.parent.name=='body') From 35bc41bbbcc6f26a6b57db4b000df4d091fe127b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 31 Jul 2009 09:43:10 -0600 Subject: [PATCH 2/8] Fix #3010 (Special characters in tags are not escaped) --- src/calibre/library/server.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/calibre/library/server.py b/src/calibre/library/server.py index d0ea9e962e..b1521d8aef 100644 --- a/src/calibre/library/server.py +++ b/src/calibre/library/server.py @@ -23,7 +23,7 @@ except ImportError: from calibre.constants import __version__, __appname__ from calibre.utils.genshi.template import MarkupTemplate -from calibre import fit_image, guess_type +from calibre import fit_image, guess_type, prepare_string_for_xml from calibre.resources import jquery, server_resources, build_time from calibre.library import server_config as config from calibre.library.database2 import LibraryDatabase2, FIELD_MAP @@ -302,11 +302,13 @@ class LibraryServer(object): extra.append('RATING: %s
'%rating) tags = record[FIELD_MAP['tags']] if tags: - extra.append('TAGS: %s
'%', '.join(tags.split(','))) + extra.append('TAGS: %s
'%\ + prepare_string_for_xml(', '.join(tags.split(',')))) series = record[FIELD_MAP['series']] if series: - extra.append('SERIES: %s [%s]
'%(series, - fmt_sidx(float(record[FIELD_MAP['series_index']])))) + extra.append('SERIES: %s [%s]
'%\ + (prepare_string_for_xml(series), + fmt_sidx(float(record[FIELD_MAP['series_index']])))) fmt = 'epub' if 'EPUB' in r else 'pdb' mimetype = guess_type('dummy.'+fmt)[0] books.append(self.STANZA_ENTRY.generate( From efe4adfe48da5c3ae9b193cc591737f872b53640 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 31 Jul 2009 10:35:40 -0600 Subject: [PATCH 3/8] Implement searching the calibre catalog in the Stanza. Fixes #3014 (Support searching from stanza) --- src/calibre/library/server.py | 7 +++++-- src/calibre/web/feeds/recipes/__init__.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/calibre/library/server.py b/src/calibre/library/server.py index b1521d8aef..c935b9a0a0 100644 --- a/src/calibre/library/server.py +++ b/src/calibre/library/server.py @@ -100,6 +100,7 @@ class LibraryServer(object): calibre Library $id ${updated.strftime('%Y-%m-%dT%H:%M:%S+00:00')} + calibre http://calibre.kovidgoyal.net @@ -283,10 +284,12 @@ class LibraryServer(object): @expose - def stanza(self): + def stanza(self, search=None): 'Feeds to read calibre books on a ipod with stanza.' books = [] + ids = self.db.data.parse(search) if search and search.strip() else self.db.data.universal_set() for record in iter(self.db): + if record[0] not in ids: continue r = record[FIELD_MAP['formats']] r = r.upper() if r else '' if 'EPUB' in r or 'PDB' in r: @@ -371,7 +374,7 @@ class LibraryServer(object): 'The / URL' want_opds = cherrypy.request.headers.get('Stanza-Device-Name', 919) != \ 919 or cherrypy.request.headers.get('Want-OPDS-Catalog', 919) != 919 - return self.stanza() if want_opds else self.static('index.html') + return self.stanza(search=kwargs.get('search', None)) if want_opds else self.static('index.html') @expose diff --git a/src/calibre/web/feeds/recipes/__init__.py b/src/calibre/web/feeds/recipes/__init__.py index acb1d967b0..c27e51583f 100644 --- a/src/calibre/web/feeds/recipes/__init__.py +++ b/src/calibre/web/feeds/recipes/__init__.py @@ -48,7 +48,7 @@ recipe_modules = ['recipe_' + r for r in ( 'the_budget_fashionista', 'elperiodico_catalan', 'elperiodico_spanish', 'expansion_spanish', 'lavanguardia', 'marca', 'kellog_faculty', 'kellog_insight', 'noaa', - 'theeconomictimes_india', '7dias', 'buenosaireseconomico', + '7dias', 'buenosaireseconomico', 'diagonales', 'miradasalsur', 'newsweek_argentina', 'veintitres', 'gva_be', 'hln', 'tijd', 'degentenaar', 'inquirer_net', 'uncrate', 'fastcompany', 'accountancyage', 'laprensa_hn', 'latribuna', From bb83f91018e035b0ac56586ecbce3c61fab92a09 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 31 Jul 2009 12:08:20 -0600 Subject: [PATCH 4/8] Handle author names that end with a period correctly when saving a single format to disk --- src/calibre/library/database2.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index d477389875..6e04f835b9 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -1678,8 +1678,11 @@ books_series_link feeds au = self.authors(id, index_is_id=True) if not au: au = _('Unknown') - fname = '%s - %s.%s'%(title, au, format.lower()) + fname = '%s - %s'%(title, au) + while fname.endswith('.'): + fname = fname[:-1] fname = ascii_filename(fname) + fname = fname + '.' + format.lower() dir = os.path.abspath(dir) fname = shorten_components_to(plen - len(dir), (fname,))[0] if not os.path.exists(dir): From b166016da52930b0d98c7bfb27832d3d8004c5f8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 31 Jul 2009 12:22:26 -0600 Subject: [PATCH 5/8] Fix #3016 (lxml.etree._Element' object has no attribute 'href) --- src/calibre/ebooks/oeb/stylizer.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/calibre/ebooks/oeb/stylizer.py b/src/calibre/ebooks/oeb/stylizer.py index 9a52709ca4..da68dc2f69 100644 --- a/src/calibre/ebooks/oeb/stylizer.py +++ b/src/calibre/ebooks/oeb/stylizer.py @@ -137,6 +137,11 @@ class Stylizer(object): 'Stylesheet %r referenced by file %r not in manifest' % (path, item.href)) continue + if not hasattr(sitem.data, 'cssRules'): + self.logger.warn( + 'Stylesheet %r referenced by file %r is not CSS'%(path, + item.href)) + continue stylesheets.append(sitem.data) for x in (extra_css, user_css): if x: From 2e8a3a28d9f2ce317af6cefe65723cf2d0d3b5e1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 31 Jul 2009 13:12:29 -0600 Subject: [PATCH 6/8] Fix #3019 (Problem converting prc to epub) --- src/calibre/devices/cybookg3/driver.py | 4 ++-- src/calibre/ebooks/oeb/stylizer.py | 1 + src/calibre/ebooks/oeb/transforms/flatcss.py | 5 ++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/calibre/devices/cybookg3/driver.py b/src/calibre/devices/cybookg3/driver.py index a8ce905b00..d3ccf85461 100644 --- a/src/calibre/devices/cybookg3/driver.py +++ b/src/calibre/devices/cybookg3/driver.py @@ -13,7 +13,7 @@ from calibre.devices.usbms.driver import USBMS import calibre.devices.cybookg3.t2b as t2b class CYBOOKG3(USBMS): - name = 'Cybook Gen 3 Device Interface' + name = 'Cybook Gen 3/Opus Device Interface' description = _('Communicate with the Cybook eBook reader.') author = _('John Schember') supported_platforms = ['windows', 'osx', 'linux'] @@ -31,7 +31,7 @@ class CYBOOKG3(USBMS): WINDOWS_MAIN_MEM = 'CYBOOK_GEN3__-FD' WINDOWS_CARD_A_MEM = 'CYBOOK_GEN3__-SD' - OSX_MAIN_MEM = 'Bookeen Cybook Gen3 -FD Media' + OSX_MAIN_MEM = ['Bookeen Cybook Gen3 -FD Media', 'Bookeen Cybook Opus -FD Media'] OSX_CARD_A_MEM = 'Bookeen Cybook Gen3 -SD Media' MAIN_MEMORY_VOLUME_LABEL = 'Cybook Gen 3 Main Memory' diff --git a/src/calibre/ebooks/oeb/stylizer.py b/src/calibre/ebooks/oeb/stylizer.py index da68dc2f69..1d3b0515d4 100644 --- a/src/calibre/ebooks/oeb/stylizer.py +++ b/src/calibre/ebooks/oeb/stylizer.py @@ -225,6 +225,7 @@ class Stylizer(object): if 'font-size' in style: size = style['font-size'] if size == 'normal': size = 'medium' + if size == 'smallest': size = 'xx-small' if size in FONT_SIZE_NAMES: style['font-size'] = "%dpt" % self.profile.fnames[size] return style diff --git a/src/calibre/ebooks/oeb/transforms/flatcss.py b/src/calibre/ebooks/oeb/transforms/flatcss.py index 7114c9736f..8ef5c42ea1 100644 --- a/src/calibre/ebooks/oeb/transforms/flatcss.py +++ b/src/calibre/ebooks/oeb/transforms/flatcss.py @@ -213,7 +213,10 @@ class CSSFlattener(object): esize = 7 cssdict['font-size'] = fnums[esize] else: - cssdict['font-size'] = fnums[force_int(size)] + try: + cssdict['font-size'] = fnums[force_int(size)] + except: + cssdict['font-size'] = fnums[3] del node.attrib['size'] if 'color' in node.attrib: cssdict['color'] = node.attrib['color'] From 923cf3522c001539bcf33b47d84efe093a8e7db5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 31 Jul 2009 14:17:47 -0600 Subject: [PATCH 7/8] EPUB Output: Remove hyperlinks with no content as they cause rendering artifacts in browser based renderers --- src/calibre/ebooks/epub/output.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/calibre/ebooks/epub/output.py b/src/calibre/ebooks/epub/output.py index 18009a9a9f..d8bab20b1c 100644 --- a/src/calibre/ebooks/epub/output.py +++ b/src/calibre/ebooks/epub/output.py @@ -148,6 +148,20 @@ class EPUBOutput(OutputFormatPlugin): if not pre.text and len(pre) == 0: pre.tag = 'div' + # Remove hyperlinks with no content as they cause rendering + # artifacts in browser based renderers + for a in body.xpath('//a[@href]'): + if a.get('id', None) is None and a.get('name', None) is None \ + and len(a) == 0 and not a.text: + p = a.getparent() + idx = p.index(a) -1 + p.remove(a) + if a.tail: + if idx <= 0: + p.text += a.tail + else: + p[idx].tail += a.tail + def convert(self, oeb, output_path, input_plugin, opts, log): self.log, self.opts, self.oeb = log, opts, oeb From b7872873dd10cbf1085bca78556b27dbba0c9378 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 31 Jul 2009 15:57:13 -0600 Subject: [PATCH 8/8] Fix #3022 (Receiving error during convert from pdf to any file) --- src/calibre/__init__.py | 8 +++++--- src/calibre/ebooks/mobi/writer.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/calibre/__init__.py b/src/calibre/__init__.py index b455c55553..5cdf03888a 100644 --- a/src/calibre/__init__.py +++ b/src/calibre/__init__.py @@ -114,9 +114,11 @@ def prints(*args, **kwargs): raise arg = repr(arg) if not isinstance(arg, str): - arg = str(arg) - if not isinstance(arg, unicode): - arg = arg.decode(preferred_encoding, 'replace') + try: + arg = str(arg) + except ValueError: + arg = unicode(arg) + if isinstance(arg, unicode): try: arg = arg.encode(enc) except UnicodeEncodeError: diff --git a/src/calibre/ebooks/mobi/writer.py b/src/calibre/ebooks/mobi/writer.py index 0a305dbe1c..d1b4076cd9 100644 --- a/src/calibre/ebooks/mobi/writer.py +++ b/src/calibre/ebooks/mobi/writer.py @@ -1972,7 +1972,7 @@ class MobiWriter(object): continue if h not in self._id_offsets: self._oeb.logger.warn(' Ignoring missing TOC entry:', - child) + unicode(child)) continue currentOffset = self._id_offsets[h]