Coverage for qutebrowser/misc/utilcmds.py : 46%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014-2018 Florian Bruhin (The Compiler) <mail@qutebrowser.org> # # 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/>.
except ImportError: hunter = None
# so it's available for :debug-pyeval
"""Execute a command after some time.
Args: ms: How many milliseconds to wait. command: The command to run, with optional args. """ if ms < 0: raise cmdexc.CommandError("I can't run something in the past!") commandrunner = runners.CommandRunner(win_id) app = objreg.get('app') timer = usertypes.Timer(name='later', parent=app) try: timer.setSingleShot(True) try: timer.setInterval(ms) except OverflowError: raise cmdexc.CommandError("Numeric argument is too large for " "internal int representation.") timer.timeout.connect( functools.partial(commandrunner.run_safely, command)) timer.timeout.connect(timer.deleteLater) timer.start() except: timer.deleteLater() raise
"""Repeat a given command.
Args: times: How many times to repeat. command: The command to run, with optional args. """ if times < 0: raise cmdexc.CommandError("A negative count doesn't make sense.") commandrunner = runners.CommandRunner(win_id) for _ in range(times): commandrunner.run_safely(command)
"""Run a command with the given count.
If run_with_count itself is run with a count, it multiplies count_arg.
Args: count_arg: The count to pass to the command. command: The command to run, with optional args. count: The count that run_with_count itself received. """ runners.CommandRunner(win_id).run(command, count_arg * count)
def message_error(text): """Show an error message in the statusbar.
Args: text: The text to show. """ message.error(text)
"""Show an info message in the statusbar.
Args: text: The text to show. count: How many times to show the message """ for _ in range(count): message.info(text)
def message_warning(text): """Show a warning message in the statusbar.
Args: text: The text to show. """ message.warning(text)
def clear_messages(): """Clear all message notifications.""" message.global_bridge.clear_messages.emit()
"""Crash for debugging purposes.
Args: typ: either 'exception' or 'segfault'. """ else:
def debug_all_objects(): """Print a list of all objects to the debug log.""" s = debug.get_all_objects() log.misc.debug(s)
def debug_cache_stats(): """Print LRU cache stats.""" prefix_info = configdata.is_valid_prefix.cache_info() # pylint: disable=protected-access render_stylesheet_info = config._render_stylesheet.cache_info() # pylint: enable=protected-access
history_info = None try: from PyQt5.QtWebKit import QWebHistoryInterface interface = QWebHistoryInterface.defaultInterface() if interface is not None: history_info = interface.historyContains.cache_info() except ImportError: pass
tabbed_browser = objreg.get('tabbed-browser', scope='window', window='last-focused') # pylint: disable=protected-access tab_bar = tabbed_browser.tabBar() tabbed_browser_info = tab_bar._minimum_tab_size_hint_helper.cache_info() # pylint: enable=protected-access
log.misc.debug('is_valid_prefix: {}'.format(prefix_info)) log.misc.debug('_render_stylesheet: {}'.format(render_stylesheet_info)) log.misc.debug('history: {}'.format(history_info)) log.misc.debug('tab width cache: {}'.format(tabbed_browser_info))
def debug_console(): """Show the debugging console.""" try: con_widget = objreg.get('debug-console') except KeyError: log.misc.debug('initializing debug console') con_widget = consolewidget.ConsoleWidget() objreg.register('debug-console', con_widget)
if con_widget.isVisible(): log.misc.debug('hiding debug console') con_widget.hide() else: log.misc.debug('showing debug console') con_widget.show()
"""Trace executed code via hunter.
Args: expr: What to trace, passed to hunter. """ "command!")
"""Evaluate a python string and display the results as a web page.
Args: s: The string to evaluate. file: Interpret s as a path to file, also implies --quiet. quiet: Don't show the output in a new tab. """ if file: quiet = True path = os.path.expanduser(s) try: with open(path, 'r', encoding='utf-8') as f: s = f.read() except OSError as e: raise cmdexc.CommandError(str(e)) try: exec(s) out = "No error" except Exception: out = traceback.format_exc() else: try: r = eval(s) out = repr(r) except Exception: out = traceback.format_exc()
qutescheme.pyeval_output = out if quiet: log.misc.debug("pyeval output: {}".format(out)) else: tabbed_browser = objreg.get('tabbed-browser', scope='window', window='last-focused') tabbed_browser.openurl(QUrl('qute://pyeval'), newtab=True)
"""Put data into the fake clipboard and enable logging, used for tests.
Args: s: The text to put into the fake clipboard, or unset to enable logging. """ if s is None: utils.log_clipboard = True else: utils.fake_clipboard = s
"""Repeat the last executed command.
Args: count: Which count to pass the command. """ cmd = runners.last_command[mode_manager.mode] commandrunner = runners.CommandRunner(win_id) commandrunner.run(cmd[0], count if count is not None else cmd[1])
"""Change the number of log lines to be stored in RAM.
Args: capacity: Number of lines for the log. """ if capacity < 0: raise cmdexc.CommandError("Can't set a negative log capacity!") else: log.ram_handler.change_log_capacity(capacity)
(level.lower() for level in log.LOG_LEVELS), key=lambda e: log.LOG_LEVELS[e.upper()])) """Change the log level for console logging.
Args: level: The log level to set. """
"""Change the log filter for console logging.
Args: filters: A comma separated list of logger names. Can also be "none" to clear any existing filters. """ raise cmdexc.CommandError("No log.console_filter. Not attached " "to a console?")
log.console_filter.names = None return
raise cmdexc.CommandError("filters: Invalid value {} - expected one " "of: {}".format(filters, ', '.join(log.LOGGER_NAMES)))
def window_only(current_win_id): """Close all windows except for the current one."""
# We could be in the middle of destroying a window here
def nop(): """Do nothing.""" return
"""Show version information.
Args: paste: Paste to pastebin. """ window=win_id)
pastebin_version() |