use pyproject.toml
This commit is contained in:
parent
b421e330f4
commit
465a5574b8
5 changed files with 166 additions and 85 deletions
23
flake.lock
generated
23
flake.lock
generated
|
|
@ -16,9 +16,30 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"pyproject-nix": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1758265079,
|
||||||
|
"narHash": "sha256-amLaLNwKSZPShQHzfgmc/9o76dU8xzN0743dWgvYlr8=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "pyproject.nix",
|
||||||
|
"rev": "02e9418fd4af638447dca4b17b1280da95527fc9",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "pyproject.nix",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs",
|
||||||
|
"pyproject-nix": "pyproject-nix"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
65
flake.nix
65
flake.nix
|
|
@ -1,59 +1,60 @@
|
||||||
{
|
{
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
pyproject-nix = {
|
||||||
|
url = "github:nix-community/pyproject.nix";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
outputs = {
|
outputs = {
|
||||||
self,
|
self,
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
|
...
|
||||||
} @ inputs: let
|
} @ inputs: let
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
inherit system;
|
inherit system;
|
||||||
config.allowUnfree = true;
|
config.allowUnfree = true;
|
||||||
};
|
};
|
||||||
in {
|
python = pkgs.python3;
|
||||||
devShells.${system}.default = pkgs.mkShell {
|
serverProject = inputs.pyproject-nix.lib.project.loadPyproject {
|
||||||
packages = with pkgs; [
|
projectRoot = ./.;
|
||||||
python313
|
|
||||||
python313Packages.flask
|
|
||||||
python313Packages.waitress
|
|
||||||
];
|
|
||||||
|
|
||||||
shellHook = ''
|
|
||||||
python --version
|
|
||||||
exec zsh
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
in {
|
||||||
|
# devShells.${system}.default = pkgs.mkShell {
|
||||||
|
# packages = with pkgs; [
|
||||||
|
# python313
|
||||||
|
# python313Packages.flask
|
||||||
|
# python313Packages.waitress
|
||||||
|
# ];
|
||||||
|
#
|
||||||
|
# shellHook = ''
|
||||||
|
# python --version
|
||||||
|
# exec zsh
|
||||||
|
# '';
|
||||||
|
# };
|
||||||
packages.${system} = let
|
packages.${system} = let
|
||||||
scanbuddy = pkgs.writeShellApplication {
|
scanbuddy = pkgs.writeShellApplication {
|
||||||
name = "scanbuddy-script";
|
name = "scanbuddy";
|
||||||
|
|
||||||
runtimeInputs = with pkgs; [sane-backends brscan5 ghostscript];
|
runtimeInputs = with pkgs; [sane-backends brscan5 ghostscript];
|
||||||
|
|
||||||
text = builtins.readFile ./scanbuddy.bash;
|
text = builtins.readFile ./scanbuddy.bash;
|
||||||
};
|
};
|
||||||
wrapper = pkgs.writeShellApplication {
|
|
||||||
name = "scanbuddy-wrapper";
|
|
||||||
|
|
||||||
text =
|
# Returns an attribute set that can be passed to `buildPythonPackage`.
|
||||||
/*
|
attrs = serverProject.renderers.buildPythonPackage {inherit python;};
|
||||||
bash
|
server = python.pkgs.buildPythonPackage (attrs
|
||||||
*/
|
// {
|
||||||
''
|
env.CUSTOM_ENVVAR = "foobar";
|
||||||
#!/usr/bin/env bash
|
});
|
||||||
readarray -d '_' args < <(printf "%s" "$1")
|
|
||||||
|
|
||||||
scanbuddy "''${args[@]}"
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
package = pkgs.symlinkJoin {
|
|
||||||
name = "scanbuddy";
|
|
||||||
paths = [scanbuddy wrapper];
|
|
||||||
};
|
|
||||||
in {
|
in {
|
||||||
default = package;
|
default = pkgs.symlinkJoin {
|
||||||
|
name = "scanbuddy";
|
||||||
|
paths = [scanbuddy server];
|
||||||
|
};
|
||||||
inherit scanbuddy;
|
inherit scanbuddy;
|
||||||
inherit wrapper;
|
inherit server;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
pyproject.toml
Normal file
14
pyproject.toml
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
[project]
|
||||||
|
name = "scanbuddy-server"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "A REST server for the scanbuddy shell-script"
|
||||||
|
|
||||||
|
# define any Python dependencies
|
||||||
|
dependencies = [
|
||||||
|
"flask>3",
|
||||||
|
]
|
||||||
|
|
||||||
|
# define the CLI executable
|
||||||
|
# Here, we define the entry point to be the 'main()' function in the module 'app/main.py'
|
||||||
|
[project.scripts]
|
||||||
|
scanbuddy-server = "server.server:main"
|
||||||
52
server.py
52
server.py
|
|
@ -1,52 +0,0 @@
|
||||||
#!/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__)
|
|
||||||
|
|
||||||
@app.route("/")
|
|
||||||
def hello_world():
|
|
||||||
return "Hello, World! Yoyoyo"
|
|
||||||
|
|
||||||
@app.route("/scan")
|
|
||||||
def scan():
|
|
||||||
command = ["bash", f"{os.getcwd()}/scanbuddy.bash", "scan"]
|
|
||||||
|
|
||||||
command += ["-d"] if (request.args.get("duplex", "n") == 'y') else []
|
|
||||||
|
|
||||||
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():
|
|
||||||
command = ["bash", f"{os.getcwd()}/scanbuddy.bash", "dispatch"]
|
|
||||||
user = request.args.get("user", "")
|
|
||||||
|
|
||||||
result = subprocess.run(command, stdout=subprocess.PIPE, text=True)
|
|
||||||
output = result.stdout.strip()
|
|
||||||
|
|
||||||
print("Scanbuddy output: ")
|
|
||||||
print(output)
|
|
||||||
|
|
||||||
return "Dispatching..."
|
|
||||||
|
|
||||||
@app.route("/unscan")
|
|
||||||
def unscan():
|
|
||||||
return "Unscanning..."
|
|
||||||
|
|
||||||
def create_app():
|
|
||||||
return app
|
|
||||||
|
|
||||||
if __name__=='__main__':
|
|
||||||
from waitress import serve
|
|
||||||
serve(app, host="0.0.0.0", port=8080)
|
|
||||||
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