From af19e6d2e5db4dee04e58aaaea631d475334fdd0 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 4 Jun 2014 14:11:55 +0200 Subject: [PATCH] Move init to own file qutebrowser.py --- qutebrowser/__main__.py | 4 +- qutebrowser/app.py | 53 --------------------------- qutebrowser/qutebrowser.py | 75 ++++++++++++++++++++++++++++++++++++++ setup.py | 2 +- 4 files changed, 78 insertions(+), 56 deletions(-) create mode 100644 qutebrowser/qutebrowser.py diff --git a/qutebrowser/__main__.py b/qutebrowser/__main__.py index f9feb06d0..af4dd8dd6 100644 --- a/qutebrowser/__main__.py +++ b/qutebrowser/__main__.py @@ -19,9 +19,9 @@ """Entry point for qutebrowser. Simply execute qutebrowser.""" -import qutebrowser.app as app +import qutebrowser.qutebrowser import sys if __name__ == '__main__': - sys.exit(app.main()) + sys.exit(qutebrowser.qutebrowser.main()) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index b6a865bda..32367da96 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -17,15 +17,6 @@ """Initialization of qutebrowser and application-wide things.""" -### Things we want to do before normal imports ### -from qutebrowser.utils.checkpyver import check_python_version -check_python_version() -import qutebrowser.utils.earlyinit as earlyinit -earlyinit.init_faulthandler() -earlyinit.fix_harfbuzz() -earlyinit.check_pyqt_core() -earlyinit.check_pyqt_webkit() - import os import sys import types @@ -35,7 +26,6 @@ import configparser from bdb import BdbQuit from functools import partial from signal import signal, SIGINT -from argparse import ArgumentParser from base64 import b64encode from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox @@ -602,41 +592,6 @@ class Application(QApplication): self.quit() -def _parse_args(): - """Parse command line options. - - Return: - Argument namespace from argparse. - """ - parser = ArgumentParser("usage: %(prog)s [options]") - parser.add_argument('-l', '--loglevel', dest='loglevel', - help="Set loglevel", default='info') - parser.add_argument('--logfilter', - help="Comma-separated list of things to be logged") - parser.add_argument('-c', '--confdir', help="Set config directory (empty " - "for no config storage)") - parser.add_argument('--debug', help="Turn on debugging options.", - action='store_true') - parser.add_argument('--nocolor', help="Turn off colored logging.", - action='store_false', dest='color') - parser.add_argument('-V', '--version', help="Show version and quit.", - action='store_true') - # Note this will be checked hardcoded via sys.argv before _parse_args - # is even run. That's also why we don't use --harfbuzz=(old|new). - group = parser.add_mutually_exclusive_group() - group.add_argument('--system-harfbuzz', help="Force system harfbuzz " - "engine", action='store_true') - group.add_argument('--new-harfbuzz', help="Force new harfbuzz engine", - action='store_true') - group.add_argument('--old-harfbuzz', help="Force old harfbuzz engine", - action='store_true') - parser.add_argument('command', nargs='*', help="Commands to execute on " - "startup.", metavar=':command') - # URLs will actually be in command - parser.add_argument('url', nargs='*', help="URLs to open on startup.") - return parser.parse_args() - - @cmdutils.register(hide=True) def crash(typ='exception'): """Crash for debugging purposes. @@ -656,11 +611,3 @@ def crash(typ='exception'): raise Exception("Segfault failed (wat.)") else: raise Exception("Forced crash") - - -def main(): - """Main entry point for qutebrowser.""" - args = _parse_args() - log.init_log(args) - app = Application(args) - return app.exec_() diff --git a/qutebrowser/qutebrowser.py b/qutebrowser/qutebrowser.py new file mode 100644 index 000000000..2665ffdf1 --- /dev/null +++ b/qutebrowser/qutebrowser.py @@ -0,0 +1,75 @@ +# Copyright 2014 Florian Bruhin (The Compiler) +# +# 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 . + +"""Early initialization and main entry pint.""" + + +from argparse import ArgumentParser + +from qutebrowser.utils.checkpyver import check_python_version +check_python_version() +import qutebrowser.utils.earlyinit as earlyinit + + +def _parse_args(): + """Parse command line options. + + Return: + Argument namespace from argparse. + """ + parser = ArgumentParser("usage: %(prog)s [options]") + parser.add_argument('-l', '--loglevel', dest='loglevel', + help="Set loglevel", default='info') + parser.add_argument('--logfilter', + help="Comma-separated list of things to be logged") + parser.add_argument('-c', '--confdir', help="Set config directory (empty " + "for no config storage)") + parser.add_argument('--debug', help="Turn on debugging options.", + action='store_true') + parser.add_argument('--nocolor', help="Turn off colored logging.", + action='store_false', dest='color') + parser.add_argument('-V', '--version', help="Show version and quit.", + action='store_true') + # Note this will be checked hardcoded via sys.argv before _parse_args + # is even run. That's also why we don't use --harfbuzz=(old|new). + group = parser.add_mutually_exclusive_group() + group.add_argument('--system-harfbuzz', help="Force system harfbuzz " + "engine", action='store_true') + group.add_argument('--new-harfbuzz', help="Force new harfbuzz engine", + action='store_true') + group.add_argument('--old-harfbuzz', help="Force old harfbuzz engine", + action='store_true') + parser.add_argument('command', nargs='*', help="Commands to execute on " + "startup.", metavar=':command') + # URLs will actually be in command + parser.add_argument('url', nargs='*', help="URLs to open on startup.") + return parser.parse_args() + + +def main(): + """Main entry point for qutebrowser.""" + earlyinit.init_faulthandler() + args = _parse_args() + earlyinit.fix_harfbuzz() + earlyinit.check_pyqt_core() + earlyinit.check_pyqt_webkit() + # We do these imports late as we need to do the early init first. + import qutebrowser.utils.log as log + from qutebrowser.app import Application + log.init_log(args) + app = Application(args) + return app.exec_() diff --git a/setup.py b/setup.py index b89c9340c..1454d5ffc 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ try: include_package_data=True, package_data={'qutebrowser': ['html/*', 'git-commit-id']}, entry_points={'gui_scripts': - ['qutebrowser = qutebrowser.app:main']}, + ['qutebrowser = qutebrowser.qutebrowser:main']}, test_suite='qutebrowser.test', zip_safe=True, **setupdata