Library Reference
The lib.i18n Module
Localization management.
The lib.utils Module
Some various utilities.
- cioservice.lib.utils.location2abs_base(locations: dict, location_id: str) str | None[source]
Return the absolute path to the base of location
location_id.
- cioservice.lib.utils.location_path2abs_path(locations: dict, location_path: str) str | None[source]
Return an absolute path for a location path using the dictionary of locations. A location path must contain
':'('private:MyDocument') and can begin with'/'('/Sandbox:Images/foo.png').- Pram dict locations:
Dictionary of locations. It can be updated during the operation.
- Parameters:
path (str) – Location path.
- Return type:
class:str or
None
The lib.service Module
Base class for services.
- class cioservice.lib.service.Service(registry: ScriptRegistry)[source]
Base class to manage a service.
- Parameters:
registry (chrysalio.scripts.ScriptRegistry) – Application registry.
- classmethod register(environment, service_class)[source]
Method to register the service.
- Parameters:
environment (
pyramid.config.Configuratorordict) – Object used to do configuration declaration within the application or a ScriptRegistry to simulate the application registry.service_class – Service class.
- need_dialog(context: str) bool[source]
Return
Trueif this service needs a dialog box before launching.
- need_write_permission(context: str) bool[source]
Return
Trueif this service needs permission to write output files.
- select_files(params: dict)[source]
Select in the build parameters dictionary files which are candidate for the service.
- Parameters:
params (dict) – Dictionary defining the parameters of the build.
- select_files_message(params: dict) str[source]
Return a message specifying files to be selected.
- Parameters:
params (dict) – Dictionary defining the parameters of the build.
- Return type:
pyramid.i18n.TranslationString
- make_build(build_id: str, params: dict, stopping: Event | None = None) Build[source]
Create a build object.
- Parameters:
build_id (str) – ID of the build.
params (dict) – Dictionary defining the parameters of the build. It has the keys
'job_id','context','lang','ttl',settings,'values','files','resources'and'output'. It possibly has the key'dbsession'.stopping (threading.Event) – (optional) Flag to stop the processing.
- Return type:
.lib.build
- run(build: Build) dict[source]
Prepare the service for execution and launch it.
- Parameters:
build (.lib.build.Build) – Current build object.
- Return type:
- Returns:
A dictionary of results.
- write_traces(build: Build, domain: str | None = None)[source]
Write trace messages into the database and/or a log file.
- Parameters:
build (.lib.build.Build) – Current build object
domain (str) – (optional) Domain of the log.
- write_running(build: Build)[source]
Write a “running” message into the database.
- Parameters:
build (.lib.build.Build) – Current build object
- erase_running(build: Build)[source]
Erase the “running” message in the database.
- Parameters:
build (.lib.build.Build) – Current build object
- variables(context: str | None, request: Request | None = None) dict[source]
Return an ordered dictionary of variables.
- Parameters:
context (str) – Context name (processor ID…).
request (pyramid.request.Request) – (optional) Current request.
- Return type:
Each variable has a name (the key in the ordered dictionary and a describing dictionary with the following keys:
'group': home group'type'(required): a type among'string','boolean','integer','decimal','regex'and'list''label'(required)'hint': a hint to set the variable'required': a boolean to specify if the variable must have a value'visible': the variable is visible before launching'default': default value'regex': a string required for regex type only'options': a dictionary required for list type only
- variables_groups(context: str, request: Request) dict[source]
Return a dictionary of groups of variables.
- Parameters:
context (str) – Context name (processor ID…).
request (pyramid.request.Request) – Current request.
- Return type:
- values_tabview(request: Request, context: str, form: Form, values: dict) str[source]
Generate the value tab.
- Parameters:
request (pyramid.request.Request) – Current request.
context (str) – Context name (processor ID…).
form (.lib.form.Form) – Current form object.
values (dict) – Values of the variables.
- Return type:
- values_schema(schema, defaults: dict, dbjob: DBJob, visible_only: bool = False, relax: bool = False)[source]
Update a Colander schema with default values for form with values.
- Parameters:
schema (colander.SchemaNode) – Colander schema to update.
defaults (dict) – Dictionary of default values for a form.
dbjob (.models.dbjob.DBJob) – SQLAlchemy object DBJob.
visible_only (bool) – (default=False) If
True, list only visible variables.relax (bool) – (default=False) If
True,requiredis ignored.
- values_tabedit(request: Request, context: str, form: Form, visible_only: bool = False) str[source]
Generate the value tab for edition.
- Parameters:
request (pyramid.request.Request) – Current request.
context (str) – Context name (processor ID…).
form (.lib.form.Form) – Current form object.
- Pram bool visible_only:
(default=False) If
True, list only visible variables.- Return type:
chrysalio.helpers.literal.Literal
The lib.build Module
Build management.
- class cioservice.lib.build.Build(lock_dir, manager, build_id, params, stopping)[source]
This class manages a build.
- Parameters:
lock_dir (str) – Absolute path to a directory which stores the lock files.
manager (.lib.build_manager) – Manager for this build.
build_id (str) – Build ID.
params (dict) – Dictionary defining the parameters of the build.
stopping (threading.Event) – Flag to stop the processing.
A build has the following keys attributes:
'job_id': job ID'uid': build ID'context': Name of the context (processor ID…)'lang': prefered language for messages'ttl': Time To Live for an execution'deadline': deadline for the run'settings': settings for this build'values': values for the variables'files': list of files to process'resources': list of resources'locations': dictionary of locations of templates or warehouses'caller': a dictionary with login, name and email of the caller'callback': ID of the callback function'dbsession': possible current SQLAlchemy session'output': absolute path to the possible output directory'stopping':threading.Eventas a Flag to stop the processing'current': a dictionary describing the file under processing'result': dictionary containing the result
The
build.currentdictionary have the following keys:'input_file': absolute path to the original input file'fup': absolute path to the File Under Processing
The
build.resultdictionary has, at least, following keys:'no_execution':Trueif the execution is impossible'infos': information messages'warnings': warning messages'errors': errors messages'traces': log'files': list of absolute paths to successful files'output': if success, an absolute or relative path to the resultdirectory
It may have:
'output_url': a possibly URL to the result directory'to_refresh': a list of relative path to refresh
- output_info(output=None)[source]
Add ‘output’ key in the build result and add an information with location of the result, possibly as a link.
- Parameters:
output (str) – (optional) Forced ouput.
- progress()[source]
Return the progress of the build .
- Return type:
- Returns:
A tuple such as
(file_percent, file_name, step_percent, step_trace).
- dbsession_factory()[source]
Retrieve a DB session maker function if the current
self.dbsessionisNone.- Return type:
sqlalchemy.orm.session.sessionmaker()orNone
- attachments_path()[source]
Return a absolute path to the attachments directory or
None.- Return type:
class:str or
None
The lib.build_manager Module
Management of parallelized builds.
- class cioservice.lib.build_manager.BuildManager(concurrency: int = 3, registry: Registry | None = None)[source]
This class manages the launch of parallelized builds.
- Parameters:
concurrency (int) – (default=DEFAULT_CONCURRENCY) Maximum number of builds running at the same time.
registry – Application registry or registry like.
The build environment is a dictionary with the following keys:
'job': job dictionary'params': dictionary of parameters for the build'status': current status ('pending','in_spool','running','stopping'or'completed')'launch': launch time'duration': duration of the processing'result': (optional) result of the processing
- set_registry(registry: Registry)[source]
Set the internal registry.
- Parameters:
registry – Application registry or registry like.
- build_env(build_id: str, check_stopping: bool = False) dict | None[source]
Return the build environment for build build_id.
- run(build_id: str, build_env: dict | None = None) str | None[source]
Add a build to the spool and try to launch it.
- set_progress(build_id: str, progress: list)[source]
Save the current progress value in the build environment.
- stop(build_id: str, build_env: dict | None = None) dict | None[source]
Stop a build and return its environment.
- completed(build_id: str, callback_id: str, result: dict)[source]
Call back for a completed build.
- Parameters:
build_id (str) – ID of the completed build.
callback_id (str) – ID of the callback function.
result (dict) – Result of the processing. See:
lib.build.Build.
- classmethod clean_logs(dbsession)[source]
Clean up old logs.
- Parameters:
dbsession (sqlalchemy.orm.session.Session) – SQLAlchemy session.
- set_launch_time(build_id: str, build_env: dict)[source]
Set the launch time and reset the duration.
- class cioservice.lib.build_manager.ServiceThread(service, build_id, params, callback)[source]
A thread to execute a service.
- Parameters:
See
lib.service.Service.run()for details onparams.The attribute
resultcontains the result of the processing.