pynux documentation

code on github

README and LICENSE

for use with Nuxeo Platform 5.8

Rest API Commands

`` nuxeo-rest-api `` just a small part of this API is implimented in pynux.

listing commands

These commands list documents in nuxeo.

By default uid and path with be printed on standard out.

Specifing an --outdir parameter with a directory name will cause a JSON dump of the list to be output, with one .json file per document. TODO: what if a document path contains .json? Should outdir use uids for file names?

nxls

usage: nxls [-h] [--outdir OUTDIR] [--loglevel LOGLEVEL] [--rcfile RCFILE]
            path

nuxeo metadata via REST API

positional arguments:
  path                 nuxeo document path

optional arguments:
  -h, --help           show this help message and exit
  --outdir OUTDIR      directory to hold application/json+nxentity .json files

common options for pynux commands:
  --loglevel LOGLEVEL  CRITICAL ERROR WARNING INFO DEBUG NOTSET, default is
                       ERROR
  --rcfile RCFILE      path to ConfigParser compatible ini file

nxql

usage: nxql [-h] [--outdir OUTDIR] [--loglevel LOGLEVEL] [--rcfile RCFILE]
            nxql

nxql via REST API

positional arguments:
  nxql                 nxql query

optional arguments:
  -h, --help           show this help message and exit
  --outdir OUTDIR      directory to hold application/json+nxentity .json files

common options for pynux commands:
  --loglevel LOGLEVEL  CRITICAL ERROR WARNING INFO DEBUG NOTSET, default is
                       ERROR
  --rcfile RCFILE      path to ConfigParser compatible ini file

nxql_all

SELECT * FROM Documents

Does not support --outdir

usage: nxql_all [-h] [--loglevel LOGLEVEL] [--rcfile RCFILE]

nuxeo metadata via REST API

optional arguments:
  -h, --help           show this help message and exit

common options for pynux commands:
  --loglevel LOGLEVEL  CRITICAL ERROR WARNING INFO DEBUG NOTSET, default is
                       ERROR
  --rcfile RCFILE      path to ConfigParser compatible ini file

update command

nxup1

update one nuxeo document from a .json input file.

if no uid nor path was specified on the command line, then look in the JSON file and prefer "path": to "uid": when because the JSON file may have come from another machine where the uuids are different. If no documentid is found it exits with an error.

Nuxeo JSON output is returned on standard out. Nuxeo returns the JSON of the updated document. (TODO I guess nxup1 could check the returned JSON and make sure it looks like the update was a-okay.)

usage: nxup1 [-h] [--uid UID | --path PATH] [--loglevel LOGLEVEL]
             [--rcfile RCFILE]
             file

nuxeo metadata via REST API, one record

positional arguments:
  file                 application/json+nxentity

optional arguments:
  -h, --help           show this help message and exit
  --uid UID            update specific nuxeo uid
  --path PATH          update specific nuxeo path

common options for pynux commands:
  --loglevel LOGLEVEL  CRITICAL ERROR WARNING INFO DEBUG NOTSET, default is
                       ERROR
  --rcfile RCFILE      path to ConfigParser compatible ini file

Platform (bulk) importer commands

nuxeo-platform-importer

pilog

init and set up logging.

usage: pilog [-h] [--activate] [--loglevel LOGLEVEL] [--rcfile RCFILE]

nuxeo platform importer log/logActivate

optional arguments:
  -h, --help           show this help message and exit
  --activate

common options for pynux commands:
  --loglevel LOGLEVEL  CRITICAL ERROR WARNING INFO DEBUG NOTSET, default is
                       ERROR
  --rcfile RCFILE      path to ConfigParser compatible ini file

pistatus

check if an import is running. Don’t run more than one job at once! Will return HTTP result from nuxeo on standard out which will either be Running or Not Running.

usage: pistatus [-h] [--loglevel LOGLEVEL] [--rcfile RCFILE]

nuxeo platform importer status

optional arguments:
  -h, --help           show this help message and exit

common options for pynux commands:
  --loglevel LOGLEVEL  CRITICAL ERROR WARNING INFO DEBUG NOTSET, default is
                       ERROR
  --rcfile RCFILE      path to ConfigParser compatible ini file

pifolder

Trigger /run of bulk importer. By default, it won’t exit until the async loading is finished, so that it can be used from a batch script.

usage: pifolder [-h] [--loglevel LOGLEVEL] [--rcfile RCFILE] --leaf_type
                LEAF_TYPE --input_path INPUT_PATH --target_path TARGET_PATH
                --folderish_type FOLDERISH_TYPE [--no_wait]
                [--poll_interval SLEEP]

run import of a folder into nuxeo

optional arguments:
  -h, --help            show this help message and exit
  --no_wait             don't poll/wait for the job to finish
  --poll_interval SLEEP
                        seconds to sleep for if waiting

common options for pynux commands:
  --loglevel LOGLEVEL   CRITICAL ERROR WARNING INFO DEBUG NOTSET, default is
                        ERROR
  --rcfile RCFILE       path to ConfigParser compatible ini file

there are four required arguments:
  --leaf_type LEAF_TYPE
                        nuxeo document type for imported leaf nodes
  --input_path INPUT_PATH
                        unix path to files
  --target_path TARGET_PATH
                        target document for import in nuxeo (parent folder
                        where new folder will be created)
  --folderish_type FOLDERISH_TYPE
                        nuxeo document type for imported folder

Library

short example

from pynux import utils
nx = utils.Nuxeo()

nx.nxql('SELECT * from Documents');
nx.all()
nx.children("asset-library")
uid = nx.get_uid("asset-library")
nx.get_metadata(uid=uid)
nx.get_metadata(path="asset-library")

pynux.utils

python function library for working with nuxeo “REST” APIs.

class pynux.utils.Nuxeo(conf={}, rcfile='.pynuxrc', loglevel='ERROR')

utility functions for nuxeo

Object’s data keeps track of URLs and credentials for Nuxeo REST API and Nuxeo Platoform Importer / bulk import API

Parameters:
  • conf – dictionary with "user":, "password":, "api": "fileImporter": and/or "X-NXDocumentProperties": to override defaults
  • rcfileConfigParser
  • loglevel – for standard library logging
_get_iter(url, params)

generator iterator for nuxeo results

Parameters:
  • url – url before query string
  • params (dict of cgi paramaters) –
Returns:

iterator of nuxeo API results

_get_page(url, params, current_page_index)

get a single page of nuxeo API results

Parameters:
  • url – url before query string
  • params (dict of cgi paramaters) –
  • current_page_index (int) – current page (index 0)
Returns:

json from nuxeo

_mkdir(newdir)

works the way a good mkdir should :) - already exists, silently complete - regular file in the way, raise an exception - parent directory(ies) does not exist, make them as well

all()

.nxql(“SELECT * FROM Document”)

Returns:iterator of nuxeo API results
call_file_importer_api(verb, params={})

generic wrapper to make GET calls to this API

children(path)

get child documents of a path

Returns:iterator of nuxeo API results
get_metadata(**documentid)

get metadata for a document

Parameters:documentid – either uid= or path=
Returns:json from nuxeo
get_uid(path)

look up uid from the path

Parameters:path (string) – nuxeo path for a document
Returns:uid
Return type:string
import_log()

show small part of file importer log

import_log_activate()

activate file importer log

import_one_folder(leaf_type, input_path, target_path, folderish_type, wait=True, sleep=20)

trigger an import and wait for it to finish

Parameters:
  • leaf_type – nuxeo document type for imported files
  • input_path – path on local file system
  • target_path – parent path in Nuxeo
  • folderish_type – nuxeo document type of new folder
  • wait – boolean (True to poll)
  • sleep – float (how long to sleep during poll)
Returns:

STDOUT

import_status_wait(wait=True, sleep=20)

check import status and wait for Not Running

nxql(query)

generic nxql query

Returns:iterator of nuxeo API results
update_nuxeo_properties(data, **documentid)

update nuxeo document properties

Parameters:
  • data (dict) – document properties for nuxeo update
  • documentid – either uid= or path=
Returns:

updated json from nuxeo

pynux.utils.get_common_options(argparse_parser)

common options for command line programs that use the library

Parameters:argvarse_parser – an argparse parser
Returns:argparse parser parameter group