Helpers¶
Check the server access
Whenever you want to check if the Nuxeo Platform server is reachable,
you can run this command. It will return a boolean
representing the
availability of the server.
is_reachable = nuxeo.client.is_reachable()
Get the Nuxeo Drive configuration
You can fetch the Drive configuration from the server:
config = nuxeo.client.request('GET', 'drive/configuration', default={})
If it has been filled, config
will have the following structure:
{
'log_level_file': 'DEBUG',
'ignored_suffixes': ['.bak', '.crdownload', '.lock', '.nxpart', '.part', '.partial', '.swp', '.tmp', '~', '.dwl', '.dwl2'],
'ignored_files': ['^atmp\\d+$'],
'update_check_delay': 3600,
'delay': 30,
'ui': 'web',
'beta_channel': False,
'timeout': 30,
'ignored_prefixes': ['.', 'icon\r', 'thumbs.db', 'desktop.ini', '~$'],
'handshake_timeout': 60
}
Get available operations
You can search for available operations on the explorer (click on Search Operations on the version corresponding to your Nuxeo Platform). You can also run the following bit of code to see the list:
import json
ops = nuxeo.operations.operations.keys()
ops.sort()
json.dumps(ops)
You’ll get an output like this:
[
"Actions.GET",
"AddEntryToMultivaluedProperty",
"AttachFiles",
"Audit.Log",
"Audit.LogEvent",
...
]
And if you pick one you can see its definition:
json.dumps(nuxeo.operations.operations['Log'])
With an output like this:
{
"category": "Notification",
"description": "Logging with log4j",
"url": "Log",
"label": "Log",
"params": [
{
"widget": "Option",
"name": "level",
"required": true,
"values": ["info", "debug", "warn", "error"],
"type": "string",
"order": 0,
"description": ""
},
{
"widget": null,
"name": "message",
"required": true,
"values": [],
"type": "string",
"order": 0,
"description": ""
},
{
"widget": null,
"name": "category",
"required": false,
"values": [],
"type": "string",
"order": 0,
"description": ""
}
],
"signature": [
"void",
"void"
],
"requires": null,
"id": "Log",
"aliases": ["LogOperation"]
}
Check operation parameters
When you execute an operation, the name of the operation and
the parameters you chose will be checked by the nuxeo.operations.check_params()
method. If you want to check the parameters of your operation by
yourself before running it, you can use the following:
try:
nuxeo.operations.check_params('Log', {'level': 'info'
'message': 'I am logging something'})
# The parameters are valid
except ValueError as e:
print(e) # Indicates what is wrong