diff --git a/app.py b/app.py index cd54065..04198f4 100755 --- a/app.py +++ b/app.py @@ -11,7 +11,7 @@ import hashlib import fnmatch from distutils.dir_util import copy_tree -from flask import Flask, render_template, request, send_from_directory, render_template_string, jsonify +from flask import Flask, render_template, request, send_from_directory, render_template_string, jsonify, redirect from threading import Thread, Lock import sys import re @@ -97,14 +97,14 @@ def run_git(cmd, cwd): app.logger.info("Running git: %s" % ' '.join(cmd)) return subprocess.run(cmd, cwd=cwd, shell=False) -def get_git_hash(branch): - app.logger.info("Running git rev-parse %s in %s" % (branch, sourcedir)) - return subprocess.check_output(['git', 'rev-parse', branch], cwd=sourcedir, encoding='utf-8', shell=False).rstrip() +def get_git_hash(branch, cwd): + app.logger.info("Running git rev-parse %s in %s" % (branch, cwd)) + return subprocess.check_output(['git', 'rev-parse', branch], cwd=cwd, encoding='utf-8', shell=False).rstrip() -def on_branch(branch): - git_hash_target = get_git_hash(branch) +def on_branch(branch, cwd): + git_hash_target = get_git_hash(branch, cwd) app.logger.info("Expected branch git-hash '%s'" % git_hash_target) - git_hash_current = get_git_hash('HEAD') + git_hash_current = get_git_hash('HEAD', cwd) app.logger.info("Current branch git-hash '%s'" % git_hash_current) return git_hash_target == git_hash_current @@ -119,7 +119,7 @@ def checkout_branch(targetBranch, s_dir, fetch_and_reset=False, temp_branch_name app.logger.error("Checkout requested for an invalid branch") return None remote = targetBranch.split('/', 1)[0] - if not on_branch(targetBranch): + if not on_branch(targetBranch, cwd=s_dir): app.logger.info("Checking out to %s branch" % targetBranch) run_git(['git', 'checkout', targetBranch], cwd=s_dir) if fetch_and_reset: @@ -128,7 +128,7 @@ def checkout_branch(targetBranch, s_dir, fetch_and_reset=False, temp_branch_name if temp_branch_name is not None: delete_branch(temp_branch_name, s_dir=s_dir) # delete temp branch if it already exists run_git(['git', 'checkout', '-b', temp_branch_name, targetBranch], cwd=s_dir) # creates new temp branch - git_hash = get_git_hash('HEAD') + git_hash = get_git_hash('HEAD', cwd=s_dir) return git_hash def clone_branch(targetBranch, sourcedir, out_dir, temp_branch_name): @@ -584,7 +584,7 @@ def generate(): os.path.join(outdir_parent, 'extra_hwdef.dat')) os.remove(os.path.join(outdir_parent, 'extra_hwdef.dat')) - new_git_hash = get_git_hash(chosen_branch) + new_git_hash = get_git_hash(chosen_branch, sourcedir) git_hash_short = new_git_hash[:10] app.logger.info('Git hash = ' + new_git_hash) selected_features_dict['git_hash_short'] = git_hash_short @@ -640,8 +640,8 @@ def generate(): base_url = request.url_root app.logger.info(base_url) - app.logger.info('Rendering index.html') - return render_template('index.html', token=token) + app.logger.info('Redirecting to /') + return redirect('/'+token) except Exception as ex: app.logger.error(ex) @@ -668,11 +668,15 @@ def filter_build_options_by_category(build_options, category): def parse_build_categories(build_options): return sorted(list(set([f.category for f in build_options]))) -@app.route('/') -def home(): +GIT_VERSION_SHORT = get_git_hash('HEAD', os.path.abspath(os.path.dirname(__file__)))[:10] + +@app.route('/', defaults={'token': None}, methods=['GET']) +@app.route('/', methods=['GET']) +def home(token): + if token: + app.logger.info("Showing log for build id " + token) app.logger.info('Rendering index.html') - return render_template('index.html', - token=None) + return render_template('index.html', token=token, app_git_version=GIT_VERSION_SHORT) @app.route("/builds/") def download_file(name): diff --git a/templates/index.html b/templates/index.html index 92c89ac..c22ee62 100644 --- a/templates/index.html +++ b/templates/index.html @@ -64,10 +64,13 @@ | Source: Ardupilot/CustomBuild + | + Git Version: + {{ app_git_version }} - To try out the newest features of the app, please visit our beta server - custom-beta.ardupilot.org + To try out the newest features of the app, please visit our + beta server