From afa7cf782d02641fdd6b71d849e040d3ddd5f370 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Thu, 30 Dec 2021 21:18:12 +0100 Subject: [PATCH 1/2] Switched to environment variables --- app.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index 9d6a38c..82664c0 100644 --- a/app.py +++ b/app.py @@ -4,8 +4,8 @@ from pathlib import Path from werkzeug.utils import secure_filename import subprocess -UPLOAD_FOLDER = './data' -API_KEY = 'yeet' +UPLOAD_FOLDER = Path(os.environ['REPO_DIR']) / "pkgs" +API_KEY = os.environ['API_KEY'] ALLOWED_EXTENSIONS = {'pkg.tar.zst', 'pkg.tar.gz'} app = Flask(__name__) @@ -46,7 +46,7 @@ def upload_file(): # Create path for file & check if it already exists filename = secure_filename(file.filename) - path = Path(app.config['UPLOAD_FOLDER']) / 'pkgs' / filename + path = Path(app.config['UPLOAD_FOLDER']) / filename if path.exists(): return {'message': 'File already exists.'}, 400 @@ -57,7 +57,7 @@ def upload_file(): file.save(path) # Run repo-add on the file - res = subprocess.run(["repo-add", path.parent.parent / "repo.db.tar.gz", path]) + res = subprocess.run(["repo-add", path.parent / "repo.db.tar.gz", path]) if res.returncode != 0: path.unlink() @@ -65,4 +65,3 @@ def upload_file(): return {'message': 'Failed to add file to repository.'}, 500 return {'message': 'Success.'}, 200 - From 26b2745e9b8ba2f1f276f0c6f97f58c2942ca6ee Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Thu, 30 Dec 2021 21:29:05 +0100 Subject: [PATCH 2/2] Added Makefile wrapper --- .gitignore | 1 + Makefile | 18 ++++++++++++++++++ requirements.txt | 2 ++ 3 files changed, 21 insertions(+) create mode 100644 Makefile create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index c18dd8d..670a936 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ __pycache__/ +.venv/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..28a244a --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ + # =====CONFIG===== +PYTHON := python3 +VENV := .venv + + +# =====RECIPES===== +# Create the virtual environment +$(VENV)/bin/activate: setup.py + '$(PYTHON)' -m venv '$(VENV)' + '$(VENV)/bin/pip' install -r requirements.txt + +venv: $(VENV)/bin/activate +.PHONY: venv + +# Remove any temporary files +clean: + @ rm -rf '$(VENV)' +.PHONY: clean diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d6aaf48 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask==2.0.2 +gunicorn==20.1.0