def plugins_wizard(filename): """Plugins Configuration Wizard. :param str filename: path to an existing Sopel configuration :return: the configuration object This wizard function helps to configure plugins for an existing Sopel config file. """ if not os.path.isfile(filename): raise config.ConfigurationNotFound(filename) settings = config.Config(filename, validate=False) _plugins_wizard(settings) try: settings.save() except Exception: # TODO: Be specific tools.stderr( "We've encountered an error while writing the configuration file." "This shouldn't happen. Check your permissions settings to make sure nothing is out of place." ) raise return settings
def load_settings(options): """Load Sopel's settings using the command line's ``options``. :param options: parsed arguments :return: sopel configuration :rtype: :class:`sopel.config.Config` :raise sopel.config.ConfigurationNotFound: raised when configuration file is not found :raise sopel.config.ConfigurationError: raised when configuration is invalid This function loads Sopel's settings from one of these sources: * value of ``options.config``, if given, * ``SOPEL_CONFIG`` environment variable, if no option is given, * otherwise the ``default`` configuration is loaded, then loads the settings and returns it as a :class:`~sopel.config.Config` object. If the configuration file can not be found, a :exc:`sopel.config.ConfigurationNotFound` error will be raised. .. note:: This function expects that ``options`` exposes two attributes: ``config`` and ``configdir``. The :func:`sopel.cli.utils.add_common_arguments` function should be used to add these options to the argument parser. """ # Default if no options.config or no env var or if they are empty name = 'default' if options.config: name = options.config elif 'SOPEL_CONFIG' in os.environ: name = os.environ['SOPEL_CONFIG'] or name # use default if empty filename = find_config(options.configdir, name) if not os.path.isfile(filename): raise config.ConfigurationNotFound(filename=filename) return config.Config(filename)
def load_settings(options): """Load Sopel's settings using the command line's ``options``. :param options: parsed arguments :return: sopel configuration :rtype: :class:`sopel.config.Config` :raise sopel.config.ConfigurationNotFound: raised when configuration file is not found :raise sopel.config.ConfigurationError: raised when configuration is invalid This function loads Sopel's settings from ``options.config``. This option's value should be from one of these sources: * given by the command line argument, * ``SOPEL_CONFIG`` environment variable, if the argument is not used, * otherwise it should default to ``default``, then it returns it as a :class:`~sopel.config.Config` object. If the configuration file can not be found, a :exc:`sopel.config.ConfigurationNotFound` error will be raised. .. note:: This function expects that ``options`` exposes two attributes: ``config`` and ``configdir``. The :func:`sopel.cli.utils.add_common_arguments` function should be used to add these options to the argument parser. This function is also responsible for using the environment variable or the default value. """ filename = find_config(options.configdir, options.config) if not os.path.isfile(filename): raise config.ConfigurationNotFound(filename=filename) return config.Config(filename)
def load_settings(options): """Load Sopel's settings using the command line's ``options``. :param options: parsed arguments :return: sopel configuration :rtype: :class:`sopel.config.Config` :raise sopel.config.ConfigurationNotFound: raised when configuration file is not found :raise sopel.config.ConfigurationError: raised when configuration is invalid This function loads Sopel's settings from one of these sources: * value of ``options.config``, if given, * or the ``default`` configuration is loaded, then loads the settings and returns it as a :class:`~sopel.config.Config` object. If the configuration file can not be found, a :exc:`sopel.config.ConfigurationNotFound` error will be raised. .. note:: To use this function effectively, the :func:`sopel.cli.utils.add_common_arguments` function should be used to add the proper option to the argument parser. """ name = options.config or 'default' filename = find_config(config.DEFAULT_HOMEDIR, name) if not os.path.isfile(filename): raise config.ConfigurationNotFound(filename=filename) return config.Config(filename)