Add debug argument for commands
This commit is contained in:
parent
d97823615a
commit
d76226626f
@ -78,8 +78,8 @@ class Application(QApplication):
|
|||||||
networkmanager: The global NetworkManager instance.
|
networkmanager: The global NetworkManager instance.
|
||||||
cookiejar: The global CookieJar instance.
|
cookiejar: The global CookieJar instance.
|
||||||
rl_bridge: The ReadlineBridge being used.
|
rl_bridge: The ReadlineBridge being used.
|
||||||
|
args: ArgumentParser instance.
|
||||||
_keyparsers: A mapping from modes to keyparsers.
|
_keyparsers: A mapping from modes to keyparsers.
|
||||||
_args: ArgumentParser instance.
|
|
||||||
_timers: List of used QTimers so they don't get GCed.
|
_timers: List of used QTimers so they don't get GCed.
|
||||||
_shutting_down: True if we're currently shutting down.
|
_shutting_down: True if we're currently shutting down.
|
||||||
_quit_status: The current quitting status.
|
_quit_status: The current quitting status.
|
||||||
@ -121,7 +121,7 @@ class Application(QApplication):
|
|||||||
|
|
||||||
sys.excepthook = self._exception_hook
|
sys.excepthook = self._exception_hook
|
||||||
|
|
||||||
self._args = args
|
self.args = args
|
||||||
self._init_misc()
|
self._init_misc()
|
||||||
actute_warning()
|
actute_warning()
|
||||||
self._init_config()
|
self._init_config()
|
||||||
@ -155,12 +155,12 @@ class Application(QApplication):
|
|||||||
|
|
||||||
def _init_config(self):
|
def _init_config(self):
|
||||||
"""Inizialize and read the config."""
|
"""Inizialize and read the config."""
|
||||||
if self._args.confdir is None:
|
if self.args.confdir is None:
|
||||||
confdir = get_standard_dir(QStandardPaths.ConfigLocation)
|
confdir = get_standard_dir(QStandardPaths.ConfigLocation)
|
||||||
elif self._args.confdir == '':
|
elif self.args.confdir == '':
|
||||||
confdir = None
|
confdir = None
|
||||||
else:
|
else:
|
||||||
confdir = self._args.confdir
|
confdir = self.args.confdir
|
||||||
try:
|
try:
|
||||||
self.config = ConfigManager(confdir, 'qutebrowser.conf')
|
self.config = ConfigManager(confdir, 'qutebrowser.conf')
|
||||||
except (config.ValidationError,
|
except (config.ValidationError,
|
||||||
@ -210,7 +210,7 @@ class Application(QApplication):
|
|||||||
|
|
||||||
def _init_misc(self):
|
def _init_misc(self):
|
||||||
"""Initialize misc things."""
|
"""Initialize misc things."""
|
||||||
if self._args.version:
|
if self.args.version:
|
||||||
print(version.version())
|
print(version.version())
|
||||||
print()
|
print()
|
||||||
print()
|
print()
|
||||||
@ -285,7 +285,7 @@ class Application(QApplication):
|
|||||||
self.processEvents(QEventLoop.ExcludeUserInputEvents |
|
self.processEvents(QEventLoop.ExcludeUserInputEvents |
|
||||||
QEventLoop.ExcludeSocketNotifiers)
|
QEventLoop.ExcludeSocketNotifiers)
|
||||||
|
|
||||||
for e in self._args.command:
|
for e in self.args.command:
|
||||||
if e.startswith(':'):
|
if e.startswith(':'):
|
||||||
log.init.debug("Startup cmd {}".format(e))
|
log.init.debug("Startup cmd {}".format(e))
|
||||||
self.commandmanager.run_safely_init(e.lstrip(':'))
|
self.commandmanager.run_safely_init(e.lstrip(':'))
|
||||||
@ -516,7 +516,7 @@ class Application(QApplication):
|
|||||||
# if shutdown:
|
# if shutdown:
|
||||||
# self.shutdown()
|
# self.shutdown()
|
||||||
|
|
||||||
@cmdutils.register(instance='', split=False)
|
@cmdutils.register(instance='', split=False, debug=True)
|
||||||
def pyeval(self, s):
|
def pyeval(self, s):
|
||||||
"""Evaluate a python string and display the results as a webpage.
|
"""Evaluate a python string and display the results as a webpage.
|
||||||
|
|
||||||
@ -602,7 +602,7 @@ class Application(QApplication):
|
|||||||
self.quit()
|
self.quit()
|
||||||
|
|
||||||
|
|
||||||
@cmdutils.register(hide=True)
|
@cmdutils.register(debug=True)
|
||||||
def crash(typ='exception'):
|
def crash(typ='exception'):
|
||||||
"""Crash for debugging purposes.
|
"""Crash for debugging purposes.
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ class Command:
|
|||||||
handler: The handler function to call.
|
handler: The handler function to call.
|
||||||
completion: Completions to use for arguments, as a list of strings.
|
completion: Completions to use for arguments, as a list of strings.
|
||||||
needs_js: Whether the command needs javascript enabled
|
needs_js: Whether the command needs javascript enabled
|
||||||
|
debug: Whether this is a debugging command (only shown with --debug).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
@ -49,7 +50,7 @@ class Command:
|
|||||||
# this might be combined with help texts or so as well
|
# this might be combined with help texts or so as well
|
||||||
|
|
||||||
def __init__(self, name, split, hide, nargs, count, desc, instance,
|
def __init__(self, name, split, hide, nargs, count, desc, instance,
|
||||||
handler, completion, modes, not_modes, needs_js):
|
handler, completion, modes, not_modes, needs_js, debug):
|
||||||
# I really don't know how to solve this in a better way, I tried.
|
# I really don't know how to solve this in a better way, I tried.
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -65,6 +66,7 @@ class Command:
|
|||||||
self.modes = modes
|
self.modes = modes
|
||||||
self.not_modes = not_modes
|
self.not_modes = not_modes
|
||||||
self.needs_js = needs_js
|
self.needs_js = needs_js
|
||||||
|
self.debug = debug
|
||||||
|
|
||||||
def check(self, args):
|
def check(self, args):
|
||||||
"""Check if the argument count is valid and the command is permitted.
|
"""Check if the argument count is valid and the command is permitted.
|
||||||
|
@ -104,11 +104,12 @@ class register: # pylint: disable=invalid-name
|
|||||||
strings.
|
strings.
|
||||||
modes/not_modes: List of modes to use/not use.
|
modes/not_modes: List of modes to use/not use.
|
||||||
needs_js: If javascript is needed for this command.
|
needs_js: If javascript is needed for this command.
|
||||||
|
debug: Whether this is a debugging command (only shown with --debug).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, instance=None, name=None, nargs=None, split=True,
|
def __init__(self, instance=None, name=None, nargs=None, split=True,
|
||||||
hide=False, completion=None, modes=None, not_modes=None,
|
hide=False, completion=None, modes=None, not_modes=None,
|
||||||
needs_js=False):
|
needs_js=False, debug=False):
|
||||||
"""Save decorator arguments.
|
"""Save decorator arguments.
|
||||||
|
|
||||||
Gets called on parse-time with the decorator arguments.
|
Gets called on parse-time with the decorator arguments.
|
||||||
@ -127,6 +128,7 @@ class register: # pylint: disable=invalid-name
|
|||||||
self.modes = modes
|
self.modes = modes
|
||||||
self.not_modes = not_modes
|
self.not_modes = not_modes
|
||||||
self.needs_js = needs_js
|
self.needs_js = needs_js
|
||||||
|
self.debug = debug
|
||||||
|
|
||||||
def __call__(self, func):
|
def __call__(self, func):
|
||||||
"""Register the command before running the function.
|
"""Register the command before running the function.
|
||||||
@ -169,7 +171,8 @@ class register: # pylint: disable=invalid-name
|
|||||||
hide=self.hide, nargs=nargs, count=count, desc=desc,
|
hide=self.hide, nargs=nargs, count=count, desc=desc,
|
||||||
instance=self.instance, handler=func,
|
instance=self.instance, handler=func,
|
||||||
completion=self.completion, modes=self.modes,
|
completion=self.completion, modes=self.modes,
|
||||||
not_modes=self.not_modes, needs_js=self.needs_js)
|
not_modes=self.not_modes, needs_js=self.needs_js,
|
||||||
|
debug=self.debug)
|
||||||
for name in names:
|
for name in names:
|
||||||
cmd_dict[name] = cmd
|
cmd_dict[name] = cmd
|
||||||
return func
|
return func
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
"""CompletionModels for different usages."""
|
"""CompletionModels for different usages."""
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSlot, Qt
|
from PyQt5.QtCore import pyqtSlot, Qt, QCoreApplication
|
||||||
|
|
||||||
import qutebrowser.config.config as config
|
import qutebrowser.config.config as config
|
||||||
import qutebrowser.config.configdata as configdata
|
import qutebrowser.config.configdata as configdata
|
||||||
@ -128,7 +128,10 @@ class CommandCompletionModel(BaseCompletionModel):
|
|||||||
assert cmd_dict
|
assert cmd_dict
|
||||||
cmdlist = []
|
cmdlist = []
|
||||||
for obj in set(cmd_dict.values()):
|
for obj in set(cmd_dict.values()):
|
||||||
if not obj.hide:
|
if obj.hide or (obj.debug and not
|
||||||
|
QCoreApplication.instance().args.debug):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
cmdlist.append((obj.name, obj.desc))
|
cmdlist.append((obj.name, obj.desc))
|
||||||
for name, cmd in config.section('aliases').items():
|
for name, cmd in config.section('aliases').items():
|
||||||
cmdlist.append((name, "Alias for '{}'".format(cmd)))
|
cmdlist.append((name, "Alias for '{}'".format(cmd)))
|
||||||
|
@ -49,7 +49,7 @@ def log_events(klass):
|
|||||||
return klass
|
return klass
|
||||||
|
|
||||||
|
|
||||||
@cmdutils.register(hide=True)
|
@cmdutils.register(debug=True)
|
||||||
def set_trace():
|
def set_trace():
|
||||||
"""Set a tracepoint in the Python debugger that works with Qt.
|
"""Set a tracepoint in the Python debugger that works with Qt.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user