]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
templates: Add Patchwork version
authorStephen Finucane <stephen@that.guru>
Sat, 19 Nov 2016 18:31:34 +0000 (18:31 +0000)
committerStephen Finucane <stephen@that.guru>
Wed, 1 Mar 2017 22:11:05 +0000 (22:11 +0000)
This is managed using a combination of hardcoded string, for
installations from tarball, and 'git describe', for installations from
a Git repo.

This includes installing Git in the Docker environment, to enable this
in the development environment.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Acked-by: Daniel Axtens <dja@axtens.net>
patchwork/__init__.py
patchwork/context_processors.py
patchwork/settings/base.py
patchwork/templates/patchwork/about.html
patchwork/version.py [new file with mode: 0644]
templates/base.html
tools/docker/Dockerfile

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..f82d7111a3aaf8c111703e3a55ee0e67772dd324 100644 (file)
@@ -0,0 +1,24 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2016 Stephen Finucane <stephen@that.guru>
+#
+# This file is part of the Patchwork package.
+#
+# Patchwork is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Patchwork is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Patchwork; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+from patchwork.version import get_latest_version
+
+VERSION = (2, 0, 0, 'alpha', 0)
+
+__version__ = get_latest_version(VERSION)
index 8f1de9e05518c6afc19cda74eb31c56c1cd50d19..b021b3118d5a9fed364d7a19b92faccf9cc2b54e 100644 (file)
 
 from django.contrib.sites.models import Site
 
+import patchwork
+
 
 def site(request):
     return {'site': Site.objects.get_current()}
+
+
+def version(request):
+    return {'version': patchwork.__version__}
index 67373502252eb38b51ec9a96a92617a818c6e100..180a4691a248829c1465729adb4497813df01d0d 100644 (file)
@@ -70,6 +70,7 @@ if django.VERSION >= (1, 8):
                     'django.template.context_processors.tz',
                     'django.contrib.messages.context_processors.messages',
                     'patchwork.context_processors.site',
+                    'patchwork.context_processors.version',
                 ],
             },
         },
@@ -85,6 +86,7 @@ else:
         'django.core.context_processors.tz',
         'django.contrib.messages.context_processors.messages',
         'patchwork.context_processors.site',
+        'patchwork.context_processors.version',
     ]
 
 
index e087f7cf35e6c58dca5e06d0f1b7cdcaf7a758f7..f602c1351b56743e9baee3efdf8f83469154e28c 100644 (file)
@@ -21,7 +21,7 @@
     </div>
     <ul class="list-group">
       <li class="list-group-item">
-        <p>2.0.0-pre</p>
+        <p>{{ version }}</p>
       </li>
     </ul>
   </div>
diff --git a/patchwork/version.py b/patchwork/version.py
new file mode 100644 (file)
index 0000000..212d8d3
--- /dev/null
@@ -0,0 +1,63 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2016 Stephen Finucane <stephen@that.guru>
+#
+# This file is part of the Patchwork package.
+#
+# Patchwork is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Patchwork is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Patchwork; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import subprocess
+import os
+
+
+ROOT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)),
+                        os.pardir)
+
+
+def get_latest_version(version):
+    """Returns the most recent version available.
+
+    This is either the hard-coded version or, if using Git, the version
+    per the most recent Git tag.
+    """
+    git_version = format_git_version(get_raw_git_version())
+    str_version = format_version(version)
+
+    return git_version or str_version
+
+
+def format_version(version):
+    """Format version tuple."""
+    return '.'.join(['.'.join([str(x) for x in version[:3]]),
+                     '-'.join([str(x) for x in version[3:]])])
+
+
+def format_git_version(version):
+    """Returns a version based on Git tags."""
+    if '-' in version:  # after tag
+        # convert version-N-githash to version.postN-githash
+        return version.replace('-', '.post', 1)
+    else:  # at tag
+        return version
+
+
+def get_raw_git_version():
+    """Returns the raw git version via 'git-describe'."""
+    try:
+        git_version = subprocess.check_output(['git', 'describe'],
+                                              cwd=ROOT_DIR)
+    except (OSError, FileNotFoundError):
+        return ''
+
+    return git_version.strip().decode('utf-8')
index 8045b51641e39d669574e72c7c8bc49a5cae20ae..d0f59b450bc4ff251539ca6fa540ef8d4f99f4dd 100644 (file)
   </div>
   <div id="footer">
    <a href="http://jk.ozlabs.org/projects/patchwork/">patchwork</a>
-   patch tracking system | <a
+   patch tracking system | version {{version}} | <a
    href="{% url 'about' %}">about patchwork</a>
   </div>
  </body>
index 883d43ab839f93bcef6134b370b59e4497135c9f..ff05707a60490da6edd0f268f68465193cbcfe44 100644 (file)
@@ -21,7 +21,7 @@ RUN apt-get update -qq && \
     python3.5-dev python3-pip python3-setuptools python3-wheel \
     python3.4-dev findutils=4.4.2-7 \
     libmysqlclient-dev mysql-client curl unzip xvfb chromium-chromedriver \
-    chromium-browser build-essential && \
+    chromium-browser build-essential git && \
     ln -s /usr/lib/chromium-browser/chromedriver /usr/bin/
 
 # User