0001-workflows-retry-PDF-generation-if-it-fails-for-some-.patch
wcs/wf/export_to_model.py | ||
---|---|---|
18 | 18 |
import collections |
19 | 19 |
from xml.etree import ElementTree as ET |
20 | 20 |
import zipfile |
21 |
import os |
|
21 | 22 |
import random |
22 | 23 |
import subprocess |
23 | 24 |
import tempfile |
25 |
import time |
|
24 | 26 |
import shutil |
25 | 27 | |
26 | 28 |
from django.utils import six |
... | ... | |
76 | 78 |
break |
77 | 79 |
infile.write(chunk) |
78 | 80 |
infile.flush() |
79 |
subprocess.check_call(['libreoffice', '--headless', '--convert-to', 'pdf', |
|
80 |
infile.name, '--outdir', temp_dir], |
|
81 |
stdout=subprocess.DEVNULL, |
|
82 |
stderr=subprocess.DEVNULL) |
|
81 |
for i in range(3): |
|
82 |
lo_output = subprocess.run( |
|
83 |
['libreoffice', '--headless', '--convert-to', 'pdf', |
|
84 |
infile.name, '--outdir', temp_dir], |
|
85 |
check=True, stdout=subprocess.PIPE) |
|
86 |
if os.path.exists(infile.name + '.pdf'): |
|
87 |
break |
|
88 |
# sometimes libreoffice fails and sometimes it's ok |
|
89 |
# afterwards. |
|
90 |
time.sleep(0.5) |
|
91 |
if not os.path.exists(infile.name + '.pdf'): |
|
92 |
raise Exception('libreoffice failed to produce pdf (%r)' % lo_output.stdout) |
|
83 | 93 |
return open(infile.name + '.pdf', 'rb') |
84 | 94 |
except subprocess.CalledProcessError: |
85 | 95 |
raise Exception('libreoffice is failing') |
86 |
- |