From a71684ea0f7f64543ae54954f584d5b89a087558 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 30 Jan 2014 20:42:15 +0100 Subject: [PATCH] Add version() to utils to get version/about infos --- qutebrowser/__init__.py | 3 ++ qutebrowser/utils/__init__.py | 52 ++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/qutebrowser/__init__.py b/qutebrowser/__init__.py index 9fd897bf0..6f8d11c4d 100644 --- a/qutebrowser/__init__.py +++ b/qutebrowser/__init__.py @@ -12,3 +12,6 @@ Subpackages: utils - Misc utility code. widgets - Qt widgets displayed on the screen. """ + +__version_info__ = (0, 0, 0) +__version__ = '.'.join(map(str, __version_info__)) diff --git a/qutebrowser/utils/__init__.py b/qutebrowser/utils/__init__.py index ad90b39d6..34d64bb7b 100644 --- a/qutebrowser/utils/__init__.py +++ b/qutebrowser/utils/__init__.py @@ -1,8 +1,14 @@ """Utility functions""" import re +import sys +import os.path +import platform +import subprocess -from PyQt5.QtCore import QUrl +from PyQt5.QtCore import QUrl, QT_VERSION_STR, PYQT_VERSION_STR, qVersion + +import qutebrowser def qurl(url): @@ -12,3 +18,47 @@ def qurl(url): if not re.match(r'^\w+://', url): url = 'http://' + url return QUrl(url) + + +def version(): + """Return a string with various version informations.""" + if sys.platform == 'linux': + osver = ', '.join((platform.dist())) + elif sys.platform == 'win32': + osver = ', '.join((platform.win32_ver())) + elif sys.platform == 'darwin': + osver = ', '.join((platform.mac_ver())) + else: + osver = '?' + + gitver = _git_str() + + lines = [ + 'qutebrowser v{}\n\n'.format(qutebrowser.__version__), + 'Python {}\n'.format(platform.python_version()), + 'Qt {}, runtime {}\n'.format(QT_VERSION_STR, qVersion()), + 'PyQt {}\n\n'.format(PYQT_VERSION_STR), + 'Platform: {}, {}\n'.format(platform.platform(), + platform.architecture()[0]), + 'OS Version: {}\n'.format(osver), + ] + + if gitver is not None: + lines.append('\nGit commit: {}'.format(gitver)) + + return ''.join(lines) + + +def _git_str(): + """Try to find out git version and return a string if possible. + + Return None if there was an error or we're not in a git repo. + """ + # FIXME this runs in PWD, not the qutebrowser dir?! + if not os.path.isdir(".git"): + return None + try: + return subprocess.check_output(['git', 'describe', '--tags', '--dirty', + '--always']).decode('UTF-8').strip() + except (subprocess.CalledProcessError, FileNotFoundError): + return None