From 359d39612326abb8a761a95131f32f9b4d342969 Mon Sep 17 00:00:00 2001 From: Rodolphe Houdas Date: Wed, 18 Aug 2021 08:11:52 +0100 Subject: [PATCH] :tada: First commit --- .dockerignore | 154 ++++++++++++++++++++++++++++++++++++++++++++ .gitignore | 148 ++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 17 +++++ README.md | 0 openscad_remote.py | 41 ++++++++++++ requirements.txt | 1 + tools/uploader.html | 7 ++ uwsgi.ini | 5 ++ 8 files changed, 373 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 openscad_remote.py create mode 100644 requirements.txt create mode 100644 tools/uploader.html create mode 100644 uwsgi.ini diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a8c53e4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,154 @@ +Dockerfile +tools/ +.gitignore +.dockerignore + + + +# Created by https://www.toptal.com/developers/gitignore/api/python +# Edit at https://www.toptal.com/developers/gitignore?templates=python + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# End of https://www.toptal.com/developers/gitignore/api/python + +# VSCode +.vscode \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2b414c3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,148 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/python +# Edit at https://www.toptal.com/developers/gitignore?templates=python + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# End of https://www.toptal.com/developers/gitignore/api/python + +# VSCode +.vscode \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8c75732 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM python:buster + +RUN apt update \ + && apt -y install openscad uwsgi uwsgi-plugin-python3 \ + && apt clean + +WORKDIR /app +COPY requirements.txt /app/requirements.txt + +RUN pip install -r requirements.txt \ + && rm -rf ~/.cache/pip/* \ + && mkdir -p /data/upload \ + && mkdir -p /data/build + +COPY . /app + +ENTRYPOINT [ "uwsgi", "--ini", "uwsgi.ini" ] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/openscad_remote.py b/openscad_remote.py new file mode 100644 index 0000000..d6951f1 --- /dev/null +++ b/openscad_remote.py @@ -0,0 +1,41 @@ +from flask import ( + Flask, + request, + jsonify, + send_file +) +import os +from uuid import uuid4 +import subprocess + +app = Flask(__name__) + + +@app.route("/") +def hello_world(): + return "

Hello, World!

" + + +@app.route("/upload", methods=['POST']) +def upload_file(): + f = request.files['file'] + uuid = uuid4() + filepath = os.path.join("/data/upload", f"{uuid}.scad") + f.save(filepath) + return jsonify({ + "id": uuid + }) + + +@app.route("/generate/") +def generate(id): + subprocess.run([ + "openscad", + "-o", f"/data/build/{id}.stl", + f"/data/upload/{id}.scad" + ]) + return send_file(f"/data/build/{id}.stl") + + +if __name__ == "__main__": + app.run() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9b8d815 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +Flask==2.0.1 \ No newline at end of file diff --git a/tools/uploader.html b/tools/uploader.html new file mode 100644 index 0000000..5ddb2f6 --- /dev/null +++ b/tools/uploader.html @@ -0,0 +1,7 @@ + +Upload new File +

Upload new File

+
+ + +
\ No newline at end of file diff --git a/uwsgi.ini b/uwsgi.ini new file mode 100644 index 0000000..e68286d --- /dev/null +++ b/uwsgi.ini @@ -0,0 +1,5 @@ +[uwsgi] +pythonpath=/usr/local/lib/python3.9/site-packages +http-socket=0.0.0.0:5000 +module=openscad_remote:app +plugin=/usr/lib/uwsgi/plugins/python3_plugin.so \ No newline at end of file