diff --git a/src/calibre/ebooks/oeb/polish/check/opf.py b/src/calibre/ebooks/oeb/polish/check/opf.py index 71552eebfb..a4dcf77b72 100644 --- a/src/calibre/ebooks/oeb/polish/check/opf.py +++ b/src/calibre/ebooks/oeb/polish/check/opf.py @@ -8,6 +8,7 @@ from calibre import prepare_string_for_xml as xml from calibre.ebooks.oeb.polish.check.base import BaseError, WARN +from calibre.ebooks.oeb.base import OPF, OPF2_NS class MissingSection(BaseError): @@ -49,8 +50,14 @@ def __call__(self, container): def check_opf(container): errors = [] + if container.opf.tag != OPF('package'): + err = BaseError(_('The OPF does not have the correct root element'), container.opf_name) + err.HELP = xml(_( + 'The opf must have the root element in namespace {0}, like this: ')).format(OPF2_NS) + errors.append(err) + for tag in ('metadata', 'manifest', 'spine'): - if not container.opf_xpath('//opf:' + tag): + if not container.opf_xpath('/opf:package/opf:' + tag): errors.append(MissingSection(container.opf_name, tag)) all_ids = set(container.opf_xpath('//*/@id')) @@ -62,4 +69,9 @@ def check_opf(container): if nl_items: errors.append(NonLinearItems(container.opf_name, nl_items)) + # Check unique identifier, version, tag with name before content for + # cover and content pointing to proper manifest item. Duplicate items in + # spine. Duplicate hrefs in manifest. hrefs in manifest that point to + # missing resources. + return errors