Library Reference
The lib.i18n
Module
Localization management.
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
.
- ciowarehouse.lib.utils.mimetype_url(theme, size, file_type)[source]
Return the URL path of the icon of file type
file_type
.
- ciowarehouse.lib.utils.flag_image(theme, flag_id, active)[source]
Return an URL to an image ON or OFF according to
active
.
- 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:
- ciowarehouse.lib.utils.normalize_filename(filename, mode='simple', is_dir=False)[source]
Normalize file name.
- 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:
- 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:
- ciowarehouse.lib.utils.file_check_move(warehouse1, file1, warehouse2, file2)[source]
Check files for a move or copy.
- Parameters:
- Return type:
- 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:
request (pyramid.request.Request) – Current request.
paging (chrysalio.lib.paging.Paging) – Paging containing all the files.
file_ids (list) – List of file IDs.
- Return type:
- ciowarehouse.lib.utils.value2str(value)[source]
Convert a value to a string for XML.
- Parameters:
value – Value to convert.
- Return type:
- ciowarehouse.lib.utils.thumbnail_create(image, sizes, abs_thumb_large, watermark=None)[source]
Create a large and a small thumbnail.
- Parameters:
- Return type:
- ciowarehouse.lib.utils.thumbnail_remove(warehouse_root, directory, filename)[source]
Remove thumbnails of a file and prune empty ancestor directories.
- 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:
- 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.
- ciowarehouse.lib.utils.full_refresh_warehouses(build, warehouse_ids, host=None, login=None, key=None)[source]
Launch a full refresh action for each warehouse.
- 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
orNone
- 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.
- 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:
- 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.
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
orNone
- Returns:
Error message or
None
if it succeeds.
- clone() str | None [source]
Create a copy of an existing repository.
- Return type:
pyramid.i18n.TranslationString
orNone
- 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
orNone
- 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
orNone
- 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
.
- move(file1: tuple[str, str], file2: tuple[str, str], copy_only: bool = False) str | None [source]
Move or copy a file.
- Parameters:
- Return type:
pyramid.i18n.TranslationString
orNone
- Returns:
Error message or
None
if it succeeds.
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:
- remove(directory: str, filename: str) str | None [source]
Remove a file or a directory in path
directory
.
- move(file1: tuple[str, str], file2: tuple[str, str], copy_only: bool = False) str | None [source]
Move or copy a file.
The lib.warehouse
Module
Warehouse class.
- class ciowarehouse.lib.warehouse.Warehouse(registry, dbwarehouse, locations)[source]
Class to manage a warehouse.
- Parameters:
- label(request)[source]
Return a translated label.
- Parameters:
request (pyramid.request.Request) – Current request.
- Return type:
- description(request)[source]
Return a translated description.
- Parameters:
request (pyramid.request.Request) – Current request.
- Return type:
- 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:
request (pyramid.request.Request) – Current request.
list_path (list) – Relative path in a list.
- Return type:
str
orNone
- file_trail(request, abs_path)[source]
Return a relative path in the warehouse and a its HTML representation.
- Parameters:
request (pyramid.request.Request) – Current request.
abs_path (str) – Absolute path to the current directory.
- Return type:
- 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:
request (pyramid.request.Request) – Current request.
file_id (str) – ID of the file to search.
- 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.
- 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:
- Returns:
A tuple such as
(handler, content)
wherehandler
is alib.handler.Handler
orNone
.
- 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:
- job(request, job_id, config=None)[source]
Return a dictionary representing the job.
- Parameters:
request (pyramid.request.Request) – Current request.
job_id (str) – Job ID.
config (configparser.ConfigParser) – (optional) Configuration parser based on application configuration file.
- Return type:
- Returns:
A dictionary with keys
'job_id'
,'i18n_label'
,'i18n_description'
,'icon'
,'threaded'
,'ttl'
,'priority'
,'settings'
,'service_id'
. If a problem succeeds, it returnsNone
.
- 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
orNone
- 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.
- 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.
- 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.
- index_search(request, fieldnames, wquery, limit=None)[source]
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:
- Returns:
A tuple such as
(dirs, files)
wheredirs
andfiles
are lists of dictionaries. Each dictionary has the keysscore
,warehouse_id
and possiblyfile_id
plus the keys reprensenting the fields of the index.
- index_update_all(dbsession, request=None)[source]
Update the search index.
- Parameters:
dbsession (sqlalchemy.orm.session.Session) – SQLAlchemy session.
request (pyramid.request.Request) – (optional) Current request or
None
if called by populate script.
- index_update(dbsession, files, request=None, force=False)[source]
Update the search index.
- Parameters:
dbsession (sqlalchemy.orm.session.Session) – SQLAlchemy session.
files (list) – List of tuples such as
(directory, file_name)
.request (pyramid.request.Request) – (optional) Current request or
None
if called by a script.force (bool) – (default=False) Force indexation.
- 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:
- 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:
- Returns:
A tuple such as
(group_set, tree)
.
- 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
andeditings
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
ordict
) – 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:
- Return type:
- Returns:
A tuple such as
(match, content)
wherematch
isTrue
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.
- 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
orNone
- 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
orNone
- save(request, warehouse, original, values, go_on)[source]
Save the file.
- Parameters:
request (pyramid.request.Request) – Current request.
warehouse (ciowarehouse.lib.warehouse.Warehouse) – Object describing the warehouse containing the file.
original (
str
orlxml.etree._ElementTree
) – Initial content of the file.values (dict) – Modified values.
go_on (bool) –
True
if the modification continues after saving.
- Return type:
str
orNone
- 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:
- 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:
- 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.
- 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:
- 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:
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:
request (pyramid.request.Request) – Current request.
warehouse (.lib.warehouse.Warehouse) – Current warehouse object if exists.
paging (chrysalio.lib.paging.Paging) – Paging containing all the files.
form (chrysalio.lib.form.Form) – Current form.
action (str) – Current action.
- Return type:
- Returns:
Return a possibly new action.
- file_id(request)[source]
Return the current file ID.
- Parameters:
request (pyramid.request.Request) – Current request.
- Return type:
- current(request, pitem)[source]
Return
'current'
if the item is the current one for the file information panel.- Parameters:
request (pyramid.request.Request) – Current request.
pitem (dict) – Paging item.
- Return type:
'current'
orNone
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:
paging (chrysalio.lib.paging.Paging) – Paging containing all the files.
file_ids (list) – List of file IDs.
- clipboard_copy(paging, file_ids, cut=False)[source]
Copy the files to the clipboard.
- Parameters:
paging (chrysalio.lib.paging.Paging) – Paging containing all the files.
file_ids (list) – List of file IDs.
cut (bool) – (default=False)
True
for a cut operation.
- 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.
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.
- 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:
- 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.