2014-06-19 09:04:37 +02:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
2017-05-09 21:37:03 +02:00
|
|
|
# Copyright 2014-2017 Florian Bruhin (The-Compiler) <mail@qutebrowser.org>
|
2016-01-22 17:46:33 +01:00
|
|
|
#
|
2014-05-13 19:46:57 +02:00
|
|
|
# This file is part of qutebrowser.
|
|
|
|
#
|
|
|
|
# qutebrowser 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 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# qutebrowser 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 qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
"""Check if qutebrowser is run with the correct python version.
|
|
|
|
|
|
|
|
This should import and run fine with both python2 and python3.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
2014-07-27 22:57:50 +02:00
|
|
|
try:
|
|
|
|
# Python3
|
|
|
|
from tkinter import Tk, messagebox
|
2016-05-24 15:40:18 +02:00
|
|
|
except ImportError: # pragma: no cover
|
2014-07-27 22:57:50 +02:00
|
|
|
try:
|
|
|
|
# Python2
|
|
|
|
from Tkinter import Tk
|
|
|
|
import tkMessageBox as messagebox
|
|
|
|
except ImportError:
|
|
|
|
# Some Python without Tk
|
|
|
|
Tk = None
|
2015-08-19 06:39:22 +02:00
|
|
|
messagebox = None
|
2014-07-27 22:57:50 +02:00
|
|
|
|
2014-05-13 19:46:57 +02:00
|
|
|
|
|
|
|
# First we check the version of Python. This code should run fine with python2
|
|
|
|
# and python3. We don't have Qt available here yet, so we just print an error
|
|
|
|
# to stderr.
|
|
|
|
def check_python_version():
|
|
|
|
"""Check if correct python version is run."""
|
2014-07-28 20:41:42 +02:00
|
|
|
if sys.hexversion < 0x03040000:
|
2014-05-13 19:46:57 +02:00
|
|
|
# We don't use .format() and print_function here just in case someone
|
|
|
|
# still has < 2.6 installed.
|
2015-12-01 07:16:32 +01:00
|
|
|
# pylint: disable=bad-builtin
|
2014-05-13 19:46:57 +02:00
|
|
|
version_str = '.'.join(map(str, sys.version_info[:3]))
|
2014-07-28 20:41:42 +02:00
|
|
|
text = ("At least Python 3.4 is required to run qutebrowser, but " +
|
2014-07-27 22:57:50 +02:00
|
|
|
version_str + " is installed!\n")
|
2016-05-24 15:40:18 +02:00
|
|
|
if Tk and '--no-err-windows' not in sys.argv: # pragma: no cover
|
2014-07-27 22:57:50 +02:00
|
|
|
root = Tk()
|
|
|
|
root.withdraw()
|
|
|
|
messagebox.showerror("qutebrowser: Fatal error!", text)
|
|
|
|
else:
|
|
|
|
sys.stderr.write(text)
|
|
|
|
sys.stderr.flush()
|
2014-05-13 19:46:57 +02:00
|
|
|
sys.exit(1)
|
2015-08-19 00:04:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
check_python_version()
|