Created
September 3, 2013 16:32
-
-
Save ColonelThirtyTwo/6426242 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
import subprocess | |
import os | |
import cgi | |
import cgitb | |
from time import asctime as curtime | |
cgitb.enable(display=0, logdir="/var/log/cgitb", format="text") | |
# Log file | |
LOG_FILE = "/var/log/gitrepo_doc" | |
# Path to repository, used by git pull | |
REPO_PATH = "/srv/www/Starfall/" | |
# Path to the source code. This is the path fed into LuaDoc | |
CODE_PATH = REPO_PATH+"/lua/starfall" | |
DOCFILES_PATH = REPO_PATH+"/docgen/" | |
# Output of documentation | |
DOCUMENT_OUTPUT = "/srv/www/htdocs/sfdoc/" | |
# Branch to document. Make sure this is the same as the branch checked out in the repo. | |
# This script will not update documentation unless a commit is made to this branch. | |
DOC_BRANCH = "refs/heads/develop" | |
# Add whatever args you want here | |
GIT_PULL_ARGS = ["git", "--git-dir="+REPO_PATH+"/.git", "--work-tree="+REPO_PATH, "pull", "-q"] | |
LUADOC_ARGS = ["lua5.1", "build_docs.lua", DOCUMENT_OUTPUT] | |
def git_pull(stderr): | |
""" | |
Runs git pull to update the repository | |
""" | |
subprocess.check_call(GIT_PULL_ARGS, stderr=stderr) | |
def luadoc(stderr): | |
""" | |
Runs luadoc to generate documentation | |
""" | |
subprocess.check_call(LUADOC_ARGS, stderr=stderr, stdout=stderr, cwd=DOCFILES_PATH) | |
def parse_post(): | |
data = cgi.FieldStorage()["payload"].value | |
return json.loads(data) | |
def log(f, str): | |
f.write("%s: %s\n" % (curtime(), str)) | |
if __name__ == "__main__": | |
logfile = open(LOG_FILE, "a", 1) | |
try: | |
pushdata = parse_post() | |
if pushdata["ref"] == DOC_BRANCH: | |
log(logfile, "Recieved github update, building documentation.") | |
try: | |
git_pull(logfile) | |
luadoc(logfile) | |
except subprocess.CalledProcessError as err: | |
log(logfile, "Error building docs: %s returned status code %d" % (err.cmd, err.returncode)) | |
else: | |
log(logfile, "Successfully built documentation") | |
else: | |
log(logfile, "Ignoring github update for ref %s" % (pushdata["ref"])) | |
finally: | |
logfile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment