diff options
-rwxr-xr-x | bin/genenetwork2 | 5 | ||||
-rw-r--r-- | wqflask/utility/tools.py | 22 |
2 files changed, 21 insertions, 6 deletions
diff --git a/bin/genenetwork2 b/bin/genenetwork2 index d0aa5d71..76afa781 100755 --- a/bin/genenetwork2 +++ b/bin/genenetwork2 @@ -64,16 +64,11 @@ GUIX_SITE=$GN2_BASE_DIR/lib/python3.8/site-packages if [ -d "${GUIX_SITE}" ]; then echo INFO: GN2 is running from GNU Guix GN2_BASE_DIR=$GUIX_SITE - GN_VERSION="${GN2_ID}:$(cat "${GN2_BASE_DIR}"/etc/VERSION)" - export GN_VERSION else echo INFO: GN2 is running from a source tree GIT_HASH=$(git rev-parse HEAD) GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) - GN_VERSION="${GN2_ID}:$(cat "${GN2_BASE_DIR}"/etc/VERSION)-${GIT_BRANCH}-$(echo "${GIT_HASH}" | cut -c1-9)" - export GN_VERSION fi -echo GN_VERSION="${GN_VERSION}" if [ "$1" = "-c" -o "$1" = "-gunicorn" ]; then echo "Can not use $1 switch without default settings file" diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index 2b1f4b8f..aa5bdb04 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -4,6 +4,8 @@ import os import sys import json +import socket +from pathlib import Path from wqflask import app @@ -255,9 +257,27 @@ def show_settings(): print(("%s: %s%s%s%s" % (k, GREEN, BOLD, app.config[k], ENDC)), file=sys.stderr) +def gn_version_repo_info(root_dir): + """retrieve the branch name and abbreviated commit hash.""" + try: + from git import Repo + repo = Repo(root_dir) + return f"{repo.head.ref.name}-{repo.head.commit.hexsha[0:9]}" + except: + return "" + +def gn_version(): + """Compute and return the version of the application.""" + hostname = socket.gethostname() + basedir = Path(__file__).absolute().parent.parent.parent + with open(Path(basedir, "etc", "VERSION"), encoding="utf8") as version_file: + version_contents = version_file.read().strip() + base_version = f"{hostname}:{basedir.name}:{version_contents}" + repo_info = gn_version_repo_info(basedir) + return f"{base_version}-{repo_info}" if bool(repo_info) else base_version # Cached values -GN_VERSION = get_setting('GN_VERSION') +GN_VERSION = gn_version() HOME = get_setting('HOME') SERVER_PORT = get_setting('SERVER_PORT') WEBSERVER_MODE = get_setting('WEBSERVER_MODE') |