logsnarf.config module

Logsnarf configuration.

See configuration for details on how to configure logsnarf.

class logsnarf.config.Config(resource_name=None, config_file=None)[source]

Bases: Mapping

Class to contain configuration information for Logsnarf.

This class wraps loading of the configparser config file(s), initializing logging (from a logging.ini), and proxies some methods from xdg.BaseDirectory module for creating/opening config or data files in appropriate places.

It also provides a dict-like read-only interface to the config file, with a vague attempt at type casting through ConfigSection objects.

Parameters:
  • resource_name (str) – The xdg resource name to use. Defaults to logsnarf

  • config_file (str) – absolute path to a configuration file

load()[source]

Initializes logging and loads the configs.

loadConfigPaths()[source]

Returns the configuration paths for the resource.

Returns an iterator which gives each directory named ‘logsnarf’ in the configuration search path. Information provided by earlier directories should take precedence over later ones, and the user-specific config dir comes first.

loadConfigs()[source]

Loads all configurations

loadLoggingConfig()[source]

Initializes logging.

The twisted PythonLoggingObserver is initialized, then the config paths are searched for a ${RESOURCE_NAME}/logging.ini, failing that, logging.basicConfig() is called with no arguments so that some sort of logging occurs.

openConfigFile(name, mode)[source]

Opens a file in the user config directory, with the given mode.

Parameters:
  • name (str) – the name of the config file to open

  • mode (str) – mode to open file with

Returns:

file object opened with the config file

Return type:

file

openDataFile(name, mode, *args, **kwargs)[source]

Opens a file in the user data directory, with the given mode.

Parameters:
  • name (str) – the name of the data file to open

  • mode (str) – mode to open file with

Returns:

file object opened with the data file

Return type:

file

saveConfigPath(name='')[source]

Ensures the user save config path exists, and returns the path.

Optionally also provide a filename, to receive a full path to that file in the data directory.

Ensure $XDG_CONFIG_HOME/logsnarf/ exists, and return its path. Use this when saving or updating application configuration.

Parameters:

name (str) – the name of the file

Returns:

path to the directory, or, if given, file

Return type:

str

saveDataPath(name='')[source]

Ensures the user save data path exists, and returns the path to it.

Optionally also provide a filename, to receive a full path to that file in the data directory.

Ensure $XDG_DATA_HOME/logsnarf/ exists, and return its path. Use this when saving or updating application data.

Parameters:

name (str) – the name of the file

Returns:

path to the directory, or, if given, file

Return type:

str

class logsnarf.config.ConfigSection(name, cfg)[source]

Bases: Mapping

Class representing a configparser section.

Provides a mapping interface that attempts to do some vaguely sane type casting. No attempt to be smart, cache results etc is done.

Parameters: