tps.config

Config module.

Takes care of the INI style config file for global and user configuration.

tps.config.CONFIGFILE = '/home/docs/.config/thinkpad-scripts/config.ini'

Path of global config file

exception tps.config.ShellParseException

Bash code could not be parsed.

The parser here is very limited, it can only detect variable assignments. If something more complicated is found on a given line, this exception is raised.

tps.config.get_config()

Loads the config from the config files.

The global config file is read first, then the user config file is read. That way, options can be overwritten in the user config file.

Returns:Config
Return type:configparser.ConfigParser
tps.config.interpret_shell_line(line, config)

Interprets a single Bash line to parse for variable assignments.

The given line is searched for a config option was allowed in the 3.x series. It will use the shlex module to parse the value of the variable assignment. If it could be parsed correctly, it will add the value to the config. The keys are translated into the new config sections.

Parameters:
  • line (str) – Line to check
  • config (configparser.ConfigParser) – Config to store parsed variables
Raise:

tps.config.ShellParseException

Returns:

None

tps.config.main()

Command line entry point.

Returns:None
tps.config.migrate_shell_config()

Migrates the shell config in an interactive way.

The old shell based config will be imported and transfered into a configparser based one. Then that will be printed out. The user can accept it and the config will be saved.

tps.config.print_config(config)

Pretty prints config with colors.

Parameters:config (configparser.ConfigParser) – Config to print
Returns:None
tps.config.set_up_logging(verbosity)

Sets up the logging to console and syslog.

This is taken from the Python Docs – Logging Cookbook.

The address parameter for the syslog is taken from an answer from dr jimbob.