Add version() to utils to get version/about infos
This commit is contained in:
parent
c3ce167926
commit
a71684ea0f
@ -12,3 +12,6 @@ Subpackages:
|
|||||||
utils - Misc utility code.
|
utils - Misc utility code.
|
||||||
widgets - Qt widgets displayed on the screen.
|
widgets - Qt widgets displayed on the screen.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
__version_info__ = (0, 0, 0)
|
||||||
|
__version__ = '.'.join(map(str, __version_info__))
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
"""Utility functions"""
|
"""Utility functions"""
|
||||||
|
|
||||||
import re
|
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):
|
def qurl(url):
|
||||||
@ -12,3 +18,47 @@ def qurl(url):
|
|||||||
if not re.match(r'^\w+://', url):
|
if not re.match(r'^\w+://', url):
|
||||||
url = 'http://' + url
|
url = 'http://' + url
|
||||||
return QUrl(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
|
||||||
|
Loading…
Reference in New Issue
Block a user