From e9ffb5d3e3a7f48b4a42980e682b21c4839e2afc Mon Sep 17 00:00:00 2001 From: Francesco Luzzana Date: Sat, 12 Mar 2022 21:50:58 +0100 Subject: [PATCH] init --- .gitignore | 17 +++++++++++++++++ .vscode/settings.json | 3 +++ config.py | 18 ++++++++++++++++++ postit/__init__.py | 0 postit/app.py | 36 ++++++++++++++++++++++++++++++++++++ postit/contents.py | 23 +++++++++++++++++++++++ postit/git.py | 5 +++++ postit/home.py | 8 ++++++++ postit/prefix.py | 14 ++++++++++++++ postit/static/favicon.ico | Bin 0 -> 15406 bytes setup.py | 10 ++++++++++ 11 files changed, 134 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 config.py create mode 100644 postit/__init__.py create mode 100644 postit/app.py create mode 100644 postit/contents.py create mode 100644 postit/git.py create mode 100644 postit/home.py create mode 100644 postit/prefix.py create mode 100644 postit/static/favicon.ico create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d9011c2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +venv/ + +*.pyc +__pycache__/ +.ipynb_checkpoints + +instance/ + +.pytest_cache/ +.coverage +htmlcov/ + +dist/ +build/ +*.egg-info/ + +.env \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0ceb6db --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.formatting.provider": "black" +} diff --git a/config.py b/config.py new file mode 100644 index 0000000..745f39b --- /dev/null +++ b/config.py @@ -0,0 +1,18 @@ +import os + + +class Config(object): + DEBUG = False + TESTING = False + URL_PREFIX = "" + + +class ProductionConfig(Config): + DEBUG = False + URL_PREFIX = os.environ.get("URL_PREFIX") + + +class DevelopmentConfig(Config): + ENV = "development" + DEVELOPMENT = True + DEBUG = True diff --git a/postit/__init__.py b/postit/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/postit/app.py b/postit/app.py new file mode 100644 index 0000000..e056e48 --- /dev/null +++ b/postit/app.py @@ -0,0 +1,36 @@ +import os +from flask import Flask, send_from_directory +from . import prefix + + +def create_app(test_config=None): + # Create and configure the Flask App + app = Flask(__name__, instance_relative_config=True) + app.config.from_mapping( + SECRET_KEY="dev", + ) + + if test_config is None: + # load the instance config, if it exists, when not testing + app.config.from_pyfile("config.py", silent=True) + else: + # load the test config if passed in + app.config.from_mapping(test_config) + + # ensure the instance folder exists + try: + os.makedirs(app.instance_path) + except OSError: + pass + + @app.route("/favicon.ico") + def favicon(): + return send_from_directory( + os.path.join(app.root_path, "static"), + "favicon.ico", + mimetype="image/vnd.microsoft.icon", + ) + + app.wsgi_app = prefix.PrefixMiddleware( + app.wsgi_app, prefix=os.environ.get("URL_PREFIX", "") + ) diff --git a/postit/contents.py b/postit/contents.py new file mode 100644 index 0000000..e646a73 --- /dev/null +++ b/postit/contents.py @@ -0,0 +1,23 @@ +import os +from shutil import rmtree +from flask import Blueprint, render_template, request, url_for +from . import git + +repo_url = os.environ.get("REPO_URL") +repo_path = os.environ.get("REPO_PATH") + + +bp = Blueprint("contents", __name__, url_prefix="/contents") + + +@bp.route("/", method=("GET", "POST")) +def contents(): + if request.method == "POST": + print(request) + if request.form.get("secret") == os.environ.get("REPO_SECRET"): + print("Updating the contents!") + print("Cleaning the folder") + rmtree(repo_path) + print("Cloning the repo") + git.clone_repo(repo_url, repo_path) + return "Hello" diff --git a/postit/git.py b/postit/git.py new file mode 100644 index 0000000..11c2654 --- /dev/null +++ b/postit/git.py @@ -0,0 +1,5 @@ +from pygit2 import clone_repository + + +def clone_repo(repo_url, repo_path): + repo = clone_repository(repo_url, repo_path) diff --git a/postit/home.py b/postit/home.py new file mode 100644 index 0000000..06096c8 --- /dev/null +++ b/postit/home.py @@ -0,0 +1,8 @@ +from flask import Blueprint, render_template, request, url_for + +bp = Blueprint("home", __name__, url_prefix="/") + + +@bp.route("/") +def home(): + return "Home" diff --git a/postit/prefix.py b/postit/prefix.py new file mode 100644 index 0000000..a94e608 --- /dev/null +++ b/postit/prefix.py @@ -0,0 +1,14 @@ +class PrefixMiddleware(object): + def __init__(self, app, prefix=""): + self.app = app + self.prefix = prefix + + def __call__(self, environ, start_response): + + if environ["PATH_INFO"].startswith(self.prefix): + environ["PATH_INFO"] = environ["PATH_INFO"][len(self.prefix) :] + environ["SCRIPT_NAME"] = self.prefix + return self.app(environ, start_response) + else: + start_response("404", [("Content-Type", "text/plain")]) + return ["This url does not belong to the app.".encode()] diff --git a/postit/static/favicon.ico b/postit/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..e6a3bb9f8fa5298716d1e3b223a859559ff323ed GIT binary patch literal 15406 zcmeHOYfKzf6dodC;8$@U6?O&oSy)4+`MxmCnh?Js|7!~L)wLc&>C^4o{Q{xXio>?eMbYOeg>ujhq$(Ox5 zGw0qjXU;kI+;h(mLe~qUX`e*pVp#} zPN-z_$Wy$?r_Zte=%pHJp0R(U`~GA)^8(W~ zlgfuDEiS+M6ZrF&{T3NVw(ucmfB!Xq?@y6X^{2Jz;us%H6~lk{qYs3C&VFN)taYpD zZ=QLmIx3;2ezoiCInVi-IKU$S&Of0ZWXHsvjD1FFtURMM7??0r`dy4G)L80LrWoH+ zYPFSjq0-x&o?ct0hmB3DWuz_D2^}SqYDM3N@3m;G7djH`6ScqGYu)FYG zZ2HgHAH+RKz-fQ?Zmqd&bIuf?pr~r(TU_!N^*_k-pPHJM=`HCf$SplPf${w>#sOR` zaEo}f@EvUS7r*led$4T+2~XFJU>hIi{@Dhn+lqpsnvofd@(*hKCE7prHQ%~(t#f6*YiL&#k`?cY72CRF7g^>+fBz&}?c@k(%ADSkL+!mEVne zKbI$g6fN;QU_E&fAX{;;AxtkD#&k?XkjzAcc8@pj5whZjfSV>}GAxJuFoJ_tdyLDg zVC&!3J(UP+?AAudB}ZmqyF;!uACv2=k^*LWse^oKSZAcqHv=3yGFu%|t@*e_Z+;M0 z|27Bk?sVVa@-_-X6*p(xkZY*darF;2-2i!=zc{;AB-VQSmu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