From f53a5d33ec2aeab2a33b63327b42491d19c91fea Mon Sep 17 00:00:00 2001 From: Li Fanxi Date: Tue, 30 Nov 2010 22:02:48 +0800 Subject: [PATCH] [Enhancement] Skip non-existing files to avoid error. This is for better error handling. --- src/calibre/ebooks/snb/input.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/calibre/ebooks/snb/input.py b/src/calibre/ebooks/snb/input.py index 8343d44301..659ca79619 100755 --- a/src/calibre/ebooks/snb/input.py +++ b/src/calibre/ebooks/snb/input.py @@ -74,17 +74,18 @@ class SNBInput(InputFormatPlugin): chapterSrc = ch.get('src') fname = 'ch_%d.htm' % i data = snbFile.GetFileStream('snbc/' + chapterSrc) - if data != None: - snbc = etree.fromstring(data) - outputFile = open(os.path.join(tdir, fname), 'wb') - lines = [] - for line in snbc.find('.//body'): - if line.tag == 'text': - lines.append(u'

%s

' % html_encode(line.text)) - elif line.tag == 'img': - lines.append(u'

' % html_encode(line.text)) - outputFile.write((HTML_TEMPLATE % (chapterName, u'\n'.join(lines))).encode('utf-8', 'replace')) - outputFile.close() + if data == None: + continue + snbc = etree.fromstring(data) + outputFile = open(os.path.join(tdir, fname), 'wb') + lines = [] + for line in snbc.find('.//body'): + if line.tag == 'text': + lines.append(u'

%s

' % html_encode(line.text)) + elif line.tag == 'img': + lines.append(u'

' % html_encode(line.text)) + outputFile.write((HTML_TEMPLATE % (chapterName, u'\n'.join(lines))).encode('utf-8', 'replace')) + outputFile.close() oeb.toc.add(ch.text, fname) id, href = oeb.manifest.generate(id='html', href=ascii_filename(fname))