x2go.inifiles module

X2GoProcessIniFile - helper class for parsing .ini files

class x2go.inifiles.X2GoIniFile(config_files, defaults=None, logger=None, loglevel=56)[source]

Bases: object

Base class for processing the different ini files used by X2Go clients. Primarily used to standardize the content of the different X2Go client ini file (settings, printing, sessions, xconfig).

If entries are omitted in an ini file, they are filled with default values (as hard coded in Python X2Go), so the resulting objects always contain the same fields.

Parameters:
  • config_files (list) – a list of configuration file names (e.g. a global filename and a user’s home directory filename)

  • defaults (dict) – a cascaded Python dicitionary structure with ini file defaults (to override Python X2Go’s hard coded defaults in x2go.defaults

  • logger (x2go.log.X2GoLogger instance) – you can pass an x2go.log.X2GoLogger object to the x2go.inifiles.X2GoIniFile constructor

  • loglevel (int) – if no x2go.log.X2GoLogger object has been supplied a new one will be constructed with the given loglevel

get(section, key, key_type=None)

Retrieve a value for a given section and key.

Parameters:
  • section (str) – the ini file section

  • key (str) – the ini file key in the given section

  • key_type – Python data type of the given key (Default value = None)

Returns:

the value for the given section and key

Return type:

class

get_type(section, key)[source]

Retrieve a value type for a given section and key. The returned value type is based on the default values dictionary.

Parameters:
  • section (str) – the ini file section

  • key (str) – the ini file key in the given section

Returns:

a Python variable type

Return type:

class

get_value(section, key, key_type=None)[source]

Retrieve a value for a given section and key.

Parameters:
  • section (str) – the ini file section

  • key (str) – the ini file key in the given section

  • key_type – Python data type of the given key (Default value = None)

Returns:

the value for the given section and key

Return type:

class

load()[source]

R(e-r)ead configuration file(s).

property printable_config_file

Returns a printable configuration file as a multi-line string.

update_value(section, key, value)[source]

Change a value for a given section and key. This method does not have any effect on configuration files.

Parameters:
  • section (str) – the ini file section

  • key (str) – the ini file key in the given section

  • value (str, list, bool, …) – the value for the given section and key

write()[source]

Write the ini file modifications (SafeConfigParser object) from RAM to disk.

For writing the first of the config_files specified on instance construction that is writable will be used.

Returns:

True if the user config file has been successfully written, False otherwise.

Return type:

bool