1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2025-12-18 13:10:17 +01:00

Removed ipc module.

There was only one function in module ipc: eintr_retry_call. This
function was used in pdftohtml module, and turns out[1] it's not needed
anymore. Support for retrying on syscall interrupts was introduced in
Python 3.5 (which was released in 2015), and covers subprocess module
among other modules. In this commit, mentioned eintr_retry_call function
has been removed, and couple of cosmetic changes was done in module
pdftohtml.

[1] https://www.python.org/dev/peps/pep-0475/
This commit is contained in:
2021-02-22 20:59:21 +01:00
parent b2f161670a
commit 2371a5a1c9
2 changed files with 12 additions and 25 deletions

View File

@@ -12,7 +12,6 @@ from ebook_converter.ptempfile import PersistentTemporaryFile
from ebook_converter.utils.cleantext import clean_xml_chars
from ebook_converter.utils import directory
from ebook_converter.utils import entities
from ebook_converter.utils.ipc import eintr_retry_call
def popen(cmd, **kw):
@@ -33,12 +32,8 @@ def pdftohtml(output_dir, pdf_path, no_images, as_xml=False):
shutil.copyfileobj(src, dest)
with directory.CurrentDir(output_dir):
def a(x):
return os.path.basename(x)
cmd = ['pdftohtml', '-enc', 'UTF-8', '-noframes', '-p', '-nomerge',
'-nodrm', a(pdfsrc), a(index)]
'-nodrm', os.path.basename(pdfsrc), os.path.basename(index)]
if no_images:
cmd.append('-i')
@@ -46,19 +41,22 @@ def pdftohtml(output_dir, pdf_path, no_images, as_xml=False):
cmd.append('-xml')
logf = PersistentTemporaryFile('pdftohtml_log')
try:
p = popen(cmd, stderr=logf._fd, stdout=logf._fd,
stdin=subprocess.PIPE)
ret = subprocess.call(cmd, stderr=logf._fd, stdout=logf._fd)
except OSError as err:
if err.errno == errno.ENOENT:
raise ConversionError('Could not find pdftohtml, check it is '
'in your PATH')
else:
raise
ret = eintr_retry_call(p.wait)
logf.flush()
logf.close()
out = open(logf.name, 'rb').read().decode('utf-8', 'replace').strip()
with open(logf.name) as fobj:
out = fobj.read().strip()
if ret != 0:
raise ConversionError('pdftohtml failed with return code: '
'%d\n%s' % (ret, out))
@@ -92,10 +90,10 @@ def pdftohtml(output_dir, pdf_path, no_images, as_xml=False):
cmd = ['pdftohtml', '-f', '1', '-l', '1', '-xml', '-i', '-enc',
'UTF-8', '-noframes', '-p', '-nomerge', '-nodrm', '-q',
'-stdout', a(pdfsrc)]
p = popen(cmd, stdout=subprocess.PIPE)
raw = p.stdout.read().strip()
if p.wait() == 0 and raw:
'-stdout', os.path.basename(pdfsrc)]
raw = subprocess.check_output(cmd).strip()
if raw:
parse_outline(raw, output_dir)
try:

View File

@@ -1,11 +0,0 @@
import errno
def eintr_retry_call(func, *args, **kwargs):
while True:
try:
return func(*args, **kwargs)
except EnvironmentError as e:
if getattr(e, 'errno', None) == errno.EINTR:
continue
raise