use pyproject.toml
This commit is contained in:
parent
b421e330f4
commit
465a5574b8
5 changed files with 166 additions and 85 deletions
97
server/server.py
Executable file
97
server/server.py
Executable file
|
|
@ -0,0 +1,97 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Run this stuff with `waitress-serve --port=5000 --call server:create_app`
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
from flask import Flask, request
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
SCANBUDDY_COMMAND = ["bash", f"{os.getcwd()}/scanbuddy.bash"]
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def hello_world():
|
||||
return "Hello, World! Yoyoyo"
|
||||
|
||||
|
||||
@app.route("/scan")
|
||||
def scan():
|
||||
print("Scanning...")
|
||||
command = SCANBUDDY_COMMAND + ["scan"]
|
||||
|
||||
duplex = request.args.get("duplex", "n") == 'y'
|
||||
resolution = request.args.get("resolution", None)
|
||||
|
||||
if duplex:
|
||||
print("Duplex: on")
|
||||
command += ["-d"]
|
||||
if resolution:
|
||||
print(f"Res.: {int(resolution)}")
|
||||
# turning the string to an int and back to a string should clean up the input
|
||||
command += ["-r", f"{int(resolution)}"]
|
||||
|
||||
result = subprocess.run(command, stdout=subprocess.PIPE, text=True)
|
||||
output = result.stdout.strip()
|
||||
|
||||
print("Scanbuddy output: ")
|
||||
print(output)
|
||||
|
||||
return output
|
||||
# return f"Scanning {'duplex' if duplex == 'y' else ''}..."
|
||||
|
||||
|
||||
@app.route("/dispatch")
|
||||
def dispatch():
|
||||
print("Dispatching...")
|
||||
command = SCANBUDDY_COMMAND + ["dispatch"]
|
||||
|
||||
# TODO: implement user
|
||||
user = request.args.get("user", "")
|
||||
|
||||
result = subprocess.run(command, stdout=subprocess.PIPE, text=True)
|
||||
output = result.stdout.strip()
|
||||
|
||||
print("Scanbuddy output: ")
|
||||
print(output)
|
||||
|
||||
return output
|
||||
|
||||
|
||||
@app.route("/unscan")
|
||||
def unscan():
|
||||
print("Unscanning...")
|
||||
command = SCANBUDDY_COMMAND + ["unscan"]
|
||||
|
||||
result = subprocess.run(command, stdout=subprocess.PIPE, text=True)
|
||||
output = result.stdout.strip()
|
||||
|
||||
print("Scanbuddy output: ")
|
||||
print(output)
|
||||
return output
|
||||
|
||||
|
||||
@app.route("/clean")
|
||||
def clean():
|
||||
print("Cleaning...")
|
||||
command = SCANBUDDY_COMMAND + ["clean"]
|
||||
|
||||
result = subprocess.run(command, stdout=subprocess.PIPE, text=True)
|
||||
output = result.stdout.strip()
|
||||
|
||||
print("Scanbuddy output: ")
|
||||
print(output)
|
||||
return output
|
||||
|
||||
|
||||
def create_app():
|
||||
return app
|
||||
|
||||
|
||||
def main():
|
||||
from waitress import serve
|
||||
serve(app, host="0.0.0.0", port=5000)
|
||||
|
||||
if __name__=='__main__':
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue