Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
web2print
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
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
Frank Sauerburger
web2print
Commits
71a55318
Verified
Commit
71a55318
authored
5 years ago
by
Frank Sauerburger
Browse files
Options
Downloads
Patches
Plain Diff
Add first functional draft
parents
Branches
57-more-intelligent-collection-sorting
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
requirements.txt
+2
-0
2 additions, 0 deletions
requirements.txt
templates/index.html
+13
-0
13 additions, 0 deletions
templates/index.html
web2print.py
+43
-0
43 additions, 0 deletions
web2print.py
with
58 additions
and
0 deletions
requirements.txt
0 → 100644
+
2
−
0
View file @
71a55318
flask
pycups
This diff is collapsed.
Click to expand it.
templates/index.html
0 → 100644
+
13
−
0
View file @
71a55318
<!doctype html>
<html>
Hello
<ul>
{% for printer in printers %}
<li>
{{ printer }}
</li>
{% endfor %}
</ul>
<form
action=
"/"
method=
"post"
enctype=
"multipart/form-data"
>
<input
type=
"file"
name=
"document"
/>
<input
type=
"submit"
value=
"print"
/>
</form>
</html>
This diff is collapsed.
Click to expand it.
web2print.py
0 → 100644
+
43
−
0
View file @
71a55318
import
os
from
time
import
time
import
cups
from
flask
import
Flask
,
render_template
,
request
from
werkzeug.utils
import
secure_filename
CUPS_SERVER
=
"
10.1.9.104:631
"
cups
.
setServer
(
CUPS_SERVER
)
app
=
Flask
(
__name__
)
app
.
config
[
'
UPLOAD_FOLDER
'
]
=
"
/tmp/web2print
"
os
.
makedirs
(
"
/tmp/web2print
"
,
exist_ok
=
True
)
def
get_printers
():
conn
=
cups
.
Connection
()
return
list
(
conn
.
getPrinters
())
@app.route
(
'
/
'
,
methods
=
[
"
POST
"
,
"
GET
"
])
def
index
():
if
(
request
.
method
==
"
GET
"
)
or
(
"
document
"
not
in
request
.
files
)
or
\
(
not
request
.
files
[
"
document
"
].
filename
):
return
render_template
(
"
index.html
"
,
printers
=
printers
)
file
=
request
.
files
[
'
document
'
]
filename
=
secure_filename
(
file
.
filename
)
local_path
=
os
.
path
.
join
(
app
.
config
[
'
UPLOAD_FOLDER
'
],
filename
)
file
.
save
(
local_path
)
conn
=
cups
.
Connection
()
conn
.
printFile
(
printers
[
0
],
local_path
,
"
web2print-%d
"
%
time
(),
{
"
fit-to-page
"
:
"
True
"
,
"
sides
"
:
"
two-sided-long-edge
"
})
try
:
os
.
remove
(
local_path
)
except
OSError
:
pass
return
"
ok
"
if
__name__
==
'
__main__
'
:
printers
=
get_printers
()
app
.
run
()
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