Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
documento-printserver
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Documento
documento-printserver
Commits
d7adec24
Verified
Commit
d7adec24
authored
3 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Use python tempfile mechanism for temporary files
parent
13998972
No related branches found
No related tags found
1 merge request
!18
Resolve "Use real temporary folder for barcode PDF files"
Pipeline
#20883
passed
3 years ago
Stage: test
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
documento_printserver/print_server.py
+18
-12
18 additions, 12 deletions
documento_printserver/print_server.py
with
18 additions
and
12 deletions
documento_printserver/print_server.py
+
18
−
12
View file @
d7adec24
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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment