Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPUB2 error while exporting #196

Closed
csantanu opened this issue Oct 10, 2019 · 5 comments
Closed

EPUB2 error while exporting #196

csantanu opened this issue Oct 10, 2019 · 5 comments

Comments

@csantanu
Copy link

Hi,

I am getting this error while using the Booktype installation which uses ebooklib as core package. Strangely, this is not happening with EPUB3 format and it is perfectly exporting.

When I am publishing using EPUB2 format, I am getting this error : KeyError : 'package_direction'.

File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 375, $
R = retval = fun(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 632, $
return self.run(*args, **kwargs)
File "/usr/local/src/booktype/lib/booktype/apps/convert/tasks.py", line 50, i$
return func(request, *args, **kwargs)
File "/usr/local/src/booktype/lib/booktype/apps/convert/tasks.py", line 66, i$
result = run_conversion(*args, **kwargs)
File "/usr/local/src/booktype/lib/booktype/convert/runner.py", line 58, in ru$
conversion_result = converter.convert(book, output)
File "/usr/local/src/booktype/lib/booktype/convert/epub/converter.py", line 1$
epub_writer.write()
File "/usr/local/lib/python2.7/dist-packages/ebooklib/epub.py", line 1223, in$
self._write_opf_file()
File "/usr/local/lib/python2.7/dist-packages/ebooklib/epub.py", line 858, in $
if self.book.direction and self.options['package_direction']:
KeyError: 'package_direction'

Please help!
Thanks.
Santanu

@laudrain
Copy link

trying an advice: stop producing EPUB2 ;)
All what EPUB2 does is done better with EPUB3...

@csantanu
Copy link
Author

Yes, I can take the EPUB3 route. But it produces a 'Guide' by default that is typically not required for most of the titles. How to switch off this feature? Booktype does not provide any interface for setting this up for EPUB3 format.

@aerkalov
Copy link
Owner

I haven't been working on the Booktype for couple of years so I wouldn't really know what have they changed but if you have your own installation you can always modify default options in file: /lib/booktype/convert/epub/writer.py

class Epub3Writer(ebooklib.epub.EpubWriter):
    DEFAULT_OPTIONS = {
        'epub2_guide': True,
        'epub3_landmark': True,
        'epub3_pages': True,
        'landmark_title': 'Guide',
        'pages_title': 'Pages',
        'spine_direction': True,
        'package_direction': False,
        'play_order': {
            'enabled': False,
            'start_from': 1
        }
    }

I just copy + pasted default options from ebooklib but modify it as you like. That will produce EPUB3 without guide.

@laudrain
Copy link

@csantanu I don't know Booktype. Thanks @aerkalov.

On guide element, latest EPUB 3.2 spec says:

The guide element [OPF2] is a legacy feature that previously provided machine-processable navigation to key structures in an EPUB Publication. It is replaced in EPUB 3 by landmarks in the EPUB Navigation Document.

@csantanu
Copy link
Author

Thanks @aerkalov
I have solved the above mentioned bug as well. In the booktype writer implementation under the epub2 writer class this default option was set -
DEFAULT_OPTIONS = {
'epub2_guide': True,
'epub3_landmark': False,
'landmark_title': 'Guide'
}
This was throwing the error for package_direction key which was coming as null. After putting the entire default options chunk here, now epub2 export is working fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants