diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2020-03-06 23:26:01 +0100 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2020-03-06 23:26:01 +0100 |
commit | c58e6a72bf9c2f74a84b303a0d78a42235d5cb0f (patch) | |
tree | 7e65c3ded04e993f509075308cc477837d7d3367 | |
parent | Updated README. (diff) | |
download | newspipe-c58e6a72bf9c2f74a84b303a0d78a42235d5cb0f.tar.gz newspipe-c58e6a72bf9c2f74a84b303a0d78a42235d5cb0f.tar.bz2 newspipe-c58e6a72bf9c2f74a84b303a0d78a42235d5cb0f.zip |
Improved method to detect current version of the Newspipe instance.
-rw-r--r-- | newspipe/web/__init__.py | 16 | ||||
-rw-r--r-- | newspipe/web/templates/about_more.html | 2 | ||||
-rw-r--r-- | newspipe/web/views/views.py | 15 |
3 files changed, 30 insertions, 3 deletions
diff --git a/newspipe/web/__init__.py b/newspipe/web/__init__.py index 810d55ce..16d84cc5 100644 --- a/newspipe/web/__init__.py +++ b/newspipe/web/__init__.py @@ -5,4 +5,18 @@ __revision__ = "$Date: 2020/02/27 $" __copyright__ = "Copyright (c) Cedric Bonhomme" __license__ = "GPLv3" -__all__ = [__version__] +import os +import subprocess + +BASE_DIR = os.path.abspath(os.path.dirname(__file__)) + +__version__ = ( + os.environ.get("PKGVER") + or subprocess.run(["git", + "-C", + BASE_DIR, + "describe", + "--tags"], stdout=subprocess.PIPE) + .stdout.decode() + .strip() +) diff --git a/newspipe/web/templates/about_more.html b/newspipe/web/templates/about_more.html index 3b253b25..94a01c07 100644 --- a/newspipe/web/templates/about_more.html +++ b/newspipe/web/templates/about_more.html @@ -2,7 +2,7 @@ {% block content %} <div class="container"> <ul class="list-group"> - <li class="list-group-item">{{ _('Newspipe version') }}: <a href="https://git.sr.ht/~cedric/newspipe/refs/{{newspipe_version}}">{{newspipe_version}}</a></li> + <li class="list-group-item">{{ _('Newspipe version') }}: <a href="{{ version_url }}">{{newspipe_version}}</a></li> <li class="list-group-item">{{ _('Registration') }}: {{registration}}</li> <li class="list-group-item">{{ _('Python version') }}: {{python_version}}</li> <li class="list-group-item">{{ _('Number of users') }}: {{nb_users}}</li> diff --git a/newspipe/web/views/views.py b/newspipe/web/views/views.py index 1fde12c7..e08270cd 100644 --- a/newspipe/web/views/views.py +++ b/newspipe/web/views/views.py @@ -86,9 +86,22 @@ def about(): @current_app.route("/about/more", methods=["GET"]) @etag_match def about_more(): + version = __version__.split("-") + if len(version) == 1: + newspipe_version = version[0] + version_url = "https://git.sr.ht/~cedric/newspipe/refs/{}".format( + version[0] + ) + else: + newspipe_version = "{} - {}".format(version[0], version[2][1:]) + version_url = "https://git.sr.ht/~cedric/newspipe/commit/{}".format( + version[2][1:] + ) + return render_template( "about_more.html", - newspipe_version=__version__.split()[1], + newspipe_version=newspipe_version, + version_url=version_url, registration=[conf.SELF_REGISTRATION and "Open" or "Closed"][0], python_version="{}.{}.{}".format(*sys.version_info[:3]), nb_users=UserController().read().count(), |