Library Reference

The lib.i18n Module

Localization management.

ciowarehouse.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.

ciowarehouse.lib.utils.mimetype_icon(file_type)[source]

Return the ID of the icon of file type file_type.

Parameters:

file_type (str) – File type. For instance plain .

Return type:

str

ciowarehouse.lib.utils.mimetype_url(theme, size, file_type)[source]

Return the URL path of the icon of file type file_type.

Parameters:
  • theme (str) – Current theme, possibly ''.

  • size (str) – Size of the icon: 'normal' or 'small'.

  • file_type (str) – File type. For instance plain .

Return type:

str

ciowarehouse.lib.utils.flag_image(theme, flag_id, active)[source]

Return an URL to an image ON or OFF according to active.

Parameters:
  • theme (str) – Current theme.

  • flag_id (str) – ID of the flag. For instance, 'favorite'.

  • active (bool) – State of the flag.

Return type:

str

ciowarehouse.lib.utils.sort_key(name)[source]

Key for sorting according to a name.

Parameters:

name (str) – Name to convert.

Return type:

str

ciowarehouse.lib.utils.make_file_id(path)[source]

Return a digest representation of the file.

Parameters:

path (str) – The path of the file i.e. its warehouse_id and its relative path inside the warehouse.

Return type:

str

ciowarehouse.lib.utils.apply_regex(request, regex_file, content)[source]

Apply al ist of regular expressions from a file.

Parameters:
  • request (pyramid.request.Request) – Current request.

  • regex_file (str) – Absolute path to the file containing regular expressions.

  • content (str) – Content to process.

Return type:

str

ciowarehouse.lib.utils.normalize_filename(filename, mode='simple', is_dir=False)[source]

Normalize file name.

Parameters:
  • filename (str) – File name to normalize.

  • mode (str) – (default=’simple’) Strategy to normalize file name ('simple' or 'strict').

  • is_dir (bool) – (default=False) True if the file is a directory.

ciowarehouse.lib.utils.files2response(request, filenames, common_path=None, download_name=None)[source]

Prepare files for download and return a Pyramid response.

Parameters:
  • request (pyramid.request.Request) – Current request.

  • filenames (list) – List of absolute paths to files to download.

  • common_path (str) – (optional) Root of all files.

  • download_name (str) – (optional) Visible name during download.

Return type:

pyramid.response.FileResponse

Returns:

Return a FileResponse or raise a pyramid.httpexceptions.HTTPNotFound exception.

ciowarehouse.lib.utils.file2response(request, filename, download_name, content_type=None)[source]

Return a Pyramid FileResponse containing the file filename.

Parameters:
  • request (pyramid.request.Request) – Current request.

  • filename (str) – Absolute path to file to encapsulate.

  • download_name (str) – Visible name during download.

Return type:

pyramid.response.FileResponse

ciowarehouse.lib.utils.file_check_move(warehouse1, file1, warehouse2, file2)[source]

Check files for a move or copy.

Parameters:
  • warehouse1 (.lib.warehouse.Warehouse) – Warehouse of the source.

  • file1 (tuple) – Tuple describing the source file such as (directory1, filename1).

  • warehouse2 (.lib.warehouse.Warehouse) – Warehouse of the target.

  • file2 (tuple) – Tuple describing the target file such as (directory2, filename2).

Return type:

tuple

Returns:

A tuple such as (abs_path1, abs_path2, error).

ciowarehouse.lib.utils.file_ids2fullnames(request, paging, file_ids)[source]

Convert a list of file IDs into a list of absolute paths.

Parameters:
Return type:

list

ciowarehouse.lib.utils.value2str(value)[source]

Convert a value to a string for XML.

Parameters:

value – Value to convert.

Return type:

str

ciowarehouse.lib.utils.thumbnail_create(image, sizes, abs_thumb_large, watermark=None)[source]

Create a large and a small thumbnail.

Parameters:
  • image (PIL.Image) – Image to convert into thumbnails.

  • sizes (tuple) – A tuple of two sizes: the size of the large and the one of the small.

  • abs_thumb_large (str) – Absolute path to the large thumbnail file.

  • watermark (PIL.Image) – (optional) Image to convert into thumbnails.

Return type:

bool

ciowarehouse.lib.utils.thumbnail_remove(warehouse_root, directory, filename)[source]

Remove thumbnails of a file and prune empty ancestor directories.

Parameters:
  • warehouse_root (str) – Absolute path of warehouse root.

  • directory (str) – Relative path to the directory containing the file.

  • filename (str) – Name of the file to remove.

ciowarehouse.lib.utils.thumbnail_move(warehouse1_root, file1, warehouse2_root, file2, copy_only=False)[source]

Move thumbnails of a file and prune empty ancestor directories.

Parameters:
  • warehouse1_root (str) – Absolute path of warehouse 1 root.

  • file1 (tuple) – A tuple such as (directory1, name1).

  • warehouse2_root (str) – Absolute path of warehouse 2 root.

  • file2 (tuple) – A tuple such as (directory2, name2).

  • copy_only (bool) – (default=False) If True, copy instead of moving the file.

ciowarehouse.lib.utils.thumbnail_url(request, pfile, size='normal')[source]

Return the URL of a thumbnail of a file representing by a paging item dictionary.

Parameters:
  • request (pyramid.request.Request) – Current request.

  • pfile (dict) – A paging file item.

  • size (str) – (default=’normal’) Size of the icon: 'normal' or 'small'.

Return type:

str

ciowarehouse.lib.utils.html2thumbnails(html_file, thumb_dir, sizes, timeout=None)[source]

Convert a HTML file into thumbnails.

Parameters:
  • html_file (str) – Absolute path to the HTML file.

  • thumb_dir (str) – Absolute path to the directory containing the thumbnail.

  • sizes (tuple) – A tuple such as ((large_width, large_height), (small_width, small_height)).

  • timeout (float) – (default=None) If set and the process hasn’t finished in that time (in seconds), exits with error.

ciowarehouse.lib.utils.restful_params(build, host=None, login=None, key=None)[source]

Return RESTful parameters: host, login, key.

Parameters:
  • build (cioservice.lib.build.Build) – Current build object.

  • host (str) – (optional) Default RESTful host.

  • login (str) – (optional) Default RESTful login.

  • key (str) – (optional) Default RESTful key.

ciowarehouse.lib.utils.full_refresh_warehouses(build, warehouse_ids, host=None, login=None, key=None)[source]

Launch a full refresh action for each warehouse.

Parameters:
  • build (cioservice.lib.build.Build) – Current build object.

  • warehouse_ids (set) – Set of warehouses to refresh.

  • host (str) – (optional) Default RESTful host.

  • login (str) – (optional) Default RESTful login.

  • key (str) – (optional) Default RESTful key.

ciowarehouse.lib.utils.refresh_warehouse(build, warehouse_id, files, recursive=False, host=None, login=None, key=None)[source]

Launch a full refresh action for some files.

Parameters:
  • build (cioservice.lib.build.Build) – Current build object.

  • warehouse_id (set) – ID of the warehouse.

  • files (list) – List of paths of files relative to the warehouse root.

  • recursive (bool) – (default=False) Refresh recursively.

  • host (str) – (optional) Default RESTful host.

  • login (str) – (optional) Default RESTful login.

  • key (str) – (optional) Default RESTful key.

ciowarehouse.lib.utils.move_inter_warehouses(warehouse1, pfile1, warehouse2, pfile2, copy_only=False)[source]

Move or copy a file between 2 differents workspaces.

Parameters:
  • warehouse1 (.lib.warehouse.Warehouse) – Warehouse of the source.

  • pfile1 (dict) – Dictionary describing the source file.

  • warehouse2 (.lib.warehouse.Warehouse) – Warehouse of the target.

  • pfile2 (dict) – Dictionary describing the target file.

  • copy_only (bool) – (default=False) If True, copy instead of moving the file.

Return type:

pyramid.i18n.TranslationString or None

Returns:

Error message or None if it succeeds.

ciowarehouse.lib.utils.infos_load(infos_file, remove_metafields=False, remove_groups=False)[source]

Load an infos XML file.

Parameters:
  • infos_file (str) – Absolute path to the infos XML file.

  • remove_metafields (bool) – if True metadata fields are removed.

  • remove_groups (bool) – if True file groups are removed.

Return type:

lxml.etree._Element

Returns:

Root element of the infos XML file.

ciowarehouse.lib.utils.infos_get_metadata(root_elt, meta_id)[source]

Return the value of a metadata in its correct type or None.

Parameters:
  • root_elt (lxml.etree.Element) – Root of the XML document.

  • meta_id (str) – ID of the metadata to retrieve.

Returns:

Value of metadata or None.

ciowarehouse.lib.utils.infos_set_metadata(root_elt, metafields)[source]

Update metadata fields.

Parameters:
  • root_elt (lxml.etree.Element) – Root of the XML document.

  • metafields (list) – List of metadata fields. Each item is a tuple such as (id, type, value).

ciowarehouse.lib.utils.infos_save(root_elt, infos_file, request=None)[source]

Save an infos XML file.

Parameters:
  • root_elt (lxml.etree.Element) – Root of the XML document.

  • infos_file (str) – Absolute path to the information file.

  • request (pyramid.request.Request) – (optional) Current request.

Return type:

bool

ciowarehouse.lib.utils.build_callback(registry, build_env, result, request=None)[source]

Function called after the build is completed.

Parameters:
  • registry – Application registry.

  • build_env (dict) – Build environment.

  • result (dict) – Result of the processing. See: cioservice.lib.build.Build.

  • request (pyramid.request.Request) – (optional) Current request.

ciowarehouse.lib.utils.cache_user_renderings(namespace_prefix, region=None)[source]

A decorator to retrieve in the user cache the dictionary renderings.

Parameters:
  • namespace_prefix (str) – Prefix of the cache namespace.

  • region (str) – (optional) Name of region.

ciowarehouse.lib.utils.cache_user_seeds(namespace_prefix, region=None)[source]

A decorator to retrieve in the user cache the dictionary of seeds.

Parameters:
  • namespace_prefix (str) – Prefix of the cache namespace.

  • region (str) – (optional) Name of region.

The lib.vcs Module

Class for warehouses with Git as VCS.

class ciowarehouse.lib.vcs_git.VcsGit(root: str, url: str | None = None, user_id: str | None = None, password: str | None = None, lock_ttl: int = 3600)[source]

Class to manage warehouses with Git as VCS.

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

  • url (str) – (optional) URL of the remote repository.

  • user_id (str) – (optional) User ID for clone/pull access.

  • password (str) – (optional) Clear password for clone/pull access.

  • lock_ttl (int) – (default=3600) Clear password for clone/pull access.

init()[source]

Initialize a local Git repository.

Return type:

pyramid.i18n.TranslationString or None

Returns:

Error message or None if it succeeds.

is_dirty() bool[source]

Return True if the repository data has been modified.

Return type:

bool

clone() str | None[source]

Create a copy of an existing repository.

Return type:

pyramid.i18n.TranslationString or None

Returns:

Error message or None if it succeeds.

pull() str | None[source]

Pull from a remote repository or do nothing.

Return type:

pyramid.i18n.TranslationString or None

Returns:

Error message or None if it succeeds.

add(path: str | None = None) str | None[source]

Add new files in path path.

Parameters:

path (str) – (optional) Relative or absolute path to add.

Return type:

pyramid.i18n.TranslationString or None

Returns:

Error message or None if it succeeds.

remove(directory: str, filename: str) str | None[source]

Remove a file or a directory in path directory.

Parameters:
  • directory (str) – Relative or absolute path to the directory containing the file.

  • filename (str) – Name of the file to remove.

Return type:

pyramid.i18n.TranslationString or None

Returns:

Error message or None if it succeeds.

move(file1: tuple[str, str], file2: tuple[str, str], copy_only: bool = False) str | None[source]

Move or copy a file.

Parameters:
  • file1 (tuple) – A tuple such as (old_directory, old_name).

  • file2 (tuple) – A tuple such as (new_directory, new_name).

  • copy_only (bool) – (default=False) If True, copy instead of moving the file.

Return type:

pyramid.i18n.TranslationString or None

Returns:

Error message or None if it succeeds.

copy(file1, file2)[source]

Copy a file.

Parameters:
  • file1 (tuple) – A tuple such as (old_directory, old_name).

  • file2 (tuple) – A tuple such as (new_directory, new_name).

Return type:

pyramid.i18n.TranslationString or None

Returns:

Error message or None if it succeeds.

commit(message, name, email='')[source]

Commit changes.

Parameters:
  • message (str) – Message for mommit.

  • name (str) – Name of the author.

  • email (str) – (optional) Emial of the author.

Return type:

pyramid.i18n.TranslationString or None

Returns:

Error message or None if it succeeds.

log(directory, filename, limit=20)[source]

Show revision history.

Parameters:
  • directory (str) – Relative or absolute path to the directory containing the file.

  • filename (str) – Name of the file to log.

  • limit (init) – (default=20) Maximum number of commits.

Return type:

list

Returns:

A list of tuples such as (commit_id, datetime, commiter_name, message).

Class for warehouses without Version Control System.

class ciowarehouse.lib.vcs_none.VcsNone(root: str, source: str | None = None)[source]

Class to manage warehouses without VCS.

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

  • source (str) – (optional) Absolute path to the source directory to initialize the warehouse.

init()[source]

Possibly create the root directory.

Return type:

None

classmethod is_dirty() bool[source]

Return False.

Return type:

bool

clone()[source]

Call meth:init.

Return type:

None

pull()[source]

Do a clone if source exists and root directory is empty.

Return type:

None

add(path=None)[source]

Do nothing.

Return type:

None

remove(directory: str, filename: str) str | None[source]

Remove a file or a directory in path directory.

Parameters:
  • directory (str) – Relative or absolute path to the directory containing the file.

  • filename (str) – Name of the file to remove.

Return type:

pyramid.i18n.TranslationString or None

Returns:

Error message or None if it succeeds.

move(file1: tuple[str, str], file2: tuple[str, str], copy_only: bool = False) str | None[source]

Move or copy a file.

Parameters:
  • file1 (tuple) – A tuple such as (directory1, name1).

  • file2 (tuple) – A tuple such as (directory2, name2).

  • copy_only (bool) – (default=False) If True, copy instead of moving the file.

Return type:

pyramid.i18n.TranslationString or None

Returns:

Error message or None if it succeeds.

copy(file1, file2)[source]

Copy a file.

Parameters:
  • file1 (tuple) – A tuple such as (old_directory, old_name).

  • file2 (tuple) – A tuple such as (new_directory, new_name).

Return type:

pyramid.i18n.TranslationString or None

Returns:

Error message or None if it succeeds.

commit(message, name, email=None)[source]

Do nothing.

Return type:

None

log(directory, filename, limit=20)[source]

Do nothing.

Return type:

None

The lib.warehouse Module

Warehouse class.

class ciowarehouse.lib.warehouse.Warehouse(registry, dbwarehouse, locations)[source]

Class to manage a warehouse.

Parameters:
  • registry (dict) – Application registry.

  • dbwarehouse (.models.dbwarehouse.DBWarehouse) – SQLAlchemy object representing the warehouse

  • locations (dict) – Dictionary of locations.

label(request)[source]

Return a translated label.

Parameters:

request (pyramid.request.Request) – Current request.

Return type:

str

description(request)[source]

Return a translated description.

Parameters:

request (pyramid.request.Request) – Current request.

Return type:

str

directory_path(request, list_path)[source]

Return an absolute path of the directory pointed by the path contained in the list list_path. Verify if the file is in the warehouse.

Parameters:
Return type:

str or None

file_trail(request, abs_path)[source]

Return a relative path in the warehouse and a its HTML representation.

Parameters:
Return type:

tuple

Returns:

A tuple such as (html_path, rel_path).

file_get(request, file_id)[source]

Return the dictionary of a file corresponding to the file ID.

Parameters:
Return type:

class:dict or None

file_normalize(filename, is_dir=False)[source]

Return a normalized file name or None if the file is in the excluded file list.

Parameters:
  • fielname (str) – Name to normalize.

  • is_dir (bool) – (default=False) True if the file is a directory.

Return type:

str

get_handler(abs_path)[source]

Retrieve the best file handler for file abs_path.

Parameters:

abs_path (str) – Absolute path to the file.

Return type:

tuple

Returns:

A tuple such as (handler, content) where handler is a lib.handler.Handler or None.

seeds(request, *args, **kwargs)

Use of user cache.

jobs(request)[source]

Return a dictionary of available jobs for this warehouse.

Parameters:

request (pyramid.request.Request) – Current request.

Return type:

dict

job(request, job_id, config=None)[source]

Return a dictionary representing the job.

Parameters:
Return type:

dict

Returns:

A dictionary with keys 'job_id', 'i18n_label', 'i18n_description', 'icon', 'threaded', 'ttl', 'priority', 'settings', 'service_id'. If a problem succeeds, it returns None.

full_refresh(request, reindex=False, recreate_thumbnails=False, in_thread=False, force=True)[source]

Pull, index, create thumbnails and commit changes on the whole warehouse.

Parameters:
  • request (pyramid.request.Request) – Current request.

  • reindex (bool) – (default=False) Remove old index.

  • recreate_thumbnails (bool) – (default=False) Remove old thumbnails.

  • in_thread (bool) – (default=False) Launch the refresh in a thread.

  • force (bool) – (default=True) If True, force refreshing even if the deadline is not reached.

Return type:

pyramid.i18n.TranslationString or None

Returns:

Error message or None.

refresh(request, files, recursive=False, in_thread=False, dbsession=None, keep_cache=False)[source]

Index and create thumbnails for a list of files.

Parameters:
  • request (pyramid.request.Request) – Current request or None if called by a script.

  • files (list) – List of paths of files relative to the warehouse root.

  • recursive (bool) – (default=False) Refresh recursively.

  • in_thread (bool) – (default=False) Launch the refresh in a thread.

  • dbsession (sqlalchemy.orm.session.Session) – (optional) SQLAlchemy session.

  • keep_cache (bool) – (default=False) if True, do not clear the cache.

refreshed()[source]

Record the time of last refresh.

unrefreshed()[source]

Remove the record of last refresh.

to_refresh(inputs, paths)[source]

Compute an optimized list of relative paths to refresh.

Parameters:
  • inputs (list) – List of absolute paths to the input files.

  • paths (str) – List of relative paths to the output files.

Return type:

set

lock(abs_file=None, relock=False)[source]

Lock a file or the whole warehouse.

Parameters:
  • abs_file (str) – (optional) Absolute path to the source file.

  • relock (bool) – If True update the date/time of the lock.

Return type:

bool

unlock(abs_file=None)[source]

Unlock a file or the whole warehouse.

Parameters:

abs_file (str) – (optional) Relative path to a file or a directory.

unlock_all()[source]

Remove lock directory.

thumbnails_erase()[source]

Remove the thumbnail directory if exists.

thumbnails_update_all(request=None, registry=None)[source]

Update or create small and large thumbnails for the entire warehouse.

Parameters:
  • request (pyramid.request.Request) – (optional) Current request or None if called by populate script.

  • registry – (optional) class:pyramid.registry.Registry or class:chrysalio.scripts.ScriptRegistry if called by populate script.

thumbnails_update(files, request=None, registry=None)[source]

Update or create small and large thumbnails for each file if it is possible.

Parameters:
  • files (list) – List of tuples such as (directory, file_name).

  • request (pyramid.request.Request) – (optional) Current request or None if called by a script.

  • registry – (optional) class:pyramid.registry.Registry or class:chrysalio.scripts.ScriptRegistry if called by populate script.

Search in the warehouse according to a Whoosh query.

Parameters:
  • request (pyramid.request.Request) – Current request.

  • fieldnames (list) – List of fields to search.

  • wquery (str) – A query in the Whoosh default query language.

  • limit (int) – (optional) Maximum number of results.

Return type:

tuple

Returns:

A tuple such as (dirs, files) where dirs and files are lists of dictionaries. Each dictionary has the keys score, warehouse_id and possibly file_id plus the keys reprensenting the fields of the index.

index_erase()[source]

Remove the index directory if exists.

index_update_all(dbsession, request=None)[source]

Update the search index.

Parameters:
index_update(dbsession, files, request=None, force=False)[source]

Update the search index.

Parameters:
index_is_obsolete(fields, abs_file)[source]

Check if the Whoosh index is obsolete.

Parameters:
  • fields – Fields of index record.

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

Return type:

bool

infos_read(path, meta_ids, for_index, request=None)[source]

Return a dictionary with authorized groups and metadata found in the infos XML file.

Parameters:
  • path (str) – Relative path of the file.

  • meta_ids (set) – Set of IDS of metadata fields to retrieve.

  • for_index (bool) – If True, convert boolean fields.

  • request (pyramid.request.Request) – (optional) Current request or None if called by a script.

Return type:

dict

infos_only_groups(path, request=None)[source]

Return a set of authorized groups or an empty set if all groups are authorized.

Parameters:
  • path (str) – Relative path of the file.

  • request (pyramid.request.Request) – (optional) Current request or None if called by a script.

Return type:

tuple

Returns:

A tuple such as (group_set, tree).

directory_file_list(directory)[source]

Return the list of files of a directory of the warehouse.

Parameters:

directory (str) – Relative path of the directory to browse.

Return type:

list

classmethod error(message, request=None)[source]

Log an error message.

Parameters:
  • message (str) – Error message.

  • request (pyramid.request.Request) – (optional) Current request or None if called by populate script.

classmethod warning(message, request=None)[source]

Log an warning message.

Parameters:
  • message (str) – Warning message.

  • request (pyramid.request.Request) – (optional) Current request or None if called by populate script.

The lib.handler Module

A file handler is a class to make thumbnail and to provide index values for a particular type of file.

class ciowarehouse.lib.handler.Handler[source]

Base class for file handlers.

This object provides thumbnail, index values and rendering for a particular type of file.

viewings and editings attributes are lists of dictionaries with the following keys:

  • 'label': (required) label of the rendering

  • 'template': (required) Chameleon template to use

  • 'css': list of paths to CSS file

  • 'js': list of path to Javascript file

  • 'only_groups': set of groups of authorized users for editing

classmethod register(environment, handler_class, **kwargs)[source]

Method to register the handler.

Parameters:
  • environment (pyramid.config.Configurator or dict) – Object used to do configuration declaration within the application or a ScriptRegistry to simulate the application registry.

  • handler_class – Handler class.

  • kwargs (dict) – Keyworded arguments

Return type:

.lib.handler.Handler

initialize(dbsession, config)[source]

Initialize the handler reading its possibly parameters in database.

Parameters:
  • dbsession – SQLAlchemy session.

  • config (dict) – Dictionary with keys 'root' and 'develop' where 'root' is the absolute path to the root directory for handler with imports.

install(force=False)[source]

Install a handler in an alternative home directory with its imports.

Parameters:

force (bool) – If True, force installation.

match(extension, filename, content=None, extensions_subset=None)[source]

Check whether this file handler matches with the file filename.

Parameters:
  • extension (str) – File extension.

  • filename (str) – Absolute path to the file.

  • content (str) – (optional) Content of the file.

  • extensions_subset (tuple) – (optional) Subset of extensions (for instance, only Web-compatible extensions).

Return type:

tuple

Returns:

A tuple such as (match, content) where match is True if the handler matches.

infos_complete_fields(warehouse, path, abs_path, whoosh_fields, request=None)[source]

Complete the whoosh_fields dictionary with information found in the infos file.

Parameters:
  • warehouse (.lib.warehouse.Warehouse) – Object describing the warehouse containing the file.

  • path (str) – Relative path of the file.

  • abs_path (str) – Absolute path of the file.

  • whoosh_fields (dict) – Dictionary of Whoosh fields to complete.

  • request (pyramid.request.Request) – (optional) Current request or None if called by a script.

classmethod thumbnails_obsolete(abs_file, thumb_dir)[source]

Check if thumbnails are obsolete.

Parameters:
  • abs_file (str) – Absolute path to the source file.

  • thumb_dir (str) – Absolute path to the directory containing the thumbnail.

Return type:

bool

thumbnails(warehouse, abs_file, thumb_dir, request=None, registry=None)[source]

Create the small and large thumbnails representing the file.

Parameters:
  • warehouse (.lib.warehouse.Warehouse) – Object describing the warehouse containing the file.

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

  • thumb_dir (str) – Absolute path to the directory containing the thumbnail.

  • request (pyramid.request.Request) – (optional) Current request or None if called by a script.

  • registry – (optional) class:pyramid.registry.Registry or class:chrysalio.scripts.ScriptRegistry if called by populate script.

view(request, warehouse, content=None, ts_factory=None)[source]

Return a string containing HTML to display the file.

Parameters:
  • request (pyramid.request.Request) – Current request.

  • warehouse (.lib.warehouse.Warehouse) – Object describing the warehouse containing the file.

  • content – (optional) Content of the file.

  • ts_factory – (optional) Translation String Factory fucntion.

Return type:

str or None

can_edit()[source]

Return True if it can produce an editor.

Return type:

bool

edit(request, warehouse, content=None, ts_factory=None)[source]

Return a string containing HTML to edit the file.

Parameters:
  • request (pyramid.request.Request) – Current request.

  • warehouse (.lib.warehouse.Warehouse) – Object describing the warehouse containing the file.

  • content – (optional) Content of the file.

  • ts_factory – (optional) Translation String Factory fucntion.

Return type:

str or None

save(request, warehouse, original, values, go_on)[source]

Save the file.

Parameters:
Return type:

str or None

Returns:

An error message or None.

edit_finalization(request, warehouse, path, message=None)[source]

Commit changes, unlock files and refresh warehouse.

Parameters:
  • request (pyramid.request.Request) – Current request.

  • warehouse (.lib.warehouse.Warehouse) – Object describing the warehouse containing the file.

  • path (str) – Relative path to the file.

  • message (str) – (optional) Commit meesage.

Return type:

bool

classmethod file_lock(request, warehouse, path=None)[source]

Lock a file for the purpose of editing it.

Parameters:
  • request (pyramid.request.Request) – Current request.

  • warehouse (.lib.warehouse.Warehouse) – Object describing the warehouse containing the file.

  • path (str) – (optional) Relative path of the file inside the warehouse.

Return type:

bool

classmethod file_unlock(request, warehouse, path=None)[source]

Unlock a file.

Parameters:
  • request (pyramid.request.Request) – Current request.

  • warehouse (.lib.warehouse.Warehouse) – Object describing the warehouse containing the file.

  • path (str) – (optional) Relative path of the file inside the warehouse.

abspath_from_home(path)[source]

Return an absolute path.

Parameters:

path (str) – Absolute path or relative path to the home directory of the handler.

Return type:

str

classmethod themed_urls(request, rendering, name)[source]

Return a list of URLs possibly completed with theme prefix.

Parameters:
  • request (pyramid.request.Request) – Current request.

  • rendering (dict) – Dictionary defining the rendering.

  • name (str) – Name of the bunch of URLs (‘css’, ‘js’)

Return type:

list

seed(seed_id)[source]

Return a tuple like (icon_url, label, absfile).

Parameters:

seed_id (str) – ID of the seed

Return type:

dict or None

current_rendering(request, warehouse, rendering)[source]

Find the current rendering.

Parameters:
  • request (pyramid.request.Request) – Current request.

  • warehouse (.lib.warehouse.Warehouse) – Object describing the warehouse containing the file.

  • rendering (str) – (‘viewing’ or ‘editing’) Type of rendering.

Return type:

dict

The lib.fileinfo Module

File information panel class.

class ciowarehouse.lib.fileinfo.FileInfo(area: tuple[str, ...] | None = None)[source]

Class to manage file information and file information panel.

See: lib.panel.Panel

prepare_rendering(request, warehouse, pfile, reset=False)[source]

Fill the file information panel with informations about pfile file.

Parameters:
  • request (pyramid.request.Request) – Current request.

  • warehouse (.lib.warehouse.Warehouse) – Current warehouse object if exists.

  • pfile (dict) – Item paging for the current file.

  • reset (bool) – (default=False) If True, reset values.

self.values(request) is a dictionary containing informations on the file:

  • Whoosh index fields:

    • 'warehouse_id'

    • 'directory'

    • 'file_name'

    • 'file_id'

    • 'file_type'

    • 'file_size'

    • 'file_date'

    • 'only_groups'

    • 'shared'

    • 'thumbnail'

  • 'file_age' (localized)

  • 'file_size_label' (localized)

  • 'file_rights'

  • 'file_rights_label' (localized)

  • 'warehouse_name' (localized)

  • 'meta_rights'

  • 'meta_rights_label' (localized)

  • 'metafields'

  • 'metadata'

  • 'sharing_links'

action(request, warehouse, paging, form, action)[source]

Execute actions of the file information panel.

Parameters:
Return type:

str

Returns:

Return a possibly new action.

file_id(request)[source]

Return the current file ID.

Parameters:

request (pyramid.request.Request) – Current request.

Return type:

str

current(request, pitem)[source]

Return 'current' if the item is the current one for the file information panel.

Parameters:
Return type:

'current' or None

The lib.wfile Module

Warehouse file class.

class ciowarehouse.lib.wfile.WFile(request)[source]

Class to operate on files in a warehouse or in a result of search.

Parameters:

request (pyramid.request.Request) – Current request.

detect_thumbnails(file_list)[source]

Complete each element of the file list with thumbnail information.

Parameters:

file_list (list) – List of files to complete.

remove(paging, file_ids)[source]

Remove files.

Parameters:
clipboard_copy(paging, file_ids, cut=False)[source]

Copy the files to the clipboard.

Parameters:
clipboard_paste(warehouse, directory)[source]

Paste the files from the clipboard to the directroy.

Parameters:
  • warehouse (.lib.warehouse.Warehouse) – Current warehouse object.

  • directory (str) – Current directory.

make_directory(warehouse, directory)[source]

Make a directory.

Parameters:
  • warehouse (.lib.warehouse.Warehouse) – Current warehouse object.

  • directory (str) – Current directory.

new_file(warehouse, directory, seed_id)[source]

Create a new file.

Parameters:
  • warehouse (.lib.warehouse.Warehouse) – Current warehouse object.

  • directory (str) – Current directory.

  • seed_id (str) – ID of a seed to create the file.

upload_all(warehouse, directory)[source]

Import several files in the current directory.

Parameters:
  • warehouse (.lib.warehouse.Warehouse) – Current warehouse object.

  • directory (str) – Current directory.

The lib.wjob Module

Warehouse job class.

class ciowarehouse.lib.wjob.WJob(request)[source]

Class to manage jobs manually called in a warehouse.

Parameters:

request (pyramid.request.Request) – Current request.

available(warehouse, caller='browse_view')[source]

Return a list of available jobs for the current warehouse.

Parameters:
  • warehouse (.lib.warehouse.Warehouse) – Current warehouse object.

  • caller (str) – (default=’browse_view’) Name of the entity which calls the warehouse.

Return type:

dict

Returns:

A dictionary of tuples such as (icon, translated_label, service, context).

prepare(warehouse, paging, form, action)[source]

Prepare a job and a build.

Parameters:
  • warehouse (.lib.warehouse.Warehouse) – Current warehouse object.

  • paging (chrysalio.lib.paging.Paging) – Paging containing all the files.

  • form – Current form.

  • action (str) – Current action.

Return type:

tuple

Returns:

A tuple such as (action, build_id).

run(build_id)[source]

Execute a job on a build.

Parameters:

build_id (str) – ID of a registered build.

get(warehouse, job_id, caller='browse_view')[source]

Retrieve a warehouse job checking if it is authorized in this context.

Parameters:
  • warehouse (.lib.warehouse.Warehouse) – Current warehouse object if exists.

  • job_id (str) – Job ID.

  • caller (str) – (default=’browse_view’) Name of the entity which calls the warehouse.

Return type:

dict

See: lib.warehouse.Warehouse.job()