Add some more init checks and use Tk for errors

This commit is contained in:
Florian Bruhin 2014-07-27 22:57:50 +02:00
parent 056e1bea76
commit c2a7a67f30
3 changed files with 48 additions and 9 deletions

View File

@ -15,14 +15,27 @@
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""Early initialization and main entry pint."""
"""Early initialization and main entry point."""
from argparse import ArgumentParser
import sys
import qutebrowser
from qutebrowser.utils.checkpyver import check_python_version
try:
from qutebrowser.utils.checkpyver import check_python_version
except ImportError:
try:
# python2
from .utils.checkpyver import check_python_version
except (SystemError, ValueError):
# Import without module - SystemError on Python3, ValueError (?!?) on
# Python2
sys.stderr.write("Please don't run this script directly, do something "
"like python3 -m qutebrowser instead.\n")
sys.stderr.flush()
sys.exit(100)
check_python_version()
from argparse import ArgumentParser
import qutebrowser.utils.earlyinit as earlyinit

View File

@ -22,6 +22,18 @@ This should import and run fine with both python2 and python3.
import sys
try:
# Python3
from tkinter import Tk, messagebox
except ImportError:
try:
# Python2
from Tkinter import Tk
import tkMessageBox as messagebox
except ImportError:
# Some Python without Tk
Tk = None
# 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
@ -32,8 +44,13 @@ def check_python_version():
# We don't use .format() and print_function here just in case someone
# still has < 2.6 installed.
version_str = '.'.join(map(str, sys.version_info[:3]))
sys.stderr.write("Fatal error: At least Python 3.3 is required to run "
"qutebrowser, but " + version_str + " is "
"installed!\n")
sys.stderr.flush()
text = ("At least Python 3.3 is required to run qutebrowser, but " +
version_str + " is installed!\n")
if Tk:
root = Tk()
root.withdraw()
messagebox.showerror("qutebrowser: Fatal error!", text)
else:
sys.stderr.write(text)
sys.stderr.flush()
sys.exit(1)

View File

@ -25,6 +25,10 @@ import sys
import faulthandler
import traceback
import signal
try:
from tkinter import Tk, messagebox
except ImportError:
Tk = None
def _missing_str(name, debian=None, arch=None, windows=None, pip=None):
@ -175,7 +179,12 @@ def check_pyqt_core():
"or the standalone qutebrowser exe.\n"
"http://www.riverbankcomputing.co.uk/"
"software/pyqt/download5")
print(text)
if Tk:
root = Tk()
root.withdraw()
messagebox.showerror("qutebrowser: Fatal error!", text)
else:
print(text, file=sys.stderr)
if '--debug' in sys.argv:
print(file=sys.stderr)
traceback.print_exc()