Add get_app_version and version

This commit is contained in:
Jesús 2020-12-17 15:31:11 -05:00
parent 5edcaa4f9d
commit a7c1f2a34e
No known key found for this signature in database
GPG Key ID: F6EE7BC59A315766
5 changed files with 68 additions and 1 deletions

View File

@ -1,4 +1,5 @@
from youtube import util
from .get_app_version import app_version
import flask
from flask import request
import settings
@ -32,6 +33,10 @@ def inject_theme_preference():
return {
'theme_path': '/youtube.com/static/' + theme_names[settings.theme] + '.css',
'settings': settings,
# Detect version
'current_version': app_version()['version'],
'current_branch': app_version()['branch'],
'current_commit': app_version()['commit'],
}

View File

@ -0,0 +1 @@
from .get_app_version import *

View File

@ -0,0 +1,54 @@
from __future__ import unicode_literals
from subprocess import (
call,
STDOUT
)
from ..version import __version__
import os
import subprocess
def app_version():
def minimal_env_cmd(cmd):
# make minimal environment
env = {}
for k in ['SYSTEMROOT', 'PATH']:
v = os.environ.get(k)
if v is not None:
env[k] = v
env['LANGUAGE'] = 'C'
env['LANG'] = 'C'
env['LC_ALL'] = 'C'
out = subprocess.Popen(
cmd, stdout=subprocess.PIPE, env=env).communicate()[0]
return out
if call(["git", "branch"], stderr=STDOUT,
stdout=open(os.devnull, 'w')) != 0:
subst_list = {
"version": __version__,
"branch": None,
"commit": None
}
else:
# version
describe = minimal_env_cmd(["git", "describe", "--always"])
git_revision = describe.strip().decode('ascii')
# branch
branch = minimal_env_cmd(["git", "branch"])
git_branch = branch.strip().decode('ascii').replace('* ', '')
subst_list = {
"version": __version__,
"branch": git_branch,
"commit": git_revision
}
return subst_list
if __name__ == "__main__":
app_version()

View File

@ -231,7 +231,11 @@
</main>
<footer class="footer">
<p>This site is Free/Libre Software</p>
<p>Current version: 3304bab @ master</p>
{% if current_commit and current_version %}
<p>Current version: {{ current_version }}-{{ current_commit }} @ {{ current_branch }}</p>
{% else %}
<p>Current version: {{ current_version }}</p>
{% endif %}
</footer>
</body>

3
youtube/version.py Normal file
View File

@ -0,0 +1,3 @@
from __future__ import unicode_literals
__version__ = '0.1.0'