whooops, broke that.
This commit is contained in:
parent
f769344ad9
commit
1c1ac6f5de
20
app/views.py
20
app/views.py
@ -1,6 +1,6 @@
|
|||||||
import datetime
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
# import tempfile
|
||||||
##
|
##
|
||||||
import git
|
import git
|
||||||
from flask import render_template, make_response, request, Response
|
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
|
from app import app
|
||||||
|
|
||||||
|
|
||||||
|
# statfile = tempfile.mkstemp(prefix = '.aif-site.')[1]
|
||||||
|
|
||||||
|
|
||||||
repo_path = '/srv/python/aif_ng'
|
repo_path = '/srv/python/aif_ng'
|
||||||
repo_uri = '/opt/git/repositories/aif-ng.git'
|
repo_uri = '/opt/git/repositories/aif-ng.git'
|
||||||
branch = 'v2_rewrite'
|
branch = 'v2_rewrite'
|
||||||
@ -21,21 +24,16 @@ else:
|
|||||||
|
|
||||||
def chkbranch(ref_param = None):
|
def chkbranch(ref_param = None):
|
||||||
oldhead = repo.head.ref
|
oldhead = repo.head.ref
|
||||||
|
repo.remotes.origin.fetch()
|
||||||
if not ref_param:
|
if not ref_param:
|
||||||
ref = branch
|
ref = branch
|
||||||
else:
|
else:
|
||||||
ref = ref_param
|
ref = ref_param
|
||||||
|
|
||||||
if not ref_param:
|
if not ref_param:
|
||||||
if repo.active_branch.name != branch:
|
if repo.active_branch.name != branch:
|
||||||
repo.git.checkout(branch)
|
repo.git.checkout(branch)
|
||||||
else:
|
else:
|
||||||
repo.git.checkout(ref)
|
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)
|
return(oldhead)
|
||||||
|
|
||||||
|
|
||||||
@ -43,8 +41,7 @@ def chkbranch(ref_param = None):
|
|||||||
def index():
|
def index():
|
||||||
oldref = chkbranch(ref_param = request.args.get('ref'))
|
oldref = chkbranch(ref_param = request.args.get('ref'))
|
||||||
docsdir = os.path.join(repo_path, 'docs')
|
docsdir = os.path.join(repo_path, 'docs')
|
||||||
# TODO: is this in the right place? it used to be after the subprocess call.
|
docspath = os.path.join(docsdir, 'MANUAL.adoc')
|
||||||
oldref.checkout()
|
|
||||||
for fname in ('MANUAL', 'README'):
|
for fname in ('MANUAL', 'README'):
|
||||||
fpath = os.path.join(docsdir, '{0}.adoc'.format(fname))
|
fpath = os.path.join(docsdir, '{0}.adoc'.format(fname))
|
||||||
if os.path.isfile(fpath):
|
if os.path.isfile(fpath):
|
||||||
@ -54,17 +51,16 @@ def index():
|
|||||||
docspath,
|
docspath,
|
||||||
'-o', '-'],
|
'-o', '-'],
|
||||||
stdout = subprocess.PIPE)
|
stdout = subprocess.PIPE)
|
||||||
|
oldref.checkout()
|
||||||
return(cmd.stdout.decode('utf-8'))
|
return(cmd.stdout.decode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/aif.xsd', methods = ['GET'])
|
@app.route('/aif.xsd', methods = ['GET'])
|
||||||
def xsd():
|
def xsd():
|
||||||
oldref = chkbranch(ref_param = request.args.get('ref'))
|
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:
|
with open(os.path.join(repo_path, 'aif.xsd'), 'r') as fh:
|
||||||
xsd_raw = fh.read()
|
xsd_raw = fh.read()
|
||||||
resp = Response(xsd_raw)
|
resp = Response(xsd_raw)
|
||||||
resp.headers['content-type'] = 'text/xml'
|
resp.headers['content-type'] = 'text/xml'
|
||||||
|
oldref.checkout()
|
||||||
return(resp)
|
return(resp)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user