vantage6.cli.context.server.ServerContext#
- class ServerContext(instance_name, system_folders=True)#
Bases:
BaseServerContext
Server context
- Parameters:
instance_name (str) – Name of the configuration instance, corresponds to the filename of the configuration file.
system_folders (bool, optional) – System wide or user configuration, by default S_FOL
- __init__(instance_name, system_folders=True)#
Create a new AppContext instance.
- Parameters:
instance_type (InstanceType) – Type of instance that is initialized
instance_name (str) – Name of the configuration
system_folders (bool) – Use system folders instead of user folders
config_file (str) – Path to a specific config file. If left as None, OS specific folder will be used to find the configuration file specified by instance_name.
print_log_header (bool) – Print a banner to the log file.
Methods
__init__
(instance_name[, system_folders])Create a new AppContext instance.
available_configurations
([system_folders])Find all available server configurations in the default folders.
config_exists
(instance_name[, system_folders])Check if a configuration file exists.
configure_logger
(name, level)Set the logging level of a logger.
find_config_file
(instance_type, ...[, ...])Find a configuration file.
from_external_config_file
(path[, system_folders])Create a server context from an external configuration file.
get_data_file
(filename)Return the path to a data file.
Obtain the database uri from the environment or the configuration.
initialize
(instance_type, instance_name[, ...])Initialize the AppContext instance.
instance_folders
(instance_type, ...)Return OS and instance specific folders for storing logs, data and config files.
log_file_name
(type_)Return a path to a log file for a given log file type
Print the log file header.
set_folders
(instance_type, instance_name, ...)Set the folders where the configuration, data and log files are stored.
Setup a basic logging mechanism.
type_data_folder
(instance_type, system_folders)Return OS specific data folder.
Attributes
LOGGING_ENABLED
Return the path to the configuration file.
Return the name of the configuration file.
Name of the docker container that the server is running in.
Return the path to the log file.
- INST_CONFIG_MANAGER#
alias of
ServerConfigurationManager
- classmethod available_configurations(system_folders=True)#
Find all available server configurations in the default folders.
- Parameters:
system_folders (bool, optional) – System wide or user configuration, by default S_FOL
- Returns:
The first list contains validated configuration files, the second list contains invalid configuration files.
- Return type:
tuple[list, list]
- classmethod config_exists(instance_name, system_folders=True)#
Check if a configuration file exists.
- Parameters:
instance_name (str) – Name of the configuration instance, corresponds to the filename of the configuration file.
system_folders (bool, optional) – System wide or user configuration, by default S_FOL
- Returns:
Whether the configuration file exists or not
- Return type:
bool
- property config_file: Path#
Return the path to the configuration file.
- Returns:
Path to the configuration file
- Return type:
Path
- property config_file_name: str#
Return the name of the configuration file.
- Returns:
Name of the configuration file
- Return type:
str
- static configure_logger(name, level)#
Set the logging level of a logger.
- Parameters:
name (str) – Name of the logger to configure. If None, the root logger is configured.
level (str) – Logging level to set. Must be one of ‘debug’, ‘info’, ‘warning’, ‘error’, ‘critical’.
- Returns:
The logger object and the logging level that was set.
- Return type:
Tuple[Logger, int]
- property docker_container_name: str#
Name of the docker container that the server is running in.
- Returns:
Server’s docker container name
- Return type:
str
- classmethod find_config_file(instance_type, instance_name, system_folders, config_file=None, verbose=True)#
Find a configuration file.
- Parameters:
instance_type (InstanceType) – Type of instance that is checked
instance_name (str) – Name of the configuration
system_folders (bool) – Use system folders rather than user folders
config_file (str | None) – Name of the configuration file. If None, the name of the configuration is used.
verbose (bool) – Print the directories that are searched for the configuration file.
- Returns:
Path to the configuration file
- Return type:
str
- Raises:
Exception – If the configuration file is not found
- classmethod from_external_config_file(path, system_folders=True)#
Create a server context from an external configuration file. External means that the configuration file is not located in the default folders but its location is specified by the user.
- Parameters:
path (str) – Path of the configuration file
system_folders (bool, optional) – System wide or user configuration, by default S_FOL
- Returns:
Server context object
- Return type:
- get_data_file(filename)#
Return the path to a data file.
- Parameters:
filename (str) – Name of the data file
- Returns:
Path to the data file
- Return type:
str
- get_database_uri()#
Obtain the database uri from the environment or the configuration.
- Returns:
string representation of the database uri
- Return type:
str
- initialize(instance_type, instance_name, system_folders=False, config_file=None, print_log_header=True)#
Initialize the AppContext instance.
- Parameters:
instance_type (str) – ‘server’ or ‘node’
instance_name (str) – Name of the configuration
system_folders (bool) – Use system folders rather than user folders
config_file (str) – Path to a specific config file. If left as None, OS specific folder will be used to find the configuration file specified by instance_name.
print_log_header (bool) – Print a banner to the log file.
- Return type:
None
- static instance_folders(instance_type, instance_name, system_folders)#
Return OS and instance specific folders for storing logs, data and config files.
- Parameters:
instance_type (InstanceType) – Type of instance that is checked
instance_name (str) – Name of the configuration
system_folders (bool) – Use system folders rather than user folders
- Returns:
Dictionary with Paths to the folders of the log, data and config files.
- Return type:
dict
- property log_file: Path#
Return the path to the log file.
- Returns:
Path to the log file
- Return type:
Path
- log_file_name(type_)#
Return a path to a log file for a given log file type
- Parameters:
type (str) – The type of log file to return.
- Returns:
The path to the log file.
- Return type:
Path
- Raises:
AssertionError – If the configuration manager is not initialized.
- print_log_header()#
Print the log file header.
- Return type:
None
- set_folders(instance_type, instance_name, system_folders)#
Set the folders where the configuration, data and log files are stored.
- Parameters:
instance_type (InstanceType) – Type of instance that is checked
instance_name (str) – Name of the configuration
system_folders (bool) – Whether to use system folders rather than user folders
- Return type:
None
- setup_logging()#
Setup a basic logging mechanism.
Exits if the log file can’t be created.
- Return type:
None
- static type_data_folder(instance_type, system_folders)#
Return OS specific data folder.
- Parameters:
instance_type (InstanceType) – Type of instance that is checked
system_folders (bool) – Use system folders rather than user folders
- Returns:
Path to the data folder
- Return type:
Path