Sync to trunk.

This commit is contained in:
John Schember 2009-07-31 18:42:12 -04:00
commit d96356f717
12 changed files with 50 additions and 21 deletions

View File

@ -114,9 +114,11 @@ def prints(*args, **kwargs):
raise raise
arg = repr(arg) arg = repr(arg)
if not isinstance(arg, str): if not isinstance(arg, str):
arg = str(arg) try:
if not isinstance(arg, unicode): arg = str(arg)
arg = arg.decode(preferred_encoding, 'replace') except ValueError:
arg = unicode(arg)
if isinstance(arg, unicode):
try: try:
arg = arg.encode(enc) arg = arg.encode(enc)
except UnicodeEncodeError: except UnicodeEncodeError:

View File

@ -13,7 +13,7 @@ from calibre.devices.usbms.driver import USBMS
import calibre.devices.cybookg3.t2b as t2b import calibre.devices.cybookg3.t2b as t2b
class CYBOOKG3(USBMS): class CYBOOKG3(USBMS):
name = 'Cybook Gen 3 Device Interface' name = 'Cybook Gen 3/Opus Device Interface'
description = _('Communicate with the Cybook eBook reader.') description = _('Communicate with the Cybook eBook reader.')
author = _('John Schember') author = _('John Schember')
supported_platforms = ['windows', 'osx', 'linux'] supported_platforms = ['windows', 'osx', 'linux']
@ -31,7 +31,7 @@ class CYBOOKG3(USBMS):
WINDOWS_MAIN_MEM = 'CYBOOK_GEN3__-FD' WINDOWS_MAIN_MEM = 'CYBOOK_GEN3__-FD'
WINDOWS_CARD_A_MEM = 'CYBOOK_GEN3__-SD' 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' OSX_CARD_A_MEM = 'Bookeen Cybook Gen3 -SD Media'
MAIN_MEMORY_VOLUME_LABEL = 'Cybook Gen 3 Main Memory' MAIN_MEMORY_VOLUME_LABEL = 'Cybook Gen 3 Main Memory'

View File

@ -87,6 +87,7 @@ class PRS500(DeviceConfig, DevicePlugin):
description = _('Communicate with the Sony PRS-500 eBook reader.') description = _('Communicate with the Sony PRS-500 eBook reader.')
author = _('Kovid Goyal') author = _('Kovid Goyal')
supported_platforms = ['windows', 'osx', 'linux'] supported_platforms = ['windows', 'osx', 'linux']
log_packets = False
VENDOR_ID = 0x054c #: SONY Vendor Id VENDOR_ID = 0x054c #: SONY Vendor Id
PRODUCT_ID = 0x029b #: Product Id for the PRS-500 PRODUCT_ID = 0x029b #: Product Id for the PRS-500

View File

@ -148,6 +148,20 @@ class EPUBOutput(OutputFormatPlugin):
if not pre.text and len(pre) == 0: if not pre.text and len(pre) == 0:
pre.tag = 'div' 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): def convert(self, oeb, output_path, input_plugin, opts, log):
self.log, self.opts, self.oeb = log, opts, oeb self.log, self.opts, self.oeb = log, opts, oeb

View File

@ -1972,7 +1972,7 @@ class MobiWriter(object):
continue continue
if h not in self._id_offsets: if h not in self._id_offsets:
self._oeb.logger.warn(' Ignoring missing TOC entry:', self._oeb.logger.warn(' Ignoring missing TOC entry:',
child) unicode(child))
continue continue
currentOffset = self._id_offsets[h] currentOffset = self._id_offsets[h]

View File

@ -904,12 +904,6 @@ class Manifest(object):
if key == 'lang' or key.endswith('}lang'): if key == 'lang' or key.endswith('}lang'):
body.attrib.pop(key) body.attrib.pop(key)
# Remove invalid links as they casue overflow until the next link
# in rendering.
data = etree.tostring(data)
data = re.sub('<a[^/]*?/>', '', data)
data = etree.fromstring(data)
return data return data
def _parse_txt(self, data): def _parse_txt(self, data):

View File

@ -137,6 +137,11 @@ class Stylizer(object):
'Stylesheet %r referenced by file %r not in manifest' % 'Stylesheet %r referenced by file %r not in manifest' %
(path, item.href)) (path, item.href))
continue 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) stylesheets.append(sitem.data)
for x in (extra_css, user_css): for x in (extra_css, user_css):
if x: if x:
@ -220,6 +225,7 @@ class Stylizer(object):
if 'font-size' in style: if 'font-size' in style:
size = style['font-size'] size = style['font-size']
if size == 'normal': size = 'medium' if size == 'normal': size = 'medium'
if size == 'smallest': size = 'xx-small'
if size in FONT_SIZE_NAMES: if size in FONT_SIZE_NAMES:
style['font-size'] = "%dpt" % self.profile.fnames[size] style['font-size'] = "%dpt" % self.profile.fnames[size]
return style return style

View File

@ -213,7 +213,10 @@ class CSSFlattener(object):
esize = 7 esize = 7
cssdict['font-size'] = fnums[esize] cssdict['font-size'] = fnums[esize]
else: 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'] del node.attrib['size']
if 'color' in node.attrib: if 'color' in node.attrib:
cssdict['color'] = node.attrib['color'] cssdict['color'] = node.attrib['color']

View File

@ -1678,8 +1678,11 @@ books_series_link feeds
au = self.authors(id, index_is_id=True) au = self.authors(id, index_is_id=True)
if not au: if not au:
au = _('Unknown') 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 = ascii_filename(fname)
fname = fname + '.' + format.lower()
dir = os.path.abspath(dir) dir = os.path.abspath(dir)
fname = shorten_components_to(plen - len(dir), (fname,))[0] fname = shorten_components_to(plen - len(dir), (fname,))[0]
if not os.path.exists(dir): if not os.path.exists(dir):

View File

@ -23,7 +23,7 @@ except ImportError:
from calibre.constants import __version__, __appname__ from calibre.constants import __version__, __appname__
from calibre.utils.genshi.template import MarkupTemplate 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.resources import jquery, server_resources, build_time
from calibre.library import server_config as config from calibre.library import server_config as config
from calibre.library.database2 import LibraryDatabase2, FIELD_MAP from calibre.library.database2 import LibraryDatabase2, FIELD_MAP
@ -100,6 +100,7 @@ class LibraryServer(object):
<title>calibre Library</title> <title>calibre Library</title>
<id>$id</id> <id>$id</id>
<updated>${updated.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</updated> <updated>${updated.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</updated>
<link rel="search" title="Search" type="application/atom+xml" href="/?search={searchTerms}"/>
<author> <author>
<name>calibre</name> <name>calibre</name>
<uri>http://calibre.kovidgoyal.net</uri> <uri>http://calibre.kovidgoyal.net</uri>
@ -283,10 +284,12 @@ class LibraryServer(object):
@expose @expose
def stanza(self): def stanza(self, search=None):
'Feeds to read calibre books on a ipod with stanza.' 'Feeds to read calibre books on a ipod with stanza.'
books = [] books = []
ids = self.db.data.parse(search) if search and search.strip() else self.db.data.universal_set()
for record in iter(self.db): for record in iter(self.db):
if record[0] not in ids: continue
r = record[FIELD_MAP['formats']] r = record[FIELD_MAP['formats']]
r = r.upper() if r else '' r = r.upper() if r else ''
if 'EPUB' in r or 'PDB' in r: if 'EPUB' in r or 'PDB' in r:
@ -302,11 +305,13 @@ class LibraryServer(object):
extra.append('RATING: %s<br />'%rating) extra.append('RATING: %s<br />'%rating)
tags = record[FIELD_MAP['tags']] tags = record[FIELD_MAP['tags']]
if tags: if tags:
extra.append('TAGS: %s<br />'%', '.join(tags.split(','))) extra.append('TAGS: %s<br />'%\
prepare_string_for_xml(', '.join(tags.split(','))))
series = record[FIELD_MAP['series']] series = record[FIELD_MAP['series']]
if series: if series:
extra.append('SERIES: %s [%s]<br />'%(series, extra.append('SERIES: %s [%s]<br />'%\
fmt_sidx(float(record[FIELD_MAP['series_index']])))) (prepare_string_for_xml(series),
fmt_sidx(float(record[FIELD_MAP['series_index']]))))
fmt = 'epub' if 'EPUB' in r else 'pdb' fmt = 'epub' if 'EPUB' in r else 'pdb'
mimetype = guess_type('dummy.'+fmt)[0] mimetype = guess_type('dummy.'+fmt)[0]
books.append(self.STANZA_ENTRY.generate( books.append(self.STANZA_ENTRY.generate(
@ -369,7 +374,7 @@ class LibraryServer(object):
'The / URL' 'The / URL'
want_opds = cherrypy.request.headers.get('Stanza-Device-Name', 919) != \ want_opds = cherrypy.request.headers.get('Stanza-Device-Name', 919) != \
919 or cherrypy.request.headers.get('Want-OPDS-Catalog', 919) != 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 @expose

View File

@ -48,7 +48,7 @@ recipe_modules = ['recipe_' + r for r in (
'the_budget_fashionista', 'elperiodico_catalan', 'the_budget_fashionista', 'elperiodico_catalan',
'elperiodico_spanish', 'expansion_spanish', 'lavanguardia', 'elperiodico_spanish', 'expansion_spanish', 'lavanguardia',
'marca', 'kellog_faculty', 'kellog_insight', 'noaa', 'marca', 'kellog_faculty', 'kellog_insight', 'noaa',
'theeconomictimes_india', '7dias', 'buenosaireseconomico', '7dias', 'buenosaireseconomico',
'diagonales', 'miradasalsur', 'newsweek_argentina', 'veintitres', 'diagonales', 'miradasalsur', 'newsweek_argentina', 'veintitres',
'gva_be', 'hln', 'tijd', 'degentenaar', 'inquirer_net', 'uncrate', 'gva_be', 'hln', 'tijd', 'degentenaar', 'inquirer_net', 'uncrate',
'fastcompany', 'accountancyage', 'laprensa_hn', 'latribuna', 'fastcompany', 'accountancyage', 'laprensa_hn', 'latribuna',

View File

@ -20,6 +20,7 @@ class Economist(BasicNewsRecipe):
oldest_article = 7.0 oldest_article = 7.0
needs_subscription = False # Strange but true needs_subscription = False # Strange but true
INDEX = 'http://www.economist.com/printedition' 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 = [dict(name=['script', 'noscript', 'title'])]
remove_tags_before = dict(name=lambda tag: tag.name=='title' and tag.parent.name=='body') remove_tags_before = dict(name=lambda tag: tag.name=='title' and tag.parent.name=='body')