mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-02-09 10:25:45 +01:00
Re added (probably) right formating codes.
This commit is contained in:
@@ -285,7 +285,7 @@ def create_option_parser(args, log):
|
||||
log.info('Available recipes:')
|
||||
titles = sorted(get_builtin_recipe_titles())
|
||||
for title in titles:
|
||||
log.info('\t%s', title)
|
||||
log.info('\t%r', title)
|
||||
log.info('%d recipes available', len(titles))
|
||||
raise SystemExit(0)
|
||||
|
||||
|
||||
@@ -1108,7 +1108,7 @@ OptionRecommendation(name='search_replace',
|
||||
try:
|
||||
fkey = list(map(float, fkey.split(',')))
|
||||
except Exception:
|
||||
self.log.error('Invalid font size key: %s ignoring', fkey)
|
||||
self.log.error('Invalid font size key: %r ignoring', fkey)
|
||||
fkey = self.opts.dest.fkey
|
||||
|
||||
if self.opts.debug_pipeline is not None:
|
||||
|
||||
@@ -957,11 +957,11 @@ class Manifest(object):
|
||||
def _fetch_css(self, path):
|
||||
hrefs = self.oeb.manifest.hrefs
|
||||
if path not in hrefs:
|
||||
self.oeb.logger.warning('CSS import of missing file %s', path)
|
||||
self.oeb.logger.warning('CSS import of missing file %r', path)
|
||||
return (None, None)
|
||||
item = hrefs[path]
|
||||
if item.media_type not in OEB_STYLES:
|
||||
self.oeb.logger.warning('CSS import of non-CSS file %s', path)
|
||||
self.oeb.logger.warning('CSS import of non-CSS file %r', path)
|
||||
return (None, None)
|
||||
data = item.data.cssText
|
||||
enc = None if isinstance(data, str) else 'utf-8'
|
||||
|
||||
@@ -239,7 +239,7 @@ def parse_html(data, log=None, decoder=None, preprocessor=None,
|
||||
if barename(data.tag) != 'html':
|
||||
if barename(data.tag) in non_html_file_tags:
|
||||
raise NotHTML(data.tag)
|
||||
log.warning('File %s does not appear to be (X)HTML', filename)
|
||||
log.warning('File %r does not appear to be (X)HTML', filename)
|
||||
nroot = etree.fromstring('<html></html>')
|
||||
has_body = False
|
||||
for child in list(data):
|
||||
@@ -248,7 +248,7 @@ def parse_html(data, log=None, decoder=None, preprocessor=None,
|
||||
break
|
||||
parent = nroot
|
||||
if not has_body:
|
||||
log.warning('File %s appears to be a HTML fragment', filename)
|
||||
log.warning('File %r appears to be a HTML fragment', filename)
|
||||
nroot = etree.fromstring('<html><body/></html>')
|
||||
parent = nroot[0]
|
||||
for child in list(data.iter()):
|
||||
|
||||
@@ -216,7 +216,7 @@ class OEBReader(object):
|
||||
scheme = urllib.parse.urlparse(href).scheme
|
||||
except Exception:
|
||||
self.oeb.log.exception('Skipping invalid href: '
|
||||
'%s', href)
|
||||
'%r', href)
|
||||
continue
|
||||
if not scheme and href not in known:
|
||||
new.add(href)
|
||||
@@ -244,12 +244,12 @@ class OEBReader(object):
|
||||
continue
|
||||
if not self.oeb.container.exists(href):
|
||||
if href not in warned:
|
||||
self.logger.warning('Referenced file %s not found',
|
||||
self.logger.warning('Referenced file %r not found',
|
||||
href)
|
||||
warned.add(href)
|
||||
continue
|
||||
if href not in warned:
|
||||
self.logger.warning('Referenced file %s not in manifest',
|
||||
self.logger.warning('Referenced file %r not in manifest',
|
||||
href)
|
||||
warned.add(href)
|
||||
id, _ = manifest.generate(id='added')
|
||||
@@ -276,13 +276,13 @@ class OEBReader(object):
|
||||
media_type = media_type.lower()
|
||||
fallback = elem.get('fallback')
|
||||
if href in manifest.hrefs:
|
||||
self.logger.warning('Duplicate manifest entry for %s', href)
|
||||
self.logger.warning('Duplicate manifest entry for %r', href)
|
||||
continue
|
||||
if not self.oeb.container.exists(href):
|
||||
self.logger.warning('Manifest item %s not found', href)
|
||||
self.logger.warning('Manifest item %r not found', href)
|
||||
continue
|
||||
if id in manifest.ids:
|
||||
self.logger.warning('Duplicate manifest id %s', id)
|
||||
self.logger.warning('Duplicate manifest id %r', id)
|
||||
id, href = manifest.generate(id, href)
|
||||
manifest.add(id, href, media_type, fallback)
|
||||
invalid = self._manifest_prune_invalid()
|
||||
@@ -324,7 +324,7 @@ class OEBReader(object):
|
||||
if item.href in removed_items_to_ignore:
|
||||
continue
|
||||
if version >= 2:
|
||||
self.logger.warning('Spine-referenced file %s not in spine',
|
||||
self.logger.warning('Spine-referenced file %r not in spine',
|
||||
item.href)
|
||||
spine.add(item, linear=False)
|
||||
|
||||
@@ -334,7 +334,7 @@ class OEBReader(object):
|
||||
for elem in base.xpath(opf, '/o2:package/o2:spine/o2:itemref'):
|
||||
idref = elem.get('idref')
|
||||
if idref not in manifest.ids:
|
||||
self.logger.warning('Spine item %s not found', idref)
|
||||
self.logger.warning('Spine item %r not found', idref)
|
||||
continue
|
||||
item = manifest.ids[idref]
|
||||
if (item.media_type.lower() in base.OEB_DOCS and
|
||||
@@ -370,7 +370,7 @@ class OEBReader(object):
|
||||
corrected_href = href
|
||||
break
|
||||
if corrected_href is None:
|
||||
self.logger.warning('Guide reference %s not found',
|
||||
self.logger.warning('Guide reference %r not found',
|
||||
ref_href)
|
||||
continue
|
||||
ref_href = corrected_href
|
||||
@@ -413,7 +413,7 @@ class OEBReader(object):
|
||||
if path and path not in self.oeb.manifest.hrefs:
|
||||
path = base.urlnormalize(path)
|
||||
if href and path not in self.oeb.manifest.hrefs:
|
||||
self.logger.warning('TOC reference %s not found', href)
|
||||
self.logger.warning('TOC reference %r not found', href)
|
||||
gc = base.xpath(child, 'ncx:navPoint')
|
||||
if not gc:
|
||||
# This node is useless
|
||||
@@ -490,7 +490,7 @@ class OEBReader(object):
|
||||
continue
|
||||
path, _ = urllib.parse.urldefrag(base.urlnormalize(href))
|
||||
if path not in self.oeb.manifest.hrefs:
|
||||
self.logger.warning('TOC reference %s not found', href)
|
||||
self.logger.warning('TOC reference %r not found', href)
|
||||
continue
|
||||
id = site.get('id')
|
||||
toc.add(title, href, id=id)
|
||||
@@ -658,7 +658,7 @@ class OEBReader(object):
|
||||
if item is not None and item.media_type in base.OEB_IMAGES:
|
||||
return item
|
||||
else:
|
||||
self.logger.warning('Invalid cover image @id %s', id)
|
||||
self.logger.warning('Invalid cover image @id %r', id)
|
||||
hcover = self.oeb.spine[0]
|
||||
if 'cover' in self.oeb.guide:
|
||||
href = self.oeb.guide['cover'].href
|
||||
|
||||
@@ -248,7 +248,7 @@ class Stylizer(object):
|
||||
sitem = hrefs[ihref]
|
||||
if sitem.media_type not in base.OEB_STYLES:
|
||||
self.logger.warning('CSS @import of non-CSS '
|
||||
'file %s', rule.href)
|
||||
'file %r', rule.href)
|
||||
continue
|
||||
stylesheets.append(sitem.data)
|
||||
# Make links to resources absolute, since these rules will
|
||||
@@ -264,11 +264,11 @@ class Stylizer(object):
|
||||
path = item.abshref(href)
|
||||
sitem = oeb.manifest.hrefs.get(path, None)
|
||||
if sitem is None:
|
||||
self.logger.warning('Stylesheet %s referenced by file %s '
|
||||
self.logger.warning('Stylesheet %r referenced by file %r '
|
||||
'not in manifest', path, item.href)
|
||||
continue
|
||||
if not hasattr(sitem.data, 'cssRules'):
|
||||
self.logger.warning('Stylesheet %s referenced by file %s '
|
||||
self.logger.warning('Stylesheet %r referenced by file %r '
|
||||
'is not CSS', path, item.href)
|
||||
continue
|
||||
stylesheets.append(sitem.data)
|
||||
@@ -304,7 +304,7 @@ class Stylizer(object):
|
||||
matches = tuple(select(text))
|
||||
except SelectorError as err:
|
||||
self.logger.error('Ignoring CSS rule with invalid selector: '
|
||||
'%s (%s)', text, err)
|
||||
'%r (%s)', text, err)
|
||||
continue
|
||||
|
||||
if fl is not None:
|
||||
@@ -368,7 +368,7 @@ class Stylizer(object):
|
||||
def _fetch_css_file(self, path):
|
||||
hrefs = self.oeb.manifest.hrefs
|
||||
if path not in hrefs:
|
||||
self.logger.warning('CSS import of missing file %s', path)
|
||||
self.logger.warning('CSS import of missing file %r', path)
|
||||
return (None, None)
|
||||
item = hrefs[path]
|
||||
if item.media_type not in base.OEB_STYLES:
|
||||
|
||||
@@ -6,11 +6,6 @@ from lxml import etree
|
||||
from ebook_converter.ebooks.oeb.base import rewrite_links, urlnormalize
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
|
||||
class RenameFiles(object): # {{{
|
||||
|
||||
'''
|
||||
|
||||
@@ -149,7 +149,7 @@ class RemoveFakeMargins(object):
|
||||
remove = set()
|
||||
for k, v in self.levels.items():
|
||||
num = len(v)
|
||||
self.log.debug('Found %s items of level: %s', num, k)
|
||||
self.log.debug('Found %d items of level: %s', num, k)
|
||||
level = int(k.split('_')[-1])
|
||||
tag = k.split('_')[0]
|
||||
if tag == 'p' and num < 25:
|
||||
|
||||
@@ -60,7 +60,7 @@ class RescaleImages(object):
|
||||
if scaled:
|
||||
new_width = max(1, new_width)
|
||||
new_height = max(1, new_height)
|
||||
self.log('Rescaling image from %sx%s to %sx%s %s', width,
|
||||
self.log('Rescaling image from %dx%d to %dx%d %s', width,
|
||||
height, new_width, new_height, item.href)
|
||||
try:
|
||||
img = img.resize((new_width, new_height))
|
||||
|
||||
@@ -22,9 +22,6 @@ from ebook_converter.css_selectors import Select, SelectorError
|
||||
from ebook_converter.utils import encoding as uenc
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
XPath = functools.partial(_XPath, namespaces=const.XPNSMAP)
|
||||
|
||||
SPLIT_POINT_ATTR = 'csp'
|
||||
@@ -128,7 +125,7 @@ class Split(object):
|
||||
page_breaks.add(elem)
|
||||
except SelectorError as err:
|
||||
self.log.warn('Ignoring page breaks specified with invalid '
|
||||
'CSS selector: %s (%s)', selector, err)
|
||||
'CSS selector: %r (%s)', selector, err)
|
||||
|
||||
for i, elem in enumerate(item.data.iter('*')):
|
||||
try:
|
||||
@@ -227,7 +224,7 @@ class FlowSplitter(object):
|
||||
for i, tree in enumerate(trees):
|
||||
size = len(tostring(tree.getroot()))
|
||||
if size > self.max_flow_size:
|
||||
self.log.info('\tFound large tree #%s', i)
|
||||
self.log.info('\tFound large tree #%d', i)
|
||||
lt_found = True
|
||||
self.split_trees = []
|
||||
self.split_to_size(tree)
|
||||
@@ -240,7 +237,7 @@ class FlowSplitter(object):
|
||||
|
||||
self.was_split = len(self.trees) > 1
|
||||
if self.was_split:
|
||||
self.log('\tSplit into %s parts', len(self.trees))
|
||||
self.log('\tSplit into %d parts', len(self.trees))
|
||||
self.commit()
|
||||
|
||||
def split_on_page_breaks(self, orig_tree):
|
||||
@@ -380,7 +377,7 @@ class FlowSplitter(object):
|
||||
continue
|
||||
elif size <= self.max_flow_size:
|
||||
self.split_trees.append(t)
|
||||
self.log.debug('\t\t\tCommitted sub-tree #%s (%s KB)',
|
||||
self.log.debug('\t\t\tCommitted sub-tree #%d (%d KB)',
|
||||
len(self.split_trees), size/1024.)
|
||||
else:
|
||||
self.log.debug('\t\t\tSplit tree still too large: %d KB',
|
||||
|
||||
@@ -67,7 +67,7 @@ class DetectStructure(object):
|
||||
self.oeb.toc = orig_toc
|
||||
else:
|
||||
self.oeb.auto_generated_toc = True
|
||||
self.log.info('Auto generated TOC with %s entries.',
|
||||
self.log.info('Auto generated TOC with %d entries.',
|
||||
self.oeb.toc.count())
|
||||
|
||||
if opts.toc_filter is not None:
|
||||
@@ -240,7 +240,7 @@ class DetectStructure(object):
|
||||
play_order=self.oeb.toc.next_play_order())
|
||||
num += 1
|
||||
except ValueError:
|
||||
self.oeb.log.critical('Failed to process link: %s',
|
||||
self.oeb.log.critical('Failed to process link: %r',
|
||||
href)
|
||||
# Most likely an incorrectly URL encoded link
|
||||
continue
|
||||
|
||||
@@ -112,7 +112,7 @@ class Reader132(FormatReader):
|
||||
|
||||
pml = ''
|
||||
for i in range(1, self.header_record.num_text_pages + 1):
|
||||
self.log.debug('Extracting text page %s', i)
|
||||
self.log.debug('Extracting text page %i', i)
|
||||
pml += self.get_text_page(i)
|
||||
hizer = PML_HTMLizer()
|
||||
html += hizer.parse_pml(pml, 'index.html')
|
||||
@@ -123,7 +123,7 @@ class Reader132(FormatReader):
|
||||
footnoteids = re.findall(
|
||||
'\\w+(?=\x00)', self.section_data(self.header_record.footnote_offset).decode('cp1252' if self.encoding is None else self.encoding))
|
||||
for fid, i in enumerate(range(self.header_record.footnote_offset + 1, self.header_record.footnote_offset + self.header_record.footnote_count)):
|
||||
self.log.debug('Extracting footnote page %s', i)
|
||||
self.log.debug('Extracting footnote page %i', i)
|
||||
if fid < len(footnoteids):
|
||||
fid = footnoteids[fid]
|
||||
else:
|
||||
@@ -135,7 +135,7 @@ class Reader132(FormatReader):
|
||||
sidebarids = re.findall(
|
||||
'\\w+(?=\x00)', self.section_data(self.header_record.sidebar_offset).decode('cp1252' if self.encoding is None else self.encoding))
|
||||
for sid, i in enumerate(range(self.header_record.sidebar_offset + 1, self.header_record.sidebar_offset + self.header_record.sidebar_count)):
|
||||
self.log.debug('Extracting sidebar page %s', i)
|
||||
self.log.debug('Extracting sidebar page %i', i)
|
||||
if sid < len(sidebarids):
|
||||
sid = sidebarids[sid]
|
||||
else:
|
||||
|
||||
@@ -87,7 +87,7 @@ class Reader202(FormatReader):
|
||||
|
||||
pml = ''
|
||||
for i in range(1, self.header_record.num_text_pages + 1):
|
||||
self.log.debug('Extracting text page %s', i)
|
||||
self.log.debug('Extracting text page %i', i)
|
||||
pml += self.get_text_page(i)
|
||||
|
||||
title = self.mi.title
|
||||
|
||||
@@ -118,7 +118,7 @@ class Reader(FormatReader):
|
||||
|
||||
self.log.info('Decompressing text...')
|
||||
for i in range(1, self.header_record.num_records + 1):
|
||||
self.log.debug('\tDecompressing text section %s', i)
|
||||
self.log.debug('\tDecompressing text section %i', i)
|
||||
title = self.header_record.chapter_titles[i-1]
|
||||
lines = []
|
||||
title_added = False
|
||||
|
||||
@@ -55,7 +55,7 @@ class Reader(FormatReader):
|
||||
|
||||
self.log.info('Decompressing text...')
|
||||
for i in range(1, self.header_record.num_records + 1):
|
||||
self.log.debug('\tDecompressing text section %s', i)
|
||||
self.log.debug('\tDecompressing text section %i', i)
|
||||
raw_txt += self.decompress_text(i)
|
||||
|
||||
self.log.info('Converting text to OEB...')
|
||||
|
||||
@@ -54,7 +54,7 @@ class Reader(FormatReader):
|
||||
if (self.header_record.flags & 0x01) == 0:
|
||||
raise zTXTError('Only compression method 1 (random access) is supported')
|
||||
|
||||
self.log.debug('Foud ztxt version: %s.%s', vmajor, vminor)
|
||||
self.log.debug('Foud ztxt version: %i.%i', vmajor, vminor)
|
||||
|
||||
# Initalize the decompressor
|
||||
self.uncompressor = zlib.decompressobj()
|
||||
@@ -73,7 +73,7 @@ class Reader(FormatReader):
|
||||
|
||||
self.log.info('Decompressing text...')
|
||||
for i in range(1, self.header_record.num_records + 1):
|
||||
self.log.debug('\tDecompressing text section %s', i)
|
||||
self.log.debug('\tDecompressing text section %i', i)
|
||||
raw_txt += self.decompress_text(i)
|
||||
|
||||
self.log.info('Converting text to OEB...')
|
||||
|
||||
@@ -11,12 +11,6 @@ from ebook_converter.ebooks.oeb.base import XHTML, barename, namespace, rewrite_
|
||||
from ebook_converter.ebooks.oeb.stylizer import Stylizer
|
||||
|
||||
|
||||
__license__ = 'GPL 3'
|
||||
__copyright__ = ('2011, John Schember <john@nachtimwald.com> 2011, '
|
||||
'Leigh Parry <leighparry@blueyonder.co.uk>')
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
|
||||
class MarkdownMLizer(OEB2HTML):
|
||||
|
||||
def extract_content(self, oeb_book, opts):
|
||||
|
||||
@@ -14,11 +14,6 @@ from ebook_converter.ebooks import unit_convert
|
||||
from ebook_converter.ebooks.textile.unsmarten import unsmarten
|
||||
|
||||
|
||||
__license__ = 'GPL 3'
|
||||
__copyright__ = '2011, Leigh Parry <leighparry@blueyonder.co.uk>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
|
||||
class TextileMLizer(OEB2HTML):
|
||||
|
||||
MAX_EM = 10
|
||||
|
||||
Reference in New Issue
Block a user