Library Reference

The lib.i18n Module

Localization management.

cioprocessor.lib.i18n.translate(text, lang=None, request=None)[source]

Return text translated.

Parameters:
  • text (str) – Text to translate.

  • lang (str) – (optional) Language to use.

  • request (pyramid.request.Request) – (optional) Current request to find the current language.

Return type:

str

The lib.utils Module

Some various utilities.

cioprocessor.lib.utils.cioset_path2full_path(file_elt)[source]

Find the full path for the file of a cioset pointed by file_elt, possibly according to <root> tags.

Parameters:

file_elt (lxml.etree.Element) – Cioset XML file element for the current file.

Return type:

str

cioprocessor.lib.utils.cioset_path2location_path(base_id, cioset_relpath, file_elt)[source]

Find the location path of the file pointed in a cioset file by file_elt, possibly according to <root> tags.

Parameters:
  • base_id (str) – ID of the base directory of the cioset file.

  • cioset_relpath (str) – Relative path in the warehouse to the cioset file.

  • file_elt (lxml.etree.Element) – Cioset XML file element for the current file.

Return type:

str or None

cioprocessor.lib.utils.cioset_path2abs_path(locations, cioset_abspath, file_elt)[source]

Find the abosulte path of the file pointed in a cioset file by file_elt, possibly according to <root> tags.

Pram dict locations:

Dictionary of locations. It can be updated during the operation.

Parameters:
  • cioset_path (str) – Relative path in the warehouse to the cioset file.

  • file_elt (lxml.etree.Element) – Cioset XML file element for the current file.

Return type:

str or None

cioprocessor.lib.utils.guess_home(abs_file, settings=None, locations=None)[source]

Try to guess a base directory for this file and an ID for this base directory. In the case of warehouses, it is the root of the warehouse containing the file and its ID.

Parameters:
  • abs_file (str) – Absolute path to an existing file.

  • settings (dict) – (optional) Settings with possibly 'input.home.path' and input.home.id' keys.

  • locations (dict) – (optional) Dictionary of locations. It can be updated during the operation.

Return type:

tuple

Returns:

A tuple such as (home_path, home_id).

cioprocessor.lib.utils.remove_empty_directories(root)[source]

Recursively remove empty directories.

Parameters:

root (str) – Absolute path to the root directory to clean.

cioprocessor.lib.utils.clean_directory(directory, regex)[source]

Clean up a directory according to a regular expression.

Parameters:
  • directory (str) – Absolute path to the directory to clean.

  • regex – Regular expression to select files to clean.

cioprocessor.lib.utils.select_files(pbuild, step)[source]

Return files, possibly in a subdirectory, according to a regular expression.

Parameters:
  • pbuild (.lib.pbuild.PBuild) – Current processor build object.

  • step (dict) – Dictionary defining the current step.

Return type:

generator

cioprocessor.lib.utils.select_file(processor, abs_file, files=None, is_dir=None)[source]

If the abs_file meets the expected criteria, return True and, possibly, add it to the files dictionary.

Parameters:
  • processor (.lib.processor.Processor) – Processor object.

  • abs_file (str) – Absolute path to the file to analyse.

  • files (dict) – (optional) Dictionary to complete.

  • is_dir (bool) – (optional) True if abs_file is a directory.

Return type:

bool

cioprocessor.lib.utils.abs_output(pbuild)[source]

Return an absolute path to the output directory.

Parameters:

pbuild (.lib.pbuild.PBuild) – Current processor build object.

Return type:

str

The lib.pservice Module

Processor as a service.

class cioprocessor.lib.pservice.PService(registry: ScriptRegistry)[source]

Class to manage a processor as a service. It uses a PBuild instead of a Build.

need_write_permission(context: str) bool[source]

Return True if this service needs input files.

See: chrysalio.lib.service.Service.need_write_permission()

select_files(params: dict)[source]

Select in the build parameters dictionary files which are candidate for the service.

See: cioservice.lib.service.Service.select_files()

select_files_message(params: dict) str[source]

Return a message specifying files to be selected.

See: cioservice.lib.service.Service.select_files_message()

make_build(build_id: str, params: dict, stopping: Event | None = None) Build[source]

Create a pbuild object.

See: cioservice.lib.service.Service.make_build()

variables(context: str | None, request: Request | None = None) dict[source]

Return an ordered dictionary of variables.

See: cioservice.lib.service.Service.variables()

variables_groups(context: str, request: Request) dict[source]

Return a dictionary of groups of variables.

See: cioservice.lib.service.Service.variables_groups()

The lib.pbuild Module

Processor build (pbuild) management.

class cioprocessor.lib.pbuild.PBuild(processor, manager: BuildManager, pbuild_id: str, params: dict, stopping: Event | None)[source]

This class manages a processor build (pbuild).

Parameters:
  • processor (.lib.processor.Processor) – Processor object.

  • manager (cioservice.lib.build_manager) – Manager for this build.

  • pbuild_id (str) – Processor build ID.

  • params (dict) – Dictionary defining the parameters of the processor build.

  • stopping (threading.Event) – Flag to stop the processing.

In addition to the Build attributes, a processor build has the following attributes:

  • 'environment': processor environment

  • 'directories': a dictionary of absolute pathes to directories

  • 'relaxngs': a dictionary of Relax NG objects

  • 'steps': list of steps for this build

  • 'rel_files': dictionary of relative paths in recursive mode

The pbuild.directories dictionary have the following keys:

  • 'root': absolute path to the root directory of the build

  • 'processor': absolute path to the processor directory

  • 'ongoing': absolute path to the global ongoing directory

  • 'result': absolute path to the result directory

The pbuild.current dictionary have the following keys:

  • 'input_file': absolute path to the original input file

  • 'input_base': possibly absolute path to the base (warehouse)

  • 'input_base_id': possibly ID of the base

  • 'input_relpath': relative path of the input with respect to the base

  • 'values': common defines and values overrided by local values

  • 'step_delta': the delta of step progress for this file

  • 'file_id': ID of the current file

  • 'workdir': absolute path to the directory where work takes place

  • 'fup': absolute path to the File Under Processing

  • 'dup': Data Under Process in a native format (DOM, plain…)

  • 'resources': common resources possibly completed by local resources

  • 'template': relative path to the used processor template

  • 'abs_template': absolute path to the used processor template

  • 'xml_declaration': True if we have to keep <?xml version=’1.0’?>

lock() bool[source]

Lock the processor build.

Return type:

bool

unlock()[source]

Unlock the processor build.

relock()[source]

Refresh the lock of the build.

current_reset() bool[source]

Reset current environment and lock for the next file.

Return type:

bool

Returns:

True if we can continue.

current_initialize(input_file: str | None) dict[source]

Return a current environment initialized according to the input file.

Parameters:

input_file (str) – Absolute path to the input file.

Return type:

dict

currents(input_file: str)[source]

Iterator to retrieve the current environments for the file input_file.

Parameters:

input_file (str) – Absolute path to the input file.

current_assembly(user_uid: int, current: dict, cioset: ElementTree) dict | None[source]

Select assembly to do.

Parameters:
  • user_uid (int) – Current user UID.

  • current (dict) – Dictionary representing the current object to process.

  • cioset (lxml.etree.ElementTree) – Root element of the cioset.

Return type:

bool

Returns:

None or current.

current_abs_resources() list | tuple[source]

Return a list of absolute paths to the current resources.

Return type:

list

assembly_xml(user_uid: int, current: dict, cioset: ElementTree, step_num: int = 0) str | None[source]

Assemble all XML file found in the cioset input file into one XML file.

Parameters:
  • user_uid (int) – Current user UID.

  • current (dict) – Dictionary representing the current object to process.

  • cioset (lxml.etree.ElementTree) – Root element of the cioset.

  • step_num (int) – (default=0) Number of current step.

Return type:

bool

Return type:

class:pyramid.i18n.TranslationString or None

Returns:

Error message or None.

save_dup(filename: str, force: bool = False, current: dict | None = None) str | None[source]

Save current Data Under Process into a file.

Parameters:
  • filename (str) – Relatve path to the current path of the file to save.

  • force (bool) – (default=False) If True, copy the file even if exists with an another name.

  • current (dict) – (optional) Forced current environment.

Return type:

str

Returns:

Relative path of saved file or None.

dup2unicode()[source]

Convert Data Under Process into a string.

dup2xml() str | None[source]

Convert Data Under Process into a XML DOM tree.

Return type:

pyramid.i18n.TranslationString

Returns:

An error message or None.

media_cache(target: str, dependencies: list) bool[source]

Try to retrieve the media from the previous result.

Parameters:
  • target (str) – Full path to target file.

  • dependencies (list) – List of files to compare with to known if it is necessary to process.

Return type:

bool

make_fid(input_file: str) str | None[source]

Create a file ID from input_file.

Parameters:

input_file (str) – Absolute path to the input file.

Return type:

str

info(text: str)[source]

Add an information message in the result.

Parameters:

text (str) – Information.

warning(text: str)[source]

Add a warning message in the result.

Parameters:

text (str) – Warning.

error(text: str)[source]

Add an error message in the result.

Parameters:

text (str) – Error.

translate(text: str) str[source]

Return text translated.

Parameters:

text (str) – Text to translate.

Return type:

str

The lib.step Module

Collection of processor steps.

class cioprocessor.lib.step.Step[source]

This class manages processor steps.

classmethod execute(pbuild, step)[source]

Execute a step on a pbuild.

Parameters:
  • pbuild (.lib.pbuild.PBuild) – Current processor build object.

  • params (dict) – Dictionary of parameter of the current step.

Return type:

pyramid.i18n.TranslationString or None

classmethod check(pbuild, step)[source]

Execute a check of the current file.

Parameters:
  • pbuild (.lib.pbuild.PBuild) – Current processor build object.

  • step (dict) – Dictionary defining the current step.

Return type:

pyramid.i18n.TranslationString

Returns:

An error message or None.

classmethod makedir(pbuild, step)[source]

Make a directory.

Parameters:
  • pbuild (.lib.pbuild.PBuild) – Current processor build object.

  • step (dict) – Dictionary defining the current step.

Return type:

pyramid.i18n.TranslationString

Returns:

An error message or None.

classmethod copy(pbuild, step)[source]

Copy files from processor directory to current path.

Parameters:
  • pbuild (.lib.pbuild.PBuild) – Current processor build object.

  • step (dict) – Dictionary defining the current step.

Return type:

pyramid.i18n.TranslationString

Returns:

An error message or None.

classmethod copy_resource(pbuild, step)[source]

Copy files from resources to current path.

Parameters:
  • pbuild (.lib.pbuild.PBuild) – Current processor build object.

  • step (dict) – Dictionary defining the current step.

Return type:

pyramid.i18n.TranslationString

Returns:

An error message or None.

classmethod copy_template(pbuild, step)[source]

Copy files from template directory to current path.

Parameters:
  • pbuild (.lib.pbuild.PBuild) – Current processor build object.

  • step (dict) – Dictionary defining the current step.

Return type:

pyramid.i18n.TranslationString

Returns:

An error message or None.

classmethod extract_ocf(pbuild, step)[source]

Extract an OCF ZIP container and replace the current file by the first root file.

Parameters:
  • pbuild (.lib.pbuild.PBuild) – Current processor build object.

  • step (dict) – Dictionary defining the current step.

Returns:

An error message or None.

classmethod regex(pbuild, step)[source]

Execute a transformation with a regular expression.

Parameters:

step (dict) – Dictionary defining the current step.

Return type:

pyramid.i18n.TranslationString

Returns:

An error message or None.

classmethod xsl(pbuild, step)[source]

Execute a transformation with a XSL file.

Parameters:
  • pbuild (.lib.pbuild.PBuild) – Current processor build object.

  • step (dict) – Dictionary defining the current step.

Return type:

pyramid.i18n.TranslationString

Returns:

An error message or None.

classmethod python(pbuild, step)[source]

Execute a transformation with a python script.

Parameters:
  • pbuild (.lib.pbuild.PBuild) – Current processor build object.

  • step (dict) – Dictionary defining the current step.

Return type:

pyramid.i18n.TranslationString

Returns:

An error message or None.

classmethod unzip(pbuild, step)[source]

Extract ZIP file and possibly replace the current file by the entry point.

Parameters:
  • pbuild (.lib.pbuild.PBuild) – Current processor build object.

  • step (dict) – Dictionary defining the current step.

Returns:

An error message or None.

classmethod zipize(pbuild, step)[source]

Create zip a directory or a file.

Parameters:
  • pbuild (.lib.pbuild.PBuild) – Current processor build object.

  • step (dict) – Dictionary defining the current step.

Return type:

pyramid.i18n.TranslationString

Returns:

An error message or None.

classmethod epubize(pbuild, step)[source]

Create an ePub.

Parameters:
  • pbuild (.lib.pbuild.PBuild) – Current processor build object.

  • step (dict) – Dictionary defining the current step.

Return type:

pyramid.i18n.TranslationString

Returns:

An error message or None.

classmethod remove(pbuild, step)[source]

Remove files in current path or one of its sub-directories according to a regular expression.

Parameters:
  • pbuild (.lib.pbuild.PBuild) – Current processor build object.

  • step (dict) – Dictionary defining the current step.

Return type:

pyramid.i18n.TranslationString

Returns:

An error message or None.

classmethod set_icon(pbuild, step)[source]

Copy an icon file into the ongoing directory.

Parameters:
  • pbuild (.lib.pbuild.PBuild) – Current processor build object.

  • step (dict) – Dictionary defining the current step.

Return type:

pyramid.i18n.TranslationString

Returns:

An error message or None.

classmethod stop(pbuild, step)[source]

Stop the process if corresponding variable is set to True.

Parameters:
  • pbuild (.lib.pbuild.PBuild) – Current processor build object.

  • step (dict) – Dictionary defining the current step.

Returns:

A STOP message or None.

The lib.iniscript Module

INI scripts management.

class cioprocessor.lib.iniscript.IniScript[source]

Class for INI script managment.

execute(pbuild, step)[source]

Interprete INI file generated by XSL transformation.

Parameters:
  • pbuild (.lib.pbuild.PBuild) – Current processor build object.

  • step (dict) – Dictionary defining the current step.

Return type:

pyramid.i18n.TranslationString

Returns:

An error message or None.

The lib.epubize Module

ePub Generation.

class cioprocessor.lib.epubize.EPubize[source]

Class to transform a directory into an ePub.

convert(step, epub_dir, epub_file)[source]

Convert a dictionary into an ePub according to step.

Parameters:
  • step (dict) – Dictionary representing step of type epubize.

  • epub_dir (str) – Absolute path to the directory representing the ePub.

  • epub_file (str) – Absolute path to the ePub to create.

Return type:

pyramid.i18n.TranslationString or None

The lib.pytransform Module

Base class for py-tranform step.

class cioprocessor.lib.pytransform.PyTransform(pbuild, step)[source]

This class manages a py-transform step.

Parameters:
  • pbuild (.lib.pbuild.PBuild) – Current processor build object.

  • step (dict) – Dictionary defining the current step.

run()[source]

Execute the transformation.

Return type:

pyramid.i18n.TranslationString

Returns:

An error message or None.