Agent Library Reference¶
The lib.build.agent Module¶
Agent build management.
An agent is a Web service.
-
class
publiforge.lib.build.agent.AgentBuildManager(settings)[source]¶ This class manages agent builds.
One instance of
AgentBuildManageris created during application initialization. It is only used in agent mode. It is stored in application registry.self._processorsis a tuple such as(processor_dictionary, root_list, available_list).processor_dictionaryis a dictionary such as{processor_id: processor_path,...}.self._frontsis a dictionary such as{front_id: password,...}.self._buildsis a dictionary ofAgentBuildobjects.self._resultsis a dictionary of dictionaries such as{build_id: result_dict}.result_dictis a dictionary with following keys:status,log,expire. According to build events, it can also containsfiles,valuesanderrorkeys.self._results[build_id]['status']is one of the following strings:a_stop,a_fatalora_end.self._results[build_id]['log']is a list of tuples such as(timestamp, step, percent, message).-
processor_list()[source]¶ Refresh information and return a list of available processors and the number of possible concurrent builds.
Returns: (tuple) A tuple such as (processor_list, concurrent).
-
add_processors(path)[source]¶ Add all processors in path
path.Parameters: path – (string) Where to look for processors.
-
processor_path(processor_id)[source]¶ Return processor path if exists.
Parameters: processor_id – (string) Processor ID. Returns: (string)
-
processor_xml(processor_id)[source]¶ Return processor XML if exists.
Parameters: processor_id – (string) Processor ID. Returns: (string)
Trueiffront_idis authorized to use agent services.
-
activity()[source]¶ Return the global activity i.e. the number of active or pending builds.
Returns: (integer) Number of builds or -1 if the maximum number is reached.
-
synchronizing(build_id, lock=True)[source]¶ Data synchronization for the build
build_id.Parameters: - build_id – (string) Build ID.
- lock – (boolean, default=True)
If
Truetry to add buildbuild_idin the list of synchronizations.
Returns: (boolean)
-
start_build(build_id, context, processing, pack, end_url=None)[source]¶ Create a build, add it in
self._buildsdictionary and try to start it.Parameters: - build_id – (string) Build ID.
- context – (dictionary)
See
FrontBuildManagercall()method. - processing – (dictionary) A processing dictionary.
- pack – (dictionary) A pack dictionary.
- end_url – (string, optional) URL to call to complete the build.
Returns: (
AgentBuildorNone)
-
progress(build_id)[source]¶ Return the progress of build.
Parameters: build_id – (string) Build ID. Returns: (tuple) A tuple such as (<step>, <percent>, <message>).The step
<step>is one of the following:a_start: startinga_env: importing processor environmenta_build: buildinga_warn: a warning occurreda_error: an error occurreda_fatal: a fatal error occurreda_stop: stoppinga_end: successfully completednone: unknown or not in progress build
-
-
class
publiforge.lib.build.agent.AgentBuild(build_manager, build_id, context, processing, pack, end_url)[source]¶ This class manages one local build.
self.resultis a dictionary with the following keys:status,message,log. Log entry is a list of tuples such as(<timestamp>, <step>, <percent>, <message>). Processor can add keys like:files,values.-
stopped(error=None, level='a_fatal')[source]¶ Check if there is a fatal error and if the build is stopped.
Parameters: Return type: Returns: Trueif it is stopped.
-
get_in_attic(target, dependencies=None, relations=None)[source]¶ Try to retrieve the last version of a file in the attic and copy it in the
Outputdirectory.Parameters: - target – (string) Path to target file.
- dependencies – (list, optional) List of files to compare with to known if it is necessary to process.
- relations – (list, optional) List of closely related files to retrieve with the target file.
Returns: (boolean)
Trueif the operation succeeded.
-
message(text)[source]¶ Add a message in
result['values'].Parameters: text – (string or pyramid.i18n.TranslationString) Message text.
-
Modules¶
A processor use a module to realize its processing.
-
publiforge.lib.processor.load_relaxngs(build, config)[source]¶ Load Relax NG files defined in configuration.
Parameters: - build – (
AgentBuild) Main Build object. - config – (
ConfigParser.ConfigParserinstance) Configuration with a[RelaxNG]section.
Returns: (dictionary) A dictionary of
lxml.etree.RelaxNGobjets.- build – (
-
publiforge.lib.processor.bin_directory()[source]¶ Return absolute path to PubliForge binary directory.
The lib.processor.validator Module¶
This module validates XML files against their Relax NG.
The lib.processor.leprisme Module¶
LePrisme module transforms files into another files or values.
-
class
publiforge.lib.processor.leprisme.Processor(build)[source]¶ Main class for LePrisme processor.
-
config(section, option, default=None)[source]¶ Retrieve a value from a configuration object.
Parameters: - section – (string) Section name.
- option – (string) Option name.
- default – (string, optional) Default value
Returns: (string) Read value or default value.
-
config_list(section, option, default=None)[source]¶ Retrieve a list of values from a configuration object.
Parameters: - section – (string) Section name.
- option – (string) Option name.
- default – (list, optional) Default values.
Returns: (list)
-
XML Transformation via XSL stylesheet.
-
class
publiforge.lib.processor.leprisme.transform.Transform(processor, steps)[source]¶ Class for XML transformation.
Publiset management.
-
class
publiforge.lib.processor.leprisme.publiset.Publiset(processor, base_path)[source]¶ Class for Publiset management.
-
fullname(file_elt)[source]¶ Find the full path of a file from a file tag.
Parameters: file_elt – (etree.Element object) File element. Returns: (string) Full path name.
-
INI scripts management.
-
class
publiforge.lib.processor.leprisme.iniscript.IniScript(processor)[source]¶ Class for INI script managment.
-
convert_media(filename, ini_file, done_tag, percent)[source]¶ Convert a media (image, audio or video).
Parameters: - filename – (string) Relative path to the original file to transform.
- ini_file – (string) Path to INI file.
- done_tag – (string) Tag to mark the once the conversion is done.
- percent – (integer) Percentage of progress.
Returns: (boolean)
-
post_execution(ini_file, target_file, done_tag)[source]¶ Process post INI script.
Parameters: - ini_file – (string) Path to INI file.
- target_file – (string) Path to target file.
- done_tag – (string) Tag to mark the once the conversion is done.
-
find_media(media_type, media_id, patterns, target=None)[source]¶ Look for a media.
Parameters: - media_type – (string) Type of media (image, audio or video).
- media_id – (string) Media ID.
- patterns – (list) List of patterns to check.
- target – (string, optional) Full path to target file.
Returns: (string) Full path to source file or
None.
-
Container factory management.
-
class
publiforge.lib.processor.leprisme.containers.ZipFactory(processor)[source]¶ Class for Zip container.
The lib.processor.publiseter Module¶
This module makes Publiset XML file from a pack structure.
-
class
publiforge.lib.processor.publiseter.Processor(build)[source]¶ Main class for Publiseter processor.
-
config(section, option, default=None)[source]¶ Retrieve a value from a configuration object.
Parameters: - section – (string) Section name.
- option – (string) Option name.
- default – (string, optional) Default value
Returns: (string) Read value or default value.
-
The lib.processor.generator Module¶
This module generate something from nothing.
-
class
publiforge.lib.processor.generator.Processor(build)[source]¶ Main class for generator processor.
-
message(text)[source]¶ Add a message in
build.result['values'].Parameters: text – (string or pyramid.i18n.TranslationString) Message text.
-
storage_handler(storage_id, storage=None)[source]¶ Update environment for storage
storage_idwith handler and user information and return the current storage handler.Parameters: - storage_id – (string) Storage ID.
- storage – (
Storageinstance, optional).
Returns: (tuple or
None) A tuple such as(storage_handler, (vcs_user_id, vcs_password, user_name)).
-