Code

The cmislib.model Module

The cmislib.model Module contains all the CMIS domain objects. When working with the repository, the first thing you need to do is grab an instance of cmislib.model.CmisClient, passing it the repository endpoint URL, username, and password.

>>> cmisClient = CmisClient('http://localhost:8080/alfresco/s/cmis', 'admin', 'admin')

From there you can get the default repository, or a specific repository if you know the repository ID.

>>> repo = cmisClient.getDefaultRepository()

Once you have that, you’re off to the races. Use the cmislib.model.Repository class to create new cmislib.model.Folder and cmislib.model.Document objects, perform searches, etc.

Module containing the domain objects used to work with a CMIS provider.

class cmislib.model.CmisClient(repositoryUrl, username, password)

Handles all communication with the CMIS provider.

delete(url)
Does a delete against the CMIS service
get(url)
Does a get against the CMIS service
getDefaultRepository()

There does not appear to be anything in the spec that identifies a repository as being the default, so we’ll define it to be the first one in the list.

>>> repo = client.getDefaultRepository()
>>> repo.getRepositoryId()
u'83beb297-a6fa-4ac5-844b-98c871c0eea9'
getRepositories()

Returns a dict of high-level info about the repositories available at this service. The dict contains entries for ‘repositoryId’ and ‘repositoryName’.

See CMIS specification document 2.2.2.1 getRepositories

>>> client.getRepositories()
[{'repositoryName': u'Main Repository', 'repositoryId': u'83beb297-a6fa-4ac5-844b-98c871c0eea9'}]
getRepository(repositoryId)

Returns the repository identified by the specified repositoryId.

This has not been implemented yet.

post(url, payload, contentType)
Does a post against the CMIS service
put(url, payload, contentType)
Does a put against the CMIS service
exception cmislib.model.CmisException
Common base class for all exceptions.
class cmislib.model.CmisObject(cmisClient, repository, objectId=None, xmlDoc=None)

Common ancestor class for other CMIS domain objects such as Document and Folder.

applyACL(addACEs=None, removeACEs=None, ACLPropagation=None)
See CMIS specification document 2.2.10.2 applyACL
applyPolicy(policyId)
See CMIS specification document 2.2.9.1 applyPolicy
delete()

Deletes this CmisObject from the repository.

See CMIS specification document 2.2.4.14 delete

The optional allVersions argument is not yet supported.

getACL(onlyBasicPermissions=None)
See CMIS specification document 2.2.10.1 getACL
getAllowableActions()

This has not yet been implemented.

See CMIS specification document 2.2.4.6 getAllowableActions

getAppliedPolicies()
See CMIS specification document 2.2.9.3 getAppliedPolicies
getObjectId()
Returns the object ID for this object.
getObjectParents()

This has not yet been implemented.

See CMIS specification document 2.2.3.5 getObjectParents

The following optional arguments are not supported:
  • filter
  • includeRelationships
  • renditionFilter
  • includeAllowableActions
  • includeRelativePathSegment
getProperties()

Returns a dict of the object’s properties. If CMIS returns an empty element for a property, the property will be in the dict wiht a value of None.

See CMIS specification document 2.2.4.8 getProperties

The optional filter argument is not yet implemented.

getTitle()
temporary
move(targetFolderId, sourceFolderId)

This is not yet implemented.

See CMIS specification document 2.2.4.13 move

reload()
An internal method that will fetch the latest representation of this object from the CMIS service.
removePolicy(policyId)
See CMIS specification document 2.2.9.2 removePolicy
updateProperties(properties)

Updates the properties of an object with the properties provided. Only provide the set of properties that need to be updated.

See CMIS specification document 2.2.4.12 updateProperties

The optional changeToken is not yet supported.

exception cmislib.model.ConstraintException
ConstraintException
exception cmislib.model.ContentAlreadyExistsException
ContentAlreadyExistsException
class cmislib.model.Document(cmisClient, repository, objectId=None, xmlDoc=None)

An object typically associated with file content.

cancelCheckout()
See CMIS specification document 2.2.7.2 cancelCheckOut
checkin(checkinComment=None)

Checks in this Document which must be a private working copy (PWC).

See CMIS specification document 2.2.7.3 checkIn

The following optional arguments are not currently supported:
  • major
  • properties
  • contentStream
  • policies
  • addACEs
  • removeACEs
checkout()

Performs a checkout on the Document and returns the Private Working Copy (PWC), which is also an instance of Document

See CMIS specification document 2.2.7.1 checkout

deleteContentStream(changeToken=None)
See CMIS specification document 2.2.4.17 deleteContentStream
getAllVersions()

This is not yet implemented.

See CMIS specification document 2.2.7.5 getAllVersions

The optional filter and includeAllowableActions arguments are not yet supported.

getContentStream()

Returns the CMIS service response from invoking the ‘enclosure’ link.

See CMIS specification document 2.2.4.10 getContentStream

The optional streamId argument is not yet supported.

getLatestVersion()

This is not yet implemented.

See CMIS specification document 2.2.7.4 getObjectOfLatestVersion

The following optional arguments are not yet supported:
  • major
  • filter
  • includeRelationships
  • includePolicyIds
  • renditionFilter
  • includeACL
  • includeAllowableActions
getPropertiesOfLatestVersion()

This is not yet implemented.

See CMIS specification document 2.2.7.4 getPropertiesOfLatestVersion

The optional major and filter arguments are not yet supported.

getRelationships()

This is not yet implemented.

See CMIS specification document 2.2.8.1 getObjectRelationships

The following optional arguments are not yet supported:
  • includeSubRelationshipTypes
  • relationshipDirection
  • typeId
  • maxItems
  • skipCount
  • filter
  • includeAllowableActions
getRenditions(renditionFilter=None, maxItems=None, skipCount=None)
See CMIS specification document 2.2.4.11 getRenditions
setContentStream(contentStream, overwriteFlag=None, changeToken=None)
See CMIS specification document 2.2.4.16 setContentStream
exception cmislib.model.FilterNotValidException
FilterNotValidException
class cmislib.model.Folder(cmisClient, repository, objectId=None, xmlDoc=None)

A container object that can hold other CmisObject objects

addObject(cmisObject)

This is not yet implemented.

See CMIS specification document 2.2.5.1 addObjectToFolder

The optional allVersions argument is not yet supported.

createDocument(properties, contentFile=None)

Creates a new Document object in the repository using the properties provided.

Right now this is basically the same as createFolder, but this deals with contentStreams. The common logic should probably be moved to CmisObject.createObject.

The following optional arguments are not yet supported:
  • versioningState
  • policies
  • addACEs
  • removeACEs
createFolder(properties)

Creates a new Folder using the properties provided. Right now I expect a property called ‘cmis:name’ but I don’t complain if it isn’t there (although the CMIS provider will)

See CMIS specification document 2.2.4.3 createFolder

The following optional arguments are not yet supported:
  • policies
  • addACEs
  • removeACEs
deleteTree()

This is not yet implemented.

See CMIS specification document 2.2.4.15 deleteTree

The optional allVersions argument is not yet supported.

getChildren()

Returns a list of CmisObjects for each child of the Folder.

See CMIS specification document 2.2.3.1 getChildren

The following optional arguments are not yet supported:
  • maxItems
  • skipCount
  • orderBy
  • filter
  • includeRelationships
  • renditionFilter
  • includeAllowableActions
  • includePathSegment
getDescendants()

Gets the descendants of this folder.

See CMIS specification document 2.2.3.2 getDescendants

The following optional arguments are currently unsupported:
  • depth
  • filter
  • includeRelationships
  • renditionFilter
  • includeAllowableActions
  • includePathSegment
Returns the ‘down’ link of type CMIS_TREE_TYPE
getParent()

This is not yet implemented.

See CMIS specification document 2.2.3.4 getFolderParent

The optional filter argument is not yet supported.

getTree()

This is not yet implemented.

See CMIS specification document 2.2.3.3 getFolderTree

The following optional arguments are currently unsupported:
  • depth
  • filter
  • includeRelationships
  • renditionFilter
  • includeAllowableActions
  • includePathSegment
removeObject(cmisObject)

This is not yet implemented.

See CMIS specification document 2.2.5.2 removeObjectFromFolder

exception cmislib.model.InvalidArgumentException
InvalidArgumentException
exception cmislib.model.NameConstraintViolationException
NameConstraintViolationException
exception cmislib.model.NotSupportedException
NotSupportedException
exception cmislib.model.ObjectNotFoundException
ObjectNotFoundException
class cmislib.model.ObjectType(cmisClient, repository, typeId=None, xmlDoc=None)

Represents the CMIS object type such as ‘cmis:document’ or ‘cmis:folder’. Contains metadata about the type.

Gets the HREF for the link element with the specified rel and linkType.
getTypeId()
Returns the type ID for this object.
reload()
This method will reload the object’s data from the CMIS service.
exception cmislib.model.PermissionDeniedException
PermissionDeniedException
class cmislib.model.Policy(repository, objectId)
An arbirary object that can ‘applied’ to objects that the repository identifies as being ‘controllable’.
class cmislib.model.Relationship(repository, objectId)
Defines a relationship object between two CmisObjects objects
class cmislib.model.Repository(cmisClient, xmlDoc=None)

Represents a CMIS repository. Will lazily populate itself by calling the repository CMIS service URL.

You must pass in an instance of a CmisClient when creating an instance of this class.

See CMIS specification document 2.1.1 Repository

createDocument(properties, parentFolder=None, contentFile=None)

Creates a new Document object. If the repository supports unfiled objects, you do not have to pass in a parent Folder otherwise it is required.

To create a document with an associated contentFile, pass in a contentFile object.

See CMIS specification document 2.2.4.1 createDocument

The following optional arguments are not currently unsupported:
  • versioningState
  • policies
  • addACEs
  • removeACEs
createDocumentFromSource(sourceId, properties=None, folderId=None, versioningState=None, policies=None, addACEs=None, removeACEs=None)
See CMIS specification document 2.2.4.2 createDocumentFromSource
createFolder(properties, parentFolder, policies=None, addACEs=None, removeACEs=None)

Creates a new Folder object in the specified parent.

See CMIS specification document 2.2.4.3 createFolder

createPolicy(properties)

This has not yet been implemented.

See CMIS specification document 2.2.4.5 createPolicy

The following optional arguments are not currently not supported:
  • folderId
  • policies
  • addACEs
  • removeACEs
createRelationship(properties)

This has not yet been implemented.

See CMIS specification document 2.2.4.4 createRelationship

The following optional arguments are not currently not supported:
  • policies
  • addACEs
  • removeACEs
getCapabilities()

Returns a dict of repository capabilities.

>>> caps = repo.getCapabilities()
>>> for k,v in caps.items():
...     print "%s:%s" % (k,v)
... 
PWCUpdatable:True
VersionSpecificFiling:False
Join:None
ContentStreamUpdatability:None
AllVersionsSearchable:False
Renditions:None
Multifiling:True
GetFolderTree:True
GetDescendants:True
ACL:None
PWCSearchable:True
Query:None
Unfiling:False
Changes:None
getCheckedOutDocs()

Returns a collection of CmisObject objects that are currently checked out.

See CMIS specification document 2.2.3.6 getCheckedOutDocs

None of these optional arguments are current supported:
  • folderId
  • maxItems
  • skipCount
  • orderBy
  • filter
  • includeRelationships
  • renditionFilter
  • includeAllowableActions
getCollection(collectionType)
Returns a list of CmisObject objects returned for the specified collection.
Returns the link HREF from the specified collectionType (‘checkedout’, for example).
getContentChanges(changeLogToken=None, includeProperties=None, includePolicyIds=None, includeACL=None, maxItems=None)
See CMIS specification document 2.2.6.2 getContentChanges
getFolder(folderId)

Returns a Folder object for a specified folderId

>>> someFolder = repo.getFolder('workspace://SpacesStore/aa1ecedf-9551-49c5-831a-0502bb43f348')
>>> someFolder.getObjectId()
u'workspace://SpacesStore/aa1ecedf-9551-49c5-831a-0502bb43f348'
Returns the HREF attribute of an Atom link element for the specified rel.
getObject(objectId)

Returns an object given the specified object ID.

See CMIS specification document 2.2.4.7 getObject

The following optional arguments are not currently unsupported:
  • filter
  • includeRelationships
  • includePolicyIds
  • renditionFilter
  • includeACL
  • includeAllowableActions
getObjectByPath(path)

Returns an object given the path to the object.

See CMIS specification document 2.2.4.9 getObjectByPath

The following optional arguments are not currently unsupported:
  • filter
  • includeAllowableActions
getRepositoryId()

Returns this repository’s unique identifier

>>> repo = client.getDefaultRepository()
>>> repo.getRepositoryId()
u'83beb297-a6fa-4ac5-844b-98c871c0eea9'
getRepositoryInfo()

Returns a dict of repository information.

See CMIS specification document 2.2.2.2 getRepositoryInfo

>>> repo = client.getDefaultRepository()>>> repo.getRepositoryName()
u'Main Repository'
>>> info = repo.getRepositoryInfo()
>>> for k,v in info.items():
...     print "%s:%s" % (k,v)
... 
cmisSpecificationTitle:Version 1.0 Committee Draft 04
cmisVersionSupported:1.0
repositoryDescription:None
productVersion:3.2.0 (r2 2440)
rootFolderId:workspace://SpacesStore/aa1ecedf-9551-49c5-831a-0502bb43f348
repositoryId:83beb297-a6fa-4ac5-844b-98c871c0eea9
repositoryName:Main Repository
vendorName:Alfresco
productName:Alfresco Repository (Community)
getRepositoryName()

Returns this repository’s name

>>> repo = client.getDefaultRepository()
>>> repo.getRepositoryName()
u'Main Repository'
getRootFolder()

Returns the root folder of the repository

>>> root = repo.getRootFolder()
>>> root.getObjectId()
u'workspace://SpacesStore/aa1ecedf-9551-49c5-831a-0502bb43f348'
getTypeChildren(typeId=None)

Returns a list of ObjectType objects corresponding to the child types of the type specified by the typeId.

If no typeId is provided, the result will be the same as calling self.getTypeDefinitions

See CMIS specification document 2.2.2.3 getTypeChildren

These optional arguments are current unsupported:
  • includePropertyDefinitions
  • maxItems
  • skipCount
>>> baseTypes = repo.getTypeChildren()
>>> for baseType in baseTypes:
...     print baseType.getTypeId()
... 
cmis:folder
cmis:relationship
cmis:document
cmis:policy
getTypeDefinition(typeId)

Returns an ObjectType object for the specified object type id.

See CMIS specification document 2.2.2.5 getTypeDefinition

>>> folderType = repo.getTypeDefinition('cmis:folder')
getTypeDefinitions()

Returns a list of ObjectType objects representing the base types in the repository.

>>> baseTypes = repo.getTypeDefinitions()
>>> for baseType in baseTypes:
...     print baseType.getTypeId()
... 
cmis:folder
cmis:relationship
cmis:document
cmis:policy
getTypeDescendants(typeId=None)

Returns a list of ObjectType objects corresponding to the descendant types of the type specified by the typeId.

If no typeId is provided, the repository’s “typesdescendants” URL will be called to determine the list of descendant types.

See CMIS specification document 2.2.2.4 getTypeDescendants

These optional arguments are currently unsupported:
  • depth
  • includePropertyDefinitions
>>> allTypes = repo.getTypeDescendants()
>>> for aType in allTypes:
...     print aType.getTypeId()
... 
cmis:folder
F:cm:systemfolder
F:act:savedactionfolder
F:app:configurations
F:fm:forums
F:wcm:avmfolder
F:wcm:avmplainfolder
F:wca:webfolder
F:wcm:avmlayeredfolder
F:st:site
F:app:glossary
F:fm:topic
getUriTemplates()
Returns a list of the URI templates the repository service knows about.
query(statement)

Returns a list of CmisObject objects based on the CMIS Query Language passed in as the statement.

In order for the results to be properly instantiated as objects, make sure you include ‘cmis:objectId’ as one of the fields in your select statement, or just use “SELECT *”.

See CMIS specification document 2.2.6.1 query

The following optional arguments are not currently unsupported:
  • searchAllVersions
  • includeRelationships
  • renditionFilter
  • includeAllowableActions
  • maxItems
  • skipCount
reload()
This method will re-fetch the object’s data from the CMIS repository.
exception cmislib.model.RuntimeException
RuntimeException
exception cmislib.model.StorageException
StorageException
exception cmislib.model.StreamNotSupportedException
StreamNotSupportedException
exception cmislib.model.UpdateConflictException
UpdateConflictException
class cmislib.model.UriTemplate(template, templateType, mediaType)
Simple dictionary to represent the data stored in a URI template entry.
exception cmislib.model.VersioningException
VersioningException
cmislib.model.multiple_replace(aDict, text)

Replace in ‘text’ all occurences of any key in the given dictionary by its corresponding value. Returns the new string.

See http://code.activestate.com/recipes/81330/

cmislib.model.parseValue(value)
Utility function to parse booleans and none from strings

The cmislib.net Module

The cmislib.net Module contains the classes used by cmislib.model.CmisClient to communicate with the CMIS repository. The most important of which is cmislib.net.RESTService.

Module that knows how to connect to the AtomPub Binding of a CMIS repo

class cmislib.net.RESTService

Generic service for interacting with an HTTP end point. Sets headers such as the USER_AGENT and builds the basic auth handler.

delete(url, username=None, password=None)
Makes a delete request to the URL specified.
get(url, username=None, password=None)
Makes a get request to the URL specified.
post(url, payload, contentType, username=None, password=None)
Makes a POST request to the URL specified and posts the payload that gets passed in. The content type header gets set to the specified content type.
put(url, payload, contentType, username=None, password=None)
Makes a PUT request to the URL specified and includes the payload that gets passed in. The content type header gets set to the specified content type.

Table Of Contents

Previous topic

Installation

Next topic

Tests

This Page