def _save(self) -> None: """Save the settings to the YAML file if they've changed.""" if not self._dirty: return settings = {} # type: _SettingsType for name, values in sorted(self._values.items()): if not values: continue settings[name] = {} for scoped in values: key = ('global' if scoped.pattern is None else str(scoped.pattern)) settings[name][key] = scoped.value data = {'config_version': self.VERSION, 'settings': settings} with qtutils.savefile_open(self._filename) as f: f.write( textwrap.dedent(""" # If a config.py file exists, this file is ignored unless it's explicitly loaded # via config.load_autoconfig(). For more information, see: # https://github.com/qutebrowser/qutebrowser/blob/master/doc/help/configuring.asciidoc#loading-autoconfigyml # DO NOT edit this file by hand, qutebrowser will overwrite it. # Instead, create a config.py - see :help for details. """.lstrip('\n'))) utils.yaml_dump(data, f) # type: ignore
def _save(self): """Save the changed settings to the YAML file.""" data = {'config_version': self.VERSION, 'global': self.values} with qtutils.savefile_open(self._filename) as f: f.write(textwrap.dedent(""" # DO NOT edit this file by hand, qutebrowser will overwrite it. # Instead, create a config.py - see :help for details. """.lstrip('\n'))) utils.yaml_dump(data, f)
def save(self, name, last_window=False, load_next_time=False, only_window=None, with_private=False): """Save a named session. Args: name: The name of the session to save, or the 'default' sentinel object. last_window: If set, saves the saved self._last_window_session instead of the currently open state. load_next_time: If set, prepares this session to be load next time. only_window: If set, only tabs in the specified window is saved. with_private: Include private windows. Return: The name of the saved session. """ name = self._get_session_name(name) path = self._get_session_path(name) log.sessions.debug("Saving session {} to {}...".format(name, path)) if last_window: data = self._last_window_session if data is None: log.sessions.error("last_window_session is None while saving!") return None else: data = self._save_all(only_window=only_window, with_private=with_private) log.sessions.vdebug( # type: ignore[attr-defined] "Saving data: {}".format(data)) try: with qtutils.savefile_open(path) as f: utils.yaml_dump(data, f) except (OSError, UnicodeEncodeError, yaml.YAMLError) as e: raise SessionError(e) if load_next_time: configfiles.state['general']['session'] = name return name
def save(self, name, last_window=False, load_next_time=False, only_window=None, with_private=False): """Save a named session. Args: name: The name of the session to save, or the 'default' sentinel object. last_window: If set, saves the saved self._last_window_session instead of the currently open state. load_next_time: If set, prepares this session to be load next time. only_window: If set, only tabs in the specified window is saved. with_private: Include private windows. Return: The name of the saved session. """ name = self._get_session_name(name) path = self._get_session_path(name) log.sessions.debug("Saving session {} to {}...".format(name, path)) if last_window: data = self._last_window_session if data is None: log.sessions.error("last_window_session is None while saving!") return None else: data = self._save_all(only_window=only_window, with_private=with_private) log.sessions.vdebug("Saving data: {}".format(data)) try: with qtutils.savefile_open(path) as f: utils.yaml_dump(data, f) except (OSError, UnicodeEncodeError, yaml.YAMLError) as e: raise SessionError(e) if load_next_time: configfiles.state['general']['session'] = name return name
def _save(self) -> None: """Save the settings to the YAML file if they've changed.""" if not self._dirty: return settings = {} # type: YamlConfig._SettingsType for name, values in sorted(self._values.items()): if not values: continue settings[name] = {} for scoped in values: key = ('global' if scoped.pattern is None else str(scoped.pattern)) settings[name][key] = scoped.value data = {'config_version': self.VERSION, 'settings': settings} with qtutils.savefile_open(self._filename) as f: f.write(textwrap.dedent(""" # DO NOT edit this file by hand, qutebrowser will overwrite it. # Instead, create a config.py - see :help for details. """.lstrip('\n'))) utils.yaml_dump(data, f)
def _save(self) -> None: """Save the settings to the YAML file if they've changed.""" if not self._dirty: return settings = {} # type: YamlConfig._SettingsType for name, values in sorted(self._values.items()): if not values: continue settings[name] = {} for scoped in values: key = ('global' if scoped.pattern is None else str(scoped.pattern)) settings[name][key] = scoped.value data = {'config_version': self.VERSION, 'settings': settings} with qtutils.savefile_open(self._filename) as f: f.write(textwrap.dedent(""" # DO NOT edit this file by hand, qutebrowser will overwrite it. # Instead, create a config.py - see :help for details. """.lstrip('\n'))) utils.yaml_dump(data, f)
def write_toplevel(self, data): with self.fobj.open('w', encoding='utf-8') as f: utils.yaml_dump(data, f)
def write_toplevel(self, data): with self.fobj.open('w', encoding='utf-8') as f: utils.yaml_dump(data, f)