Skip to content
Snippets Groups Projects
Verified Commit d7adec24 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Use python tempfile mechanism for temporary files

parent 13998972
No related branches found
No related tags found
1 merge request!18Resolve "Use real temporary folder for barcode PDF files"
Pipeline #20883 passed
import os
import subprocess # noqa import subprocess # noqa
import time import time
from tempfile import TemporaryDirectory
import requests import requests
from barcode import Code128 from barcode import Code128
...@@ -110,18 +112,22 @@ def print_server(): ...@@ -110,18 +112,22 @@ def print_server():
if report == "barcode_label": if report == "barcode_label":
label_url = base_url + document["barcode_label"] label_url = base_url + document["barcode_label"]
# Download barcode label with TemporaryDirectory() as temp_dir:
r = requests.get(label_url) # Download barcode label
with open("barcode-tmp.pdf", "wb") as f: r = requests.get(label_url)
f.write(r.content) filename = os.path.join(temp_dir, "barcode-tmp.pdf")
print(filename)
# Send barcode label to printer with open(filename, "wb") as f:
subprocess.Popen( # noqa f.write(r.content)
["lp", "-d", settings.get("barcode_printer.name"), "barcode-tmp.pdf"], print(["lp", "-d", settings.get("barcode_printer.name"), filename])
stderr=subprocess.DEVNULL, # Send barcode label to printer
stdout=subprocess.DEVNULL, p = subprocess.Popen( # noqa
) # noqa ["lp", "-d", settings.get("barcode_printer.name"), filename],
printed = True stderr=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
) # noqa
p.wait()
printed = True
elif report == "info_page": elif report == "info_page":
print_info(document, categories) print_info(document, categories)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment