config package¶
Submodules¶
config.appcfg module¶
- filename
sppas.src.config.appcfg.py
- author
Florian Hocquet, Brigitte Bigi
- contact
- summary
The application configuration.
- class config.appcfg.sppasAppConfig[source]¶
Bases:
object
Configuration for SPPAS application.
An instance of this class has to be created for any application using the SPPAS API.
Members are:
log_level
splash_delay
features dictionary
- APP_CONFIG_FILENAME = '.app~'¶
- DEFAULT_LOG_LEVEL = 0¶
- __init__()[source]¶
Create a new sppasAppConfig instance.
The configuration is set to its default values and updated with the content of a configuration file (if existing).
The configuration is saved the 1st time this class is instantiated and when this class is deleted.
- feature_installed(key)[source]¶
Return True if a feature was successfully installed by SPPAS.
- Parameters
key – (str) Identifier of a feature.
- property log_level¶
Return the level for logging messages, ranging 0-50.
config.exceptions module¶
- filename
sppas.src.config.exceptions.py
- author
Brigitte Bigi
- contact
- summary
Global exceptions of SPPAS: a status is added.
Status of global exceptions for sppas:
main exception: 001
type errors: 100-series
index errors: 200-series
value errors: 300-series
key errors: 400-series
os errors: 500-series
IO errors: 600-series
- exception config.exceptions.IOExtensionError(filename)[source]¶
Bases:
config.exceptions.sppasIOError
:ERROR 0610:.
Unknown extension for filename ‘{:s}’.
- exception config.exceptions.IndexRangeException(value, min_value, max_value)[source]¶
Bases:
config.exceptions.sppasValueError
:ERROR 0340:.
List index {} out of range [{},{}].
- exception config.exceptions.IntervalRangeException(value, min_value, max_value)[source]¶
Bases:
config.exceptions.sppasValueError
:ERROR 0330:.
Value {} is out of range [{},{}].
- exception config.exceptions.NegativeValueError(value)[source]¶
Bases:
config.exceptions.sppasValueError
:ERROR 0310:.
Expected a positive value. Got {value}.
- exception config.exceptions.NoDirectoryError(dirname)[source]¶
Bases:
config.exceptions.sppasIOError
:ERROR 0620:.
The directory {dirname} does not exist.
- exception config.exceptions.RangeBoundsException(min_value, max_value)[source]¶
Bases:
config.exceptions.sppasValueError
:ERROR 0320:.
Min value {} is bigger than max value {}.’
- exception config.exceptions.sppasEnableFeatureError(name)[source]¶
Bases:
config.exceptions.sppasOSError
:ERROR 0520:.
Feature {name} is not enabled; its installation should be processed first.
- exception config.exceptions.sppasError(message)[source]¶
Bases:
Exception
:ERROR 0001:.
The following error occurred: {message}.
- property status¶
- exception config.exceptions.sppasExtensionReadError(filename)[source]¶
Bases:
config.exceptions.sppasIOError
:ERROR 0670:.
Files with extension ‘{:s}’ are not supported for reading.
- exception config.exceptions.sppasExtensionWriteError(filename)[source]¶
Bases:
config.exceptions.sppasIOError
:ERROR 0680:.
Files with extension ‘{:s}’ are not supported for writing.
- exception config.exceptions.sppasIOError(filename)[source]¶
Bases:
OSError
:ERROR 0600:.
No such file or directory: {name}
- property status¶
- exception config.exceptions.sppasIndexError(index)[source]¶
Bases:
IndexError
:ERROR 0200:.
Invalid index value {:d}.
- property status¶
- exception config.exceptions.sppasInstallationError(error_msg)[source]¶
Bases:
config.exceptions.sppasOSError
:ERROR 0510:.
Installation failed with error: {error}.
- exception config.exceptions.sppasKeyError(data_name, value)[source]¶
Bases:
KeyError
:ERROR 0400:.
Invalid key ‘{!s:s}’ for data ‘{!s:s}’.
- property status¶
- exception config.exceptions.sppasOSError(error_msg)[source]¶
Bases:
OSError
:ERROR 0500:.
OS error: {error}.
- property status¶
- exception config.exceptions.sppasOpenError(filename)[source]¶
Bases:
config.exceptions.sppasIOError
:ERROR 0650:.
File ‘{:s}’ can’t be open or read.
- exception config.exceptions.sppasPackageFeatureError(package, name)[source]¶
Bases:
config.exceptions.sppasOSError
:ERROR 0530:.
The package {package} can’t be imported. The installation of the feature {name} should be processed first.
- exception config.exceptions.sppasPackageUpdateFeatureError(package, name)[source]¶
Bases:
config.exceptions.sppasOSError
:ERROR 0540:.
The package {package} is not up-to-date. The re-installation of the feature {name} should be processed first.”
- exception config.exceptions.sppasPermissionError(error_msg)[source]¶
Bases:
config.exceptions.sppasOSError
:ERROR 0513:.
Permission error: access to {place} is denied.
- exception config.exceptions.sppasTypeError(rtype, expected)[source]¶
Bases:
TypeError
:ERROR 0100:.
{!s:s} is not of the expected type ‘{:s}’.
- property status¶
- exception config.exceptions.sppasValueError(data_name, value)[source]¶
Bases:
ValueError
:ERROR 0300:.
Invalid value ‘{!s:s}’ for ‘{!s:s}’.
- property status¶
- exception config.exceptions.sppasWriteError(filename)[source]¶
Bases:
config.exceptions.sppasIOError
:ERROR 0660:.
File ‘{:s}’ can’t be saved.
config.logs module¶
- filename
sppas.src.config.logs.py
- author
Brigitte Bigi
- contact
- summary
Log system of SPPAS.
- class config.logs.sppasLogFile(pattern='log')[source]¶
Bases:
object
Manager for logs of SPPAS runs.
- class config.logs.sppasLogSetup(log_level=0)[source]¶
Bases:
object
A convenient class to initialize the python logging system.
- __init__(log_level=0)[source]¶
Create a sppasLogSetup instance.
By default, the NullHandler is assigned: no output. The numeric values of logging levels are the followings:
CRITICAL 50
ERROR 40
WARNING 30
INFO 20
DEBUG 10
NOTSET 0
Logging messages which are less severe than the given level value will be ignored. When NOTSET is assigned, all messages are printed.
- Parameters
log_level – Set the threshold logger value
- file_handler(filename)[source]¶
Start to redirect to logging FileHandler.
- Parameters
filename – a FileHandler has to be created using this filename.
config.makeunicode module¶
- filename
sppas.src.config.makeunicode.py
- author
Brigitte Bigi
- contact
- summary
Utilities for unicode.
makeunicode is useful for the compatibility of strings between Python 2.7 and Python > 3.2.
>>> token = "
Ỹ
ỏ "
>>> sp = sppasUnicode(token)
>>> token = sp.to_strip()
>>> token == u('Ỹ ỏ')
>>> True
- config.makeunicode.b(x)[source]¶
Convert to byte using encode().
- Parameters
x – a unicode string
- Returns
a string
- class config.makeunicode.sppasUnicode(entry)[source]¶
Bases:
object
Make a string as unicode and operates on it.
- __init__(entry)[source]¶
Create a sppasUnicode instance.
- Parameters
entry – (str or unicode or bytes in python 2)
config.po module¶
- filename
sppas.src.config.po.py
- author
Brigitte Bigi
- contact
- summary
Translation system of SPPAS.
- class config.po.T[source]¶
Bases:
object
Utility class to mimic the GNUTranslations class.
Backward compatibility of Python 2.7.
- config.po.error(msg_id, domain=None)[source]¶
Return the error message from gettext.
- Parameters
msg_id – (str or int) Error id
domain – (str) Name of the domain
- config.po.info(msg_id, domain=None)[source]¶
Return the info message from gettext.
- Parameters
msg_id – (str or int) Info id
domain – (str) Name of the domain
- config.po.msg(msg, domain=None)[source]¶
Return the message from gettext.
- Parameters
msg – (str) Message
domain – (str) Name of the domain
- class config.po.sppasTranslate[source]¶
Bases:
object
Fix the domain to translate messages and to activate the gettext method.
sppasTranslate is useful for the internationalization of texts. The locale is used to set the language but English is the default. The path to search for a domain translation is the one of the ‘po’ folder.
- Example
>>> _ = sppasTranslate().translation("domain").gettext >>> my_string = _("Some string in the domain.")
- DEFAULT_LOCALE = ['en']¶
config.process module¶
- filename
sppas.src.config.process.py
- authors
Florian Hocquet, Brigitte Bigi
- contact
- summary
Execute a subprocess and get results.
- class config.process.Process[source]¶
Bases:
object
A convenient class to execute a subprocess.
A Process is a wrapper of subprocess.Popen command.
- Launch a command:
>>> p = Process() >>> p.run_popen("ls -l")
- Return the stdout of the command:
>>> p.out()
- Return the stderr of the command:
>>> p.error()
- Stop a command:
>>> p.stop()
- Return the state of the command:
>>> p.is_running()
- run(command, timeout=120)[source]¶
Execute command with subprocess.run.
- Parameters
command – (str) The command to execute
timeout – (int) Will raise TimeoutExpired() after timeout seconds
- run_popen(command)[source]¶
Execute the given command with subprocess.Popen.
- Parameters
command – (str) The command to be executed
config.settings module¶
- filename
sppas.src.config.settings.py
- author
Brigitte Bigi
- contact
- summary
Store global modifiable or non-modifiable members.
- class config.settings.sppasAnnotationsSettings[source]¶
Bases:
config.settings.sppasBaseSettings
Representation of global non-modifiable settings of annotations.
- class config.settings.sppasBaseSettings[source]¶
Bases:
object
Base class to manage any kind of settings, represented in a dictionary.
A base class for any configuration or settings. Allows to store modifiable or un-modifiable members - by declaring a set() method, and to load/save them from/to a file each time the instance is created/deleted.
- Example
>>>with sppasBaseSettings() as settings: >>> settings.newKey = ‘myNewValue’ >>> print(settings.newKey)
- class config.settings.sppasGlobalSettings[source]¶
Bases:
object
Representation of global non-modifiable settings of SPPAS.
Includes the version, name, author, copyright, etc. These global settings are loaded from a JSON file.
- class config.settings.sppasPathSettings[source]¶
Bases:
config.settings.sppasBaseSettings
Representation of global non-modifiable paths of SPPAS.
- class config.settings.sppasSeparatorSettings[source]¶
Bases:
config.settings.sppasBaseSettings
Representation of global non-modifiable separators of SPPAS.
- class config.settings.sppasSymbolSettings[source]¶
Bases:
config.settings.sppasBaseSettings
Representation of global non-modifiable symbols of SPPAS.
This class defines:
unk: the default symbol used by annotations and resources to represent unknown entries
ortho: symbols used in an orthographic transcription, or after a text normalization
phone: symbols used to represent events in grapheme to phoneme conversion.
all: ortho+phone (i.e. all known symbols)
config.support module¶
- filename
sppas.src.config.support.py
- author
Brigitte Bigi
- contact
- summary
Support of SPPAS. Currently under development.
config.trash module¶
- filename
sppas.src.config.trash.py
- author
Brigitte Bigi
- contact
- summary
The application trash for backup files.
- class config.trash.sppasTrash[source]¶
Bases:
object
Utility manager of the Trash of SPPAS.
- __init__()[source]¶
Create a sppasTrash instance.
Create the trash directory if not already existing.
Module contents¶
- filename
sppas.src.config.__init__.py
- author
Brigitte Bigi
- contact
- summary
Package for the configuration of SPPAS.
config: configuration & globals of SPPAS¶
This package includes classes to fix all global parameters. It does not requires any other package but all other packages of SPPAS are requiring it!
All classes of this package are compatible with any version of python.
- exception config.IOExtensionError(filename)[source]¶
Bases:
config.exceptions.sppasIOError
:ERROR 0610:.
Unknown extension for filename ‘{:s}’.
- exception config.IndexRangeException(value, min_value, max_value)[source]¶
Bases:
config.exceptions.sppasValueError
:ERROR 0340:.
List index {} out of range [{},{}].
- exception config.IntervalRangeException(value, min_value, max_value)[source]¶
Bases:
config.exceptions.sppasValueError
:ERROR 0330:.
Value {} is out of range [{},{}].
- exception config.NegativeValueError(value)[source]¶
Bases:
config.exceptions.sppasValueError
:ERROR 0310:.
Expected a positive value. Got {value}.
- exception config.NoDirectoryError(dirname)[source]¶
Bases:
config.exceptions.sppasIOError
:ERROR 0620:.
The directory {dirname} does not exist.
- class config.Process[source]¶
Bases:
object
A convenient class to execute a subprocess.
A Process is a wrapper of subprocess.Popen command.
- Launch a command:
>>> p = Process() >>> p.run_popen("ls -l")
- Return the stdout of the command:
>>> p.out()
- Return the stderr of the command:
>>> p.error()
- Stop a command:
>>> p.stop()
- Return the state of the command:
>>> p.is_running()
- run(command, timeout=120)[source]¶
Execute command with subprocess.run.
- Parameters
command – (str) The command to execute
timeout – (int) Will raise TimeoutExpired() after timeout seconds
- run_popen(command)[source]¶
Execute the given command with subprocess.Popen.
- Parameters
command – (str) The command to be executed
- exception config.RangeBoundsException(min_value, max_value)[source]¶
Bases:
config.exceptions.sppasValueError
:ERROR 0320:.
Min value {} is bigger than max value {}.’
- config.b(x)[source]¶
Convert to byte using encode().
- Parameters
x – a unicode string
- Returns
a string
- config.error(msg_id, domain=None)[source]¶
Return the error message from gettext.
- Parameters
msg_id – (str or int) Error id
domain – (str) Name of the domain
- config.info(msg_id, domain=None)[source]¶
Return the info message from gettext.
- Parameters
msg_id – (str or int) Info id
domain – (str) Name of the domain
- config.msg(msg, domain=None)[source]¶
Return the message from gettext.
- Parameters
msg – (str) Message
domain – (str) Name of the domain
- class config.sppasAnnotationsSettings[source]¶
Bases:
config.settings.sppasBaseSettings
Representation of global non-modifiable settings of annotations.
- class config.sppasAppConfig[source]¶
Bases:
object
Configuration for SPPAS application.
An instance of this class has to be created for any application using the SPPAS API.
Members are:
log_level
splash_delay
features dictionary
- APP_CONFIG_FILENAME = '.app~'¶
- DEFAULT_LOG_LEVEL = 0¶
- __init__()[source]¶
Create a new sppasAppConfig instance.
The configuration is set to its default values and updated with the content of a configuration file (if existing).
The configuration is saved the 1st time this class is instantiated and when this class is deleted.
- feature_installed(key)[source]¶
Return True if a feature was successfully installed by SPPAS.
- Parameters
key – (str) Identifier of a feature.
- property log_level¶
Return the level for logging messages, ranging 0-50.
- class config.sppasBaseSettings[source]¶
Bases:
object
Base class to manage any kind of settings, represented in a dictionary.
A base class for any configuration or settings. Allows to store modifiable or un-modifiable members - by declaring a set() method, and to load/save them from/to a file each time the instance is created/deleted.
- Example
>>>with sppasBaseSettings() as settings: >>> settings.newKey = ‘myNewValue’ >>> print(settings.newKey)
- exception config.sppasEnableFeatureError(name)[source]¶
Bases:
config.exceptions.sppasOSError
:ERROR 0520:.
Feature {name} is not enabled; its installation should be processed first.
- exception config.sppasError(message)[source]¶
Bases:
Exception
:ERROR 0001:.
The following error occurred: {message}.
- property status¶
- exception config.sppasExtensionReadError(filename)[source]¶
Bases:
config.exceptions.sppasIOError
:ERROR 0670:.
Files with extension ‘{:s}’ are not supported for reading.
- exception config.sppasExtensionWriteError(filename)[source]¶
Bases:
config.exceptions.sppasIOError
:ERROR 0680:.
Files with extension ‘{:s}’ are not supported for writing.
- class config.sppasGlobalSettings[source]¶
Bases:
object
Representation of global non-modifiable settings of SPPAS.
Includes the version, name, author, copyright, etc. These global settings are loaded from a JSON file.
- exception config.sppasIOError(filename)[source]¶
Bases:
OSError
:ERROR 0600:.
No such file or directory: {name}
- property status¶
- exception config.sppasIndexError(index)[source]¶
Bases:
IndexError
:ERROR 0200:.
Invalid index value {:d}.
- property status¶
- exception config.sppasInstallationError(error_msg)[source]¶
Bases:
config.exceptions.sppasOSError
:ERROR 0510:.
Installation failed with error: {error}.
- exception config.sppasKeyError(data_name, value)[source]¶
Bases:
KeyError
:ERROR 0400:.
Invalid key ‘{!s:s}’ for data ‘{!s:s}’.
- property status¶
- class config.sppasLogFile(pattern='log')[source]¶
Bases:
object
Manager for logs of SPPAS runs.
- class config.sppasLogSetup(log_level=0)[source]¶
Bases:
object
A convenient class to initialize the python logging system.
- __init__(log_level=0)[source]¶
Create a sppasLogSetup instance.
By default, the NullHandler is assigned: no output. The numeric values of logging levels are the followings:
CRITICAL 50
ERROR 40
WARNING 30
INFO 20
DEBUG 10
NOTSET 0
Logging messages which are less severe than the given level value will be ignored. When NOTSET is assigned, all messages are printed.
- Parameters
log_level – Set the threshold logger value
- file_handler(filename)[source]¶
Start to redirect to logging FileHandler.
- Parameters
filename – a FileHandler has to be created using this filename.
- exception config.sppasOpenError(filename)[source]¶
Bases:
config.exceptions.sppasIOError
:ERROR 0650:.
File ‘{:s}’ can’t be open or read.
- exception config.sppasPackageFeatureError(package, name)[source]¶
Bases:
config.exceptions.sppasOSError
:ERROR 0530:.
The package {package} can’t be imported. The installation of the feature {name} should be processed first.
- exception config.sppasPackageUpdateFeatureError(package, name)[source]¶
Bases:
config.exceptions.sppasOSError
:ERROR 0540:.
The package {package} is not up-to-date. The re-installation of the feature {name} should be processed first.”
- class config.sppasPathSettings[source]¶
Bases:
config.settings.sppasBaseSettings
Representation of global non-modifiable paths of SPPAS.
- exception config.sppasPermissionError(error_msg)[source]¶
Bases:
config.exceptions.sppasOSError
:ERROR 0513:.
Permission error: access to {place} is denied.
- class config.sppasSeparatorSettings[source]¶
Bases:
config.settings.sppasBaseSettings
Representation of global non-modifiable separators of SPPAS.
- class config.sppasSymbolSettings[source]¶
Bases:
config.settings.sppasBaseSettings
Representation of global non-modifiable symbols of SPPAS.
This class defines:
unk: the default symbol used by annotations and resources to represent unknown entries
ortho: symbols used in an orthographic transcription, or after a text normalization
phone: symbols used to represent events in grapheme to phoneme conversion.
all: ortho+phone (i.e. all known symbols)
- class config.sppasTrash[source]¶
Bases:
object
Utility manager of the Trash of SPPAS.
- __init__()[source]¶
Create a sppasTrash instance.
Create the trash directory if not already existing.
- exception config.sppasTypeError(rtype, expected)[source]¶
Bases:
TypeError
:ERROR 0100:.
{!s:s} is not of the expected type ‘{:s}’.
- property status¶
- class config.sppasUnicode(entry)[source]¶
Bases:
object
Make a string as unicode and operates on it.
- __init__(entry)[source]¶
Create a sppasUnicode instance.
- Parameters
entry – (str or unicode or bytes in python 2)
- exception config.sppasValueError(data_name, value)[source]¶
Bases:
ValueError
:ERROR 0300:.
Invalid value ‘{!s:s}’ for ‘{!s:s}’.
- property status¶
- exception config.sppasWriteError(filename)[source]¶
Bases:
config.exceptions.sppasIOError
:ERROR 0660:.
File ‘{:s}’ can’t be saved.