diff --git a/latty.py b/latty.py index 6cb1c5b..408bfc1 100644 --- a/latty.py +++ b/latty.py @@ -11,16 +11,19 @@ def get_unique(): unique = str(uuid.uuid1().hex) return unique + def get_datetime(): from datetime import datetime now = datetime.now() return now.strftime("%Y-%m-%d %H:%M:%S") + root_dir = os.path.dirname(os.getcwd()) proj_dir = root_dir + '/undercover/' output_dir = proj_dir + 'outputs/' base_tex_text = open(proj_dir + "/writing_templates/base.tex", "r").read() + @dataclass class CLData(): username: str @@ -93,5 +96,6 @@ class CLData(): del errors[-2:] return (None, errors) + def cleanup(unique): subprocess.run(['bash', '-c', "rm " + unique + ".*"]) diff --git a/writing.py b/writing.py index 6aec8a3..5c4a2a7 100644 --- a/writing.py +++ b/writing.py @@ -8,6 +8,8 @@ from latty import CLData import flaskr import flaskr.db as db import os +import subprocess +import threading writing_blueprint = Blueprint('writing', __name__,) @@ -82,14 +84,21 @@ def dbtest_get(): def update_get(): if os.environ['GITLAB_HOOK_TOKEN'] == request.headers['X-Gitlab-Token'] and request.headers['X-Gitlab-Event'] == "Push Hook": print("Update notification received.") - # TODO: Git clone response = make_response("", 200) response.mimetype = "text/plain" + threading.Timer(5, git_update, []).start() return response else: return make_response("", 404) +def git_update(): + script = os.environ['UPDATE_SCRIPT_PATH'] + if not script: + return + subprocess.run(['bash', '-c', "test -f " + script + " && " + script]) + + @writing_blueprint.route('/', methods=['POST']) def index_post(): form = CLForm(request.form)