Skip to main content

Utils

A collection of various utility-functions that can be helpful during development

reflect_comet()​

Writes a formatted list of contents of the comet-module to the logfile and console-output / indesign-dialog.

Returns:nothing

benchmark(...)​

( logging = False )​

This function should be used as decorater above the definition of a function. It records the execution time of the function that it wraps and saves it in a comet-variable. Optionally writes the execution time of the function to the logs.

Parameters:logging (bool)
Whether or not to write the results to the logs.
Returns:Function-Wrapper
Return Type:Any

Example:

from time import sleep
@utils.benchmark(logging=True)
def my_function(duration:float|int=3.14):
sleep(duration)
return None

my_function()
> [benchmark] Function 'my_function' executed in 3.1401s
my_function(6.28)
> [benchmark] Function 'my_function' executed in 6.2801s

get_benchmark(...)​

( names = [] )​

Retrieves the execution times saved by the benchmark-function.

Parameters:names (bool)
A list of function names to filter the results by. If no list list is given, all saved entries are returned.
Returns:Dictionary with of recorded execution-times by function-name.
Return Type:dict

get_benchmark_sum(...)​

( names = [] )​

Retrieves the execution times saved by the benchmark-function. Also adds information on the total amount of function calls and duration of the saved returned entries.

Parameters:names (bool)
A list of function names to filter the results by. If no list list is given, all saved entries are returned.
Returns:Dictionary with of recorded execution-times by function-name.
Return Type:dict

read_project_config(...)​

( config )​

Read a configuration-file (xml) of the comet-project and return its entries.

Parameters:config (ProjectConfig)
An Enum for one of the configuration files in a comet-project.
Returns:The configuration-file's entries.
Return Type:list[dict]

ProjectConfig(Enum)​

Enumerator for all xml-config-files in a comet-project, by filename.

actions
colors
datafiles
documents
domain
findstatements
fontdb
fontnames
framerules
grids
gridtypes
log
pageitemtypes
pageitems
pagetemplates
panelstatements
placeholder
relatedto
settings
xentities
xindex