mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-21 13:41:30 +02:00
Use the real constants module.
This is progressing refactor of the calibre code to make it more readable, and transform it to something more coherent. In this patch, there are changes regarding imports for some modules, instead of polluting namespace of each module with some other modules symbols, which often were imported from other modules. Yuck.
This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
from lxml import etree
|
||||
|
||||
from ebook_converter.ebooks.oeb.polish.container import OPF_NAMESPACES
|
||||
from ebook_converter import constants as const
|
||||
from ebook_converter.utils.localization import canonicalize_lang
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
|
||||
def get_book_language(container):
|
||||
for lang in container.opf_xpath('//dc:language'):
|
||||
raw = lang.text
|
||||
@@ -18,7 +14,7 @@ def get_book_language(container):
|
||||
|
||||
|
||||
def set_guide_item(container, item_type, title, name, frag=None):
|
||||
ref_tag = '{%s}reference' % OPF_NAMESPACES['opf']
|
||||
ref_tag = const.OPF_REFERENCE
|
||||
href = None
|
||||
if name:
|
||||
href = container.name_to_href(name, container.opf_name)
|
||||
@@ -27,23 +23,27 @@ def set_guide_item(container, item_type, title, name, frag=None):
|
||||
|
||||
guides = container.opf_xpath('//opf:guide')
|
||||
if not guides and href:
|
||||
g = container.opf.makeelement('{%s}guide' % OPF_NAMESPACES['opf'], nsmap={'opf':OPF_NAMESPACES['opf']})
|
||||
g = container.opf.makeelement(const.OPF_GUIDE,
|
||||
nsmap={'opf': const.OPF2_NS})
|
||||
container.insert_into_xml(container.opf, g)
|
||||
guides = [g]
|
||||
|
||||
for guide in guides:
|
||||
matches = []
|
||||
for child in guide.iterchildren(etree.Element):
|
||||
if child.tag == ref_tag and child.get('type', '').lower() == item_type.lower():
|
||||
if (child.tag == ref_tag and
|
||||
child.get('type', '').lower() == item_type.lower()):
|
||||
matches.append(child)
|
||||
if not matches and href:
|
||||
r = guide.makeelement(ref_tag, type=item_type, nsmap={'opf':OPF_NAMESPACES['opf']})
|
||||
r = guide.makeelement(ref_tag, type=item_type,
|
||||
nsmap={'opf': const.OPF2_NS})
|
||||
container.insert_into_xml(guide, r)
|
||||
matches.append(r)
|
||||
for m in matches:
|
||||
if href:
|
||||
m.set('title', title), m.set('href', href), m.set('type', item_type)
|
||||
m.set('title', title)
|
||||
m.set('href', href)
|
||||
m.set('type', item_type)
|
||||
else:
|
||||
container.remove_from_xml(m)
|
||||
container.dirty(container.opf_name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user