configfile module
- class configfile.ConfigFile[source]
Bases:
object
Store options in a plain text file in form of: key=value
- askQuestion(message)[source]
Call previously registered function to ask a question.
- Parameters:
message (str) – question that should be shown
- listValue(key, type_key='str:value', default=[])[source]
Return a list of values
Size of the list must be stored in key.size
- Parameters:
- Returns:
- value of
key
ordefault
if
key
is not set.
- value of
- Return type:
type_key
pattern examples:'str:value' => return str values from key.value 'int:type' => return int values from key.type 'bool:enabled' => return bool values from key.enabled ('str:value', 'int:type') => return tuple of values
- load(filename, **kwargs)[source]
Reset current options and load new options from file.
- Parameters:
filename (str) – full path
- notifyError(message)[source]
Call previously registered function to show an error.
- Parameters:
message (str) – error message that should be shown
- removeKeysStartsWith(prefix)[source]
Remove key from options which start with given prefix.
- Parameters:
prefix (str) – prefix for keys (key starts with this string) that should be removed
- setErrorHandler(handler)[source]
Register a function that should be called for notifying errors.
handler (method): callable function
- setListValue(key, type_key, value)[source]
Set a list of values.
Size of the list will be stored in key.size
- Parameters:
type_key
pattern examples:'str:value' => return str values from key.value 'int:type' => return int values from key.type 'bool:enabled' => return bool values from key.enabled ('str:value', 'int:type') => return tuple of values
- setQuestionHandler(handler)[source]
Register a function that should be called for asking questions.
handler (method): callable function
- class configfile.ConfigFileWithProfiles(default_profile_name='')[source]
Bases:
ConfigFile
Store options in profiles as ‘profileX.key=value’
- Parameters:
default_profile_name (str) – default name of the first profile.
- append(filename)[source]
Load options from file and append them to current options.
- Parameters:
filename (str) – full path
- currentProfile()[source]
Currently selected profile ID. Profile IDs are strings!
- Returns:
profile ID
- Return type:
- load(filename)[source]
Reset current options and load new options from file.
- Parameters:
filename (str) – full path
- profileStrValue(key, default='', profile_id=None)[source]
Return the value of
key
related toprofile_id
.- Returns:
The value.
- Return type:
- profiles()[source]
List of all available profile IDs. Profile IDs are strings!
- Returns:
all available profile IDs as strings
- Return type:
- profilesSortedByName()[source]
List of available profile IDs alphabetically sorted by their names. Profile IDs are strings!
- Returns:
all available profile IDs as strings
- Return type:
- removeProfileKeysStartsWith(prefix, profile_id=None)[source]
Remove the keys starting with prefix from profile.