Skip to content
Snippets Groups Projects
Verified Commit 71a55318 authored by Frank Sauerburger's avatar Frank Sauerburger
Browse files

Add first functional draft

parents
Branches 1-improve-user-interface
No related tags found
No related merge requests found
<!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>
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()
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