def process(tab: apitypes.Tab, pid: int = None, action: str = 'show') -> None: """Manage processes spawned by qutebrowser. Note that processes with a successful exit get cleaned up after 1h. Args: pid: The process ID of the process to manage. action: What to do with the given process: - show: Show information about the process. - terminate: Try to gracefully terminate the process (SIGTERM). - kill: Kill the process forcefully (SIGKILL). """ if pid is None: if last_pid is None: raise cmdutils.CommandError("No process executed yet!") pid = last_pid try: proc = all_processes[pid] except KeyError: raise cmdutils.CommandError(f"No process found with pid {pid}") if proc is None: raise cmdutils.CommandError(f"Data for process {pid} got cleaned up") if action == 'show': tab.load_url(QUrl(f'qute://process/{pid}')) elif action == 'terminate': proc.terminate() elif action == 'kill': proc.terminate(kill=True) else: raise utils.Unreachable(action)
def stop(tab: apitypes.Tab) -> None: """Stop loading in the current/[count]th tab. Args: count: The tab index to stop, or None. """ if tab is not None: tab.stop()
def reloadpage(tab: apitypes.Tab, force: bool = False) -> None: """Reload the current/[count]th tab. Args: count: The tab index to reload, or None. force: Bypass the page cache. """ if tab is not None: tab.reload(force=force)
def screenshot( tab: apitypes.Tab, filename: pathlib.Path, *, rect: str = None, force: bool = False, ) -> None: """Take a screenshot of the currently shown part of the page. The file format is automatically determined based on the given file extension. Args: filename: The file to save the screenshot to (~ gets expanded). rect: The rectangle to save, as a string like WxH+X+Y. force: Overwrite existing files. """ expanded = filename.expanduser() if expanded.exists() and not force: raise cmdutils.CommandError( f"File {filename} already exists (use --force to overwrite)") qrect = None if rect is None else utils.parse_rect(rect) pic = tab.grab_pixmap(qrect) if pic is None: raise cmdutils.CommandError("Getting screenshot failed") ok = pic.save(str(expanded)) if not ok: raise cmdutils.CommandError(f"Saving to {filename} failed") _LOGGER.debug(f"Screenshot saved to {filename}")
def jmatrix_toggle_rule(tab: apitypes.Tab, rule: str): """View request types made on this host and block/allow them. Requests are collated based on the host of the URL, so you may see requests from other pages on the same host. """ try: action, res_type, dest = rule.split() except ValueError: raise cmdutils.CommandError( "Expected input of the form \"block/allow request_type " "destination_host\"") if action.upper() == "BLOCK": action = jmatrix.rule.Action.ALLOW else: action = jmatrix.rule.Action.BLOCK if res_type == '*': res_type = "ALL" try: res_type = jmatrix.rule.Type[res_type.upper()] except KeyError: message.error("Type '{}' not recognized".format(res_type)) origin = tab.url().host() JMATRIX_RULES.matrix_rules[origin][dest][res_type] = action # Change our seen requests to match so it'll show up in the completion # without having to reload the page. SEEN_REQUESTS.matrix_rules[origin][dest][res_type] = action
def debug_dump_page(tab: apitypes.Tab, dest: str, plain: bool = False) -> None: """Dump the current page's content to a file. Args: dest: Where to write the file to. plain: Write plain text instead of HTML. """ dest = os.path.expanduser(dest) def callback(data: str) -> None: """Write the data to disk.""" try: with open(dest, 'w', encoding='utf-8') as f: f.write(data) except OSError as e: message.error('Could not write page: {}'.format(e)) else: message.info("Dumped page to {}.".format(dest)) tab.dump_async(callback, plain=plain)
def home(tab: apitypes.Tab) -> None: """Open main startpage in current tab.""" if tab.data.pinned: message.info("Tab is pinned!") else: tab.load_url(config.val.url.start_pages[0])
def home(tab: apitypes.Tab) -> None: """Open main startpage in current tab.""" if tab.navigation_blocked(): message.info("Tab is pinned!") else: tab.load_url(config.val.url.start_pages[0])