Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show git version in app footer #51

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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('/<token>', 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/<path:name>")
def download_file(name):
Expand Down
7 changes: 5 additions & 2 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@
</span>|
<span class="mx-2">Source:
<a href="https://github.com/Ardupilot/CustomBuild" style="text-decoration: underline; color: white;">Ardupilot/CustomBuild</a>
</span>|
<span class="mx-2">Git Version:
<a href="https://github.com/Ardupilot/CustomBuild/commit/{{ app_git_version }}" style="text-decoration: underline; color: white;">{{ app_git_version }}</a>
</span>
</div>
<span>To try out the newest features of the app, please visit our beta server
<a href="https://custom-beta.ardupilot.org" style="text-decoration: underline; color: white;">custom-beta.ardupilot.org</a>
<span>To try out the newest features of the app, please visit our
<a href="https://custom-beta.ardupilot.org" style="text-decoration: underline; color: white;">beta server</a>
</span>
</div>
</div>
Expand Down