Review fixes

This commit is contained in:
Jared Esparza 2023-12-05 14:27:27 +01:00
parent 988646e903
commit d1f491d30e
4 changed files with 31 additions and 34 deletions

View File

@ -484,20 +484,9 @@ class HTMLReportMixin:
except KeyError:
logger.warning('Model "Printer" not found.')
if Printer:
result = Printer.send_report(oext, content,
return Printer.send_report(oext, content,
action_name, action)
if result:
oext, content, direct_print, filename = result
if queue and content:
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
temp_file.write(content)
try:
queue.put((oext, temp_file.name, cls.get_direct_print(action), filename))
except Exception as e:
queue.put(e)
elif content:
return (oext, content, cls.get_direct_print(action), filename)
return oext, content, cls.get_direct_print(action), filename
@classmethod
def execute(cls, ids, data):

View File

@ -190,26 +190,31 @@ class PdfGenerator:
def render_pdf(self):
context = Transaction().context
timeout = context.get('timeout', None)
path = os.path.dirname(os.path.abspath(__file__)) + '/'
json_path = self.to_json_file()
process = subprocess.Popen(['python3', path+'generator_script.py', json_path],
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
encoding='utf-8', errors='ignore')
out = None
try:
out, err = process.communicate(timeout=timeout)
except subprocess.TimeoutExpired:
print('timeout')
process.kill()
out, err = process.communicate()
raise UserError(gettext('html_report.msg_error_timeout'))
timeout_report = context.get('timeout_report', None)
document = None
if out and os.path.exists(out.strip()):
with open(out.strip(), 'rb') as file:
document = file.read()
os.remove(out.strip())
if timeout_report:
path = os.path.dirname(os.path.abspath(__file__)) + '/'
json_path = self.to_json_file()
process = subprocess.Popen(['python3', path+'generator_script.py', json_path],
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
encoding='utf-8', errors='ignore')
out = None
try:
out, err = process.communicate(timeout=timeout_report)
except subprocess.TimeoutExpired:
process.kill()
out, err = process.communicate()
raise UserError(gettext('html_report.msg_error_timeout', seconds=timeout_report))
finally:
os.remove(json_path)
document = None
if out and os.path.exists(out.strip()):
with open(out.strip(), 'rb') as file:
document = file.read()
os.remove(out.strip())
else:
document = self.render_html().write_pdf()
return document
@staticmethod

View File

@ -26,10 +26,13 @@ def from_json_file(filepath):
side_margin=data["side_margin"],
extra_vertical_margin=data["extra_vertical_margin"]
)
os.remove(filepath)
return reuslt
def main(argv):
conunt = 0
for i in range(100000000):
conunt += 1
json_filepath = argv[1]
pdf_generator = from_json_file(json_filepath)
result = pdf_generator.render_html().write_pdf()

View File

@ -23,7 +23,7 @@
<field name="text">The nullslast filter only accept a list of tuples.</field>
</record>
<record model="ir.message" id="msg_error_timeout">
<field name="text">The process was interrupted by timeout.</field>
<field name="text">The process was interrupted by %(seconds)s seconds timeout.</field>
</record>
<record model="ir.message" id="msg_queue_empty">
<field name="text">The queue (timeout) was empty and can not render the report.</field>