master
km0 3 years ago
commit e9ffb5d3e3

17
.gitignore vendored

@ -0,0 +1,17 @@
venv/
*.pyc
__pycache__/
.ipynb_checkpoints
instance/
.pytest_cache/
.coverage
htmlcov/
dist/
build/
*.egg-info/
.env

@ -0,0 +1,3 @@
{
"python.formatting.provider": "black"
}

@ -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

@ -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", "")
)

@ -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"

@ -0,0 +1,5 @@
from pygit2 import clone_repository
def clone_repo(repo_url, repo_path):
repo = clone_repository(repo_url, repo_path)

@ -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"

@ -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()]

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

@ -0,0 +1,10 @@
from setuptools import find_packages, setup
setup(
name="postit",
version="1.0.0",
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=["flask", "python-dotenv", "pygit2"],
)
Loading…
Cancel
Save