whooops, broke that.

This commit is contained in:
brent s 2019-11-12 02:43:56 -05:00
parent f769344ad9
commit 1c1ac6f5de
1 changed files with 8 additions and 12 deletions

View File

@ -1,6 +1,6 @@
import datetime
import os
import subprocess
# import tempfile
##
import git
from flask import render_template, make_response, request, Response
@ -8,6 +8,9 @@ from flask import render_template, make_response, request, Response
from app import app


# statfile = tempfile.mkstemp(prefix = '.aif-site.')[1]


repo_path = '/srv/python/aif_ng'
repo_uri = '/opt/git/repositories/aif-ng.git'
branch = 'v2_rewrite'
@ -21,21 +24,16 @@ else:

def chkbranch(ref_param = None):
oldhead = repo.head.ref
repo.remotes.origin.fetch()
if not ref_param:
ref = branch
else:
ref = ref_param

if not ref_param:
if repo.active_branch.name != branch:
repo.git.checkout(branch)
else:
repo.git.checkout(ref)
lastcommit = repo.head.commit.authored_datetime
now = datetime.datetime.now(datetime.timezone.utc)
if (now - lastcommit) > datetime.timedelta(hours = update_hours):
print('Fetching update. Current HEAD: {0}'.format(repo.head.commit.hexsha))
repo.remotes.origin.fetch()
return(oldhead)


@ -43,8 +41,7 @@ def chkbranch(ref_param = None):
def index():
oldref = chkbranch(ref_param = request.args.get('ref'))
docsdir = os.path.join(repo_path, 'docs')
# TODO: is this in the right place? it used to be after the subprocess call.
oldref.checkout()
docspath = os.path.join(docsdir, 'MANUAL.adoc')
for fname in ('MANUAL', 'README'):
fpath = os.path.join(docsdir, '{0}.adoc'.format(fname))
if os.path.isfile(fpath):
@ -54,17 +51,16 @@ def index():
docspath,
'-o', '-'],
stdout = subprocess.PIPE)
oldref.checkout()
return(cmd.stdout.decode('utf-8'))


@app.route('/aif.xsd', methods = ['GET'])
def xsd():
oldref = chkbranch(ref_param = request.args.get('ref'))
# TODO: is this in the right place? it used to be after the resp.headers i think.
oldref.checkout()
with open(os.path.join(repo_path, 'aif.xsd'), 'r') as fh:
xsd_raw = fh.read()
resp = Response(xsd_raw)
resp.headers['content-type'] = 'text/xml'
oldref.checkout()
return(resp)