Add version() to utils to get version/about infos

This commit is contained in:
Florian Bruhin 2014-01-30 20:42:15 +01:00
parent c3ce167926
commit a71684ea0f
2 changed files with 54 additions and 1 deletions

View File

@ -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__))

View File

@ -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