mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-09 03:45:22 +02:00
Merge from trunk
This commit is contained in:
commit
a2e959c7c9
4 changed files with 463 additions and 394 deletions
|
|
@ -11,6 +11,14 @@
|
|||
class InvalidEpub(ValueError):
|
||||
pass
|
||||
|
||||
class ParseError(ValueError):
|
||||
|
||||
def __init__(self, name, desc):
|
||||
self.name = name
|
||||
self.desc = desc
|
||||
ValueError.__init__(self,
|
||||
_('Failed to parse: %s with error: %s')%(name, desc))
|
||||
|
||||
class ePubFixer(Plugin):
|
||||
|
||||
supported_platforms = ['windows', 'osx', 'linux']
|
||||
|
|
|
|||
|
|
@ -8,8 +8,9 @@
|
|||
import os, posixpath, urllib, sys, re
|
||||
|
||||
from lxml import etree
|
||||
from lxml.etree import XMLSyntaxError
|
||||
|
||||
from calibre.ebooks.epub.fix import InvalidEpub
|
||||
from calibre.ebooks.epub.fix import InvalidEpub, ParseError
|
||||
from calibre import guess_type, prepare_string_for_xml
|
||||
from calibre.ebooks.chardet import xml_to_unicode
|
||||
from calibre.constants import iswindows
|
||||
|
|
@ -148,7 +149,10 @@ def get(self, name):
|
|||
return self.cache[name]
|
||||
raw = self.get_raw(name)
|
||||
if name in self.mime_map:
|
||||
raw = self._parse(raw, self.mime_map[name])
|
||||
try:
|
||||
raw = self._parse(raw, self.mime_map[name])
|
||||
except XMLSyntaxError, err:
|
||||
raise ParseError(name, unicode(err))
|
||||
self.cache[name] = raw
|
||||
return raw
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@
|
|||
from calibre.utils.logging import default_log
|
||||
from calibre.customize.ui import epub_fixers
|
||||
from calibre.ebooks.epub.fix.container import Container
|
||||
from calibre.ebooks.epub.fix import ParseError
|
||||
|
||||
|
||||
def option_parser():
|
||||
parser = OptionParser(usage=_(
|
||||
|
|
@ -50,7 +52,11 @@ def main(args=sys.argv):
|
|||
default_log.error(_('You must specify an epub file'))
|
||||
return
|
||||
epub = os.path.abspath(args[1])
|
||||
run(epub, opts, default_log)
|
||||
try:
|
||||
run(epub, opts, default_log)
|
||||
except ParseError, err:
|
||||
default_log.error(unicode(err))
|
||||
raise SystemExit(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue