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 time
from tempfile import TemporaryDirectory
import requests
from barcode import Code128
......@@ -110,18 +112,22 @@ def print_server():
if report == "barcode_label":
label_url = base_url + document["barcode_label"]
# Download barcode label
r = requests.get(label_url)
with open("barcode-tmp.pdf", "wb") as f:
f.write(r.content)
# Send barcode label to printer
subprocess.Popen( # noqa
["lp", "-d", settings.get("barcode_printer.name"), "barcode-tmp.pdf"],
stderr=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
) # noqa
printed = True
with TemporaryDirectory() as temp_dir:
# Download barcode label
r = requests.get(label_url)
filename = os.path.join(temp_dir, "barcode-tmp.pdf")
print(filename)
with open(filename, "wb") as f:
f.write(r.content)
print(["lp", "-d", settings.get("barcode_printer.name"), filename])
# Send barcode label to printer
p = subprocess.Popen( # noqa
["lp", "-d", settings.get("barcode_printer.name"), filename],
stderr=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
) # noqa
p.wait()
printed = True
elif report == "info_page":
print_info(document, categories)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment