feat: improve handling of output directory
- don't fail, when the directory doesn't exist but create it instead - handle failures to create the output directory properly - use f-string formatting to simplify building the output filename - use OS-independent `os.path.join` to build the output path
This commit is contained in:
committed by
gitolicious
parent
aeb5ca7b3d
commit
f9d2cb4469
10
main.py
10
main.py
@@ -1,3 +1,6 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
import AveryLabels
|
||||
from reportlab.lib.units import mm, cm
|
||||
from reportlab_qrcode import QRCodeImage
|
||||
@@ -96,10 +99,15 @@ def render(c: canvas.Canvas, width: float, height: float):
|
||||
c.restoreState()
|
||||
|
||||
|
||||
fileName = "out/labels-" + str(labelForm) + "-" + str(mode) + ".pdf"
|
||||
outputDirectory = 'out'
|
||||
fileName = os.path.join(outputDirectory, f"labels-{labelForm}-{mode}.pdf")
|
||||
|
||||
label = AveryLabels.AveryLabel(labelForm)
|
||||
label.debug = debug
|
||||
try:
|
||||
os.makedirs(outputDirectory, exist_ok=True)
|
||||
except OSError as oe:
|
||||
sys.exit(f"Failed to create directory '{outputDirectory}': {oe}")
|
||||
label.open(fileName)
|
||||
label.render(render, count=labelsToPrint, offset=offsetLabels)
|
||||
label.close()
|
||||
|
||||
Reference in New Issue
Block a user