Comment 0 for bug 1941992

Revision history for this message
Gregory Khvatsky (gregkh1996) wrote :

When trying ebook-convert with TXT output and --max-line-length option set to more than 25, e.g.

ebook-convert d_ch.fb2 text.txt --max-line-length 70

The command crashes with the following error:

.....
Converting XHTML to TXT...
Traceback (most recent call last):
  File "runpy.py", line 194, in _run_module_as_main
  File "runpy.py", line 87, in _run_code
  File "site.py", line 45, in <module>
  File "site.py", line 41, in main
  File "calibre/ebooks/conversion/cli.py", line 401, in main
  File "calibre/ebooks/conversion/plumber.py", line 1271, in run
  File "calibre/ebooks/conversion/plugins/txt_output.py", line 100, in convert
  File "calibre/ebooks/txt/txtml.py", line 65, in extract_content
  File "calibre/ebooks/txt/txtml.py", line 86, in mlize_spine
  File "calibre/ebooks/txt/txtml.py", line 160, in cleanup_text
TypeError: slice indices must be integers or None or have an __index__ method

This is most likely due to the fact that for some reason, in the function cleanup_text, the type of self.opts.max_line_length is float, which, when passed to line.rfind(...) on line 160, causes the error. This behavior of rfind can be reproduced by running something like

"aaaa aaaa".rfind(" ", 0, 1.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: slice indices must be integers or None or have an __index__ method

In a Python console.

Included is a patch that fixes this by forcibly converting self.opts.max_line_length to an int, although I am not sure whether it broke something else or not.