gitea-webhook-commander/hook.py

43 lines
927 B
Python
Raw Normal View History

2022-11-21 22:33:50 +00:00
#!/usr/bin/python3.9
from flask import request, Flask
from flask.logging import logging
2022-11-22 08:48:54 +00:00
from flask import request
import subprocess
import os
import json
2022-11-21 22:33:50 +00:00
# Setup the Flask web app.
app = Flask("thing")
commands={
}
2023-03-31 16:32:31 +01:00
def initCommands(file):
global commands
2023-03-31 16:34:00 +01:00
commands = json.loads(open(file, "r").read())
2022-11-21 22:33:50 +00:00
@app.route("/build/<site>", methods=["POST"])
def buildHandler(site):
2022-11-22 08:48:54 +00:00
print("Requesting an automatic rebuild of '%s'"%(site))
# Extract the correct mapping
item=commands[site]
itemDir=item["dir"]
itemPreCommand=item["pre-command"]
itemCommand=item["command"]
# Change directory to the item's CWD
os.chdir(itemDir)
2022-11-21 22:33:50 +00:00
2022-11-22 08:48:54 +00:00
# Call the pre-command followed by the command
subprocess.call(itemPreCommand)
subprocess.call(itemCommand)
2022-11-21 22:33:50 +00:00
2022-11-22 08:48:54 +00:00
# The deadline will probably be exceeded but flask
# wants this here
2022-11-22 15:06:38 +00:00
return "Ok"
2022-11-21 22:33:50 +00:00
initCommands("/home/pi/HDD/temp/gitea-webhook-commander/commands.json")
2023-12-20 16:53:06 +00:00
app.run(host="::")