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.
Handles all communication with the CMIS provider.
Does a delete against the CMIS service. More than likely, you will not need to call this method. Instead, let the other objects to it for you.
For example, to delete a folder you’d call Folder.delete and to delete a document you’d call Document.delete.
Does a get against the CMIS service. More than likely, you will not need to call this method. Instead, let the other objects to it for you.
For example, if you need to get a specific object by object id, try Repository.getObject. If you have a path instead of an object id, use Repository.getObjectByPath. Or, you could start with the root folder (Repository.getRootFolder) and drill down from there.
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'
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'}]
Returns the repository identified by the specified repositoryId.
>>> repo = client.getRepository('83beb297-a6fa-4ac5-844b-98c871c0eea9')
>>> repo.getRepositoryName()
u'Main Repository'
Does a post against the CMIS service. More than likely, you will not need to call this method. Instead, let the other objects to it for you.
For example, to update the properties on an object, you’d call CmisObject.updateProperties. Or, to check in a document that’s been checked out, you’d call Document.checkin on the PWC.
Does a put against the CMIS service. More than likely, you will not need to call this method. Instead, let the other objects to it for you.
For example, to update the properties on an object, you’d call CmisObject.updateProperties. Or, to check in a document that’s been checked out, you’d call Document.checkin on the PWC.
Common ancestor class for other CMIS domain objects such as Document and Folder.
Repository.getCapabilities[‘ACL’] must return manage.
See CMIS specification document 2.2.10.2 applyACL
This is not yet implemented.
See CMIS specification document 2.2.9.1 applyPolicy
Deletes this CmisObject from the repository. Note that in the case of a Folder object, some repositories will refuse to delete it if it contains children and some will delete it without complaint. If what you really want to do is delete the folder and all of its descendants, use deleteTree() instead.
See CMIS specification document 2.2.4.14 delete
>>> folder.delete()
The optional allVersions argument is not yet supported.
Repository.getCapabilities[‘ACL’] must return manage or discover.
See CMIS specification document 2.2.10.1 getACL
The optional onlyBasicPermissions argument is currently not supported.
Returns a dictionary of allowable actions, keyed off of the action name.
>>> actions = doc.getAllowableActions()
>>> for a in actions:
... print "%s:%s" % (a,actions[a])
...
canDeleteContentStream:True
canSetContentStream:True
canCreateRelationship:True
canCheckIn:False
canApplyACL:False
canDeleteObject:True
canGetAllVersions:True
canGetObjectParents:True
canGetProperties:True
See CMIS specification document 2.2.4.6 getAllowableActions
This is not yet implemented.
See CMIS specification document 2.2.9.3 getAppliedPolicies
Returns the value of cmis:name from the getProperties() dictionary. We don’t need a getter for every standard CMIS property, but name is a pretty common one so it seems to make sense.
>>> doc.getName()
u'system-overview.html'
Returns the object ID for this object.
>>> doc = resultSet.getResults()[0]
>>> doc.getObjectId()
u'workspace://SpacesStore/dc26102b-e312-471b-b2af-91bfb0225339'
This has not yet been implemented.
See CMIS specification document 2.2.3.5 getObjectParents
Returns a dict of the object’s properties. If CMIS returns an empty element for a property, the property will be in the dict with a value of None.
See CMIS specification document 2.2.4.8 getProperties
>>> props = doc.getProperties()
>>> for p in props:
... print "%s: %s" % (p, props[p])
...
cmis:contentStreamMimeType: text/html
cmis:creationDate: 2009-12-15T09:45:35.369-06:00
cmis:baseTypeId: cmis:document
cmis:isLatestMajorVersion: false
cmis:isImmutable: false
cmis:isMajorVersion: false
cmis:objectId: workspace://SpacesStore/dc26102b-e312-471b-b2af-91bfb0225339
The optional filter argument is not yet implemented.
This is not yet implemented.
See CMIS specification document 2.2.4.13 move
This is not yet implemented.
See CMIS specification document 2.2.9.2 removePolicy
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
>>> folder = repo.getObjectByPath('/someFolder2')
>>> folder.getName()
u'someFolder2'
>>> props = {'cmis:name': 'someFolderFoo'}
>>> folder.updateProperties(props)
<cmislib.model.Folder object at 0x103ab1210>
>>> folder.getName()
u'someFolderFoo'
The optional changeToken is not yet supported.
An object typically associated with file content.
Cancels the checkout of this object by retrieving the Private Working Copy (PWC) and then deleting it. After the PWC is deleted, this object will be reloaded to update properties related to a checkout.
See CMIS specification document 2.2.7.2 cancelCheckOut
>>> doc.isCheckedOut()
True
>>> doc.cancelCheckout()
>>> doc.isCheckedOut()
False
Checks in this Document which must be a private working copy (PWC).
See CMIS specification document 2.2.7.3 checkIn
>>> doc.isCheckedOut()
False
>>> pwc = doc.checkout()
>>> doc.isCheckedOut()
True
>>> pwc.checkin()
<cmislib.model.Document object at 0x103a8ae90>
>>> doc.isCheckedOut()
False
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
>>> doc.getObjectId()
u'workspace://SpacesStore/f0c8b90f-bec0-4405-8b9c-2ab570589808;1.0'
>>> doc.isCheckedOut()
False
>>> pwc = doc.checkout()
>>> doc.isCheckedOut()
True
This is not yet implemented.
See CMIS specification document 2.2.7.5 getAllVersions
The optional filter and includeAllowableActions arguments are not yet supported.
Returns the CMIS service response from invoking the ‘enclosure’ link.
See CMIS specification document 2.2.4.10 getContentStream
>>> doc.getName()
u'sample-b.pdf'
>>> o = open('tmp.pdf', 'wb')
>>> result = doc.getContentStream()
>>> o.write(result.read())
>>> result.close()
>>> o.close()
>>> import os.path
>>> os.path.getsize('tmp.pdf')
117248
The optional streamId argument is not yet supported.
This is not yet implemented.
See CMIS specification document 2.2.7.4 getObjectOfLatestVersion
Retrieves the object using the object ID in the property: cmis:versionSeriesCheckedOutId then uses getObject to instantiate the object.
>>> doc.isCheckedOut()
False
>>> doc.checkout()
<cmislib.model.Document object at 0x103a25ad0>
>>> pwc = doc.getPrivateWorkingCopy()
>>> pwc.getTitle()
u'sample-b (Working Copy).pdf'
This is not yet implemented.
See CMIS specification document 2.2.7.4 getPropertiesOfLatestVersion
The optional major and filter arguments are not yet supported.
This is not yet implemented.
See CMIS specification document 2.2.8.1 getObjectRelationships
This is not yet supported.
See CMIS specification document 2.2.4.11 getRenditions
Returns true if the document is checked out.
>>> doc.isCheckedOut()
True
>>> doc.cancelCheckout()
>>> doc.isCheckedOut()
False
See CMIS specification document 2.2.4.16 setContentStream
A container object that can hold other CmisObject objects
This is not yet implemented.
See CMIS specification document 2.2.5.1 addObjectToFolder
The optional allVersions argument is not yet supported.
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.
>>> f = open('250px-Cmis_logo.png', 'rb')
>>> subFolder.createDocument('logo.png', contentFile=f)
<cmislib.model.Document object at 0x10410fa10>
>>> f.close()
If you wanted to set one or more properties when creating the doc, pass in a dict, like this:
>>> props = {'cmis:someProp':'someVal'}
>>> f = open('250px-Cmis_logo.png', 'rb')
>>> subFolder.createDocument('logo.png', props, contentFile=f)
<cmislib.model.Document object at 0x10410fa10>
>>> f.close()
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
>>> subFolder = folder.createFolder('someSubfolder')
>>> subFolder.getName()
u'someSubfolder'
Deletes the folder and all of its descendant objects.
See CMIS specification document 2.2.4.15 deleteTree
>>> resultSet = subFolder.getDescendants()
>>> len(resultSet.getResults())
2
>>> subFolder.deleteTree()
Returns a paged ResultSet. The result set contains a list of CmisObject objects for each child of the Folder. The actual type of the object returned depends on the object’s CMIS base type id. For example, the method might return a list that contains both Document objects and Folder objects.
See CMIS specification document 2.2.3.1 getChildren
>>> childrenRS = subFolder.getChildren()
>>> children = childrenRS.getResults()
Gets the descendants of this folder. The descendants are returned as a paged ResultSet object. The result set contains a list of CmisObject objects where the actual type of each object returned will vary depending on the object’s base type id. For example, the method might return a list that contains both Document objects and Folder objects.
See CMIS specification document 2.2.3.2 getDescendants
>>> resultSet = folder.getDescendants()
>>> len(resultSet.getResults())
105
>>> resultSet = folder.getDescendants(depth=1)
>>> len(resultSet.getResults())
103
The following optional arguments may also work but haven’t been tested:
- filter
- includeRelationships
- renditionFilter
- includeAllowableActions
- includePathSegment
Returns the ‘down’ link of type CMIS_TREE_TYPE
>>> folder.getDescendantsLink()
u'http://localhost:8080/alfresco/s/cmis/s/workspace:SpacesStore/i/86f6bf54-f0e8-4a72-8cb1-213599ba086c/descendants'
This is not yet implemented.
See CMIS specification document 2.2.3.4 getFolderParent
The optional filter argument is not yet supported.
This is not yet implemented.
See CMIS specification document 2.2.3.3 getFolderTree
This is not yet implemented.
See CMIS specification document 2.2.5.2 removeObjectFromFolder
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.
>>> from cmislib.model import ATOM_XML_FEED_TYPE
>>> docType.getLink('down', ATOM_XML_FEED_TYPE)
u'http://localhost:8080/alfresco/s/cmis/type/cmis:document/children'
Returns the type ID for this object.
>>> docType = repo.getTypeDefinition('cmis:document')
>>> docType.getTypeId()
'cmis:document'
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
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 File object.
See CMIS specification document 2.2.4.1 createDocument
>>> f = open('sample-a.pdf', 'rb')
>>> doc = folder.createDocument('sample-a.pdf', contentFile=f)
<cmislib.model.Document object at 0x105be5e10>
>>> f.close()
>>> doc.getTitle()
u'sample-a.pdf'
This is not yet implemented.
See CMIS specification document 2.2.4.2 createDocumentFromSource
Creates a new Folder object in the specified parentFolder.
See CMIS specification document 2.2.4.3 createFolder
>>> root = repo.getRootFolder()
>>> folder = repo.createFolder(root, 'someFolder2')
>>> folder.getTitle()
u'someFolder2'
>>> folder.getObjectId()
u'workspace://SpacesStore/2224a63c-350b-438c-be72-8f425e79ce1f'
This has not yet been implemented.
See CMIS specification document 2.2.4.5 createPolicy
This has not yet been implemented.
See CMIS specification document 2.2.4.4 createRelationship
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:anytime
AllVersionsSearchable:False
Renditions:None
Multifiling:True
GetFolderTree:True
GetDescendants:True
ACL:None
PWCSearchable:True
Query:bothcombined
Unfiling:False
Changes:None
Returns a ResultSet of CmisObject objects that are currently checked out.
See CMIS specification document 2.2.3.6 getCheckedOutDocs
>>> rs = repo.getCheckedOutDocs()
>>> len(rs.getResults())
2
>>> for doc in repo.getCheckedOutDocs().getResults():
... doc.getTitle()
...
u'sample-a (Working Copy).pdf'
u'sample-b (Working Copy).pdf'
Returns a list of objects returned for the specified collection.
If the query collection is requested, an exception will be raised. That collection isn’t meant to be retrieved.
If the types collection is specified, the method returns the result of getTypeDefinitions.
>>> from cmislib.model import TYPES_COLL
>>> types = repo.getCollection(TYPES_COLL)
>>> len(types)
4
>>> types[0].getTypeId()
u'cmis:folder'
Otherwise, the collection URL is invoked, and a ResultSet is returned.
>>> from cmislib.model import CHECKED_OUT_COLL
>>> resultSet = repo.getCollection(CHECKED_OUT_COLL)
>>> len(resultSet.getResults())
1
Returns the link HREF from the specified collectionType (‘checkedout’, for example).
>>> from cmislib.model import CHECKED_OUT_COLL
>>> repo.getCollectionLink(CHECKED_OUT_COLL)
u'http://localhost:8080/alfresco/s/cmis/checkedout'
See CMIS specification document 2.2.6.2 getContentChanges
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 an object given the specified object ID.
See CMIS specification document 2.2.4.7 getObject
>>> doc = repo.getObject('workspace://SpacesStore/f0c8b90f-bec0-4405-8b9c-2ab570589808')
>>> doc.getTitle()
u'sample-b.pdf'
Returns an object given the path to the object.
See CMIS specification document 2.2.4.9 getObjectByPath
>>> doc = repo.getObjectByPath('/jeff test/sample-b.pdf')
>>> doc.getTitle()
u'sample-b.pdf'
Returns this repository’s unique identifier
>>> repo = client.getDefaultRepository()
>>> repo.getRepositoryId()
u'83beb297-a6fa-4ac5-844b-98c871c0eea9'
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)
Returns this repository’s name
>>> repo = client.getDefaultRepository()
>>> repo.getRepositoryName()
u'Main Repository'
Returns the root folder of the repository
>>> root = repo.getRootFolder()
>>> root.getObjectId()
u'workspace://SpacesStore/aa1ecedf-9551-49c5-831a-0502bb43f348'
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
>>> baseTypes = repo.getTypeChildren()
>>> for baseType in baseTypes:
... print baseType.getTypeId()
...
cmis:folder
cmis:relationship
cmis:document
cmis:policy
Returns an ObjectType object for the specified object type id.
See CMIS specification document 2.2.2.5 getTypeDefinition
>>> folderType = repo.getTypeDefinition('cmis:folder')
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
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
>>> 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
Returns a list of the URI templates the repository service knows about.
>>> templates = repo.getUriTemplates()
>>> templates['typebyid']['mediaType']
u'application/atom+xml;type=entry'
>>> templates['typebyid']['template']
u'http://localhost:8080/alfresco/s/cmis/type/{id}'
Returns a list of CmisObject objects based on the CMIS Query Language passed in as the statement. The actual objects returned will be instances of the appropriate child class based on the object’s base type ID.
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 *”.
If you want the search results to automatically be instantiated with the appropriate sub-class of CmisObject you must either include cmis:baseTypeId as one of the fields in your select statement or just use “SELECT *”.
See CMIS specification document 2.2.6.1 query
>>> q = "select * from cmis:document where cmis:name like '%test%'"
>>> resultSet = repo.query(q)
>>> len(resultSet.getResults())
1
>>> resultSet.hasNext()
False
Represents a paged result set. In CMIS, this is most often an Atom feed.
Returns the first page of results as a dictionary of CmisObject objects or its appropriate sub-type. This only works when the server returns a “first” link. Not all of them do.
>>> resultSet.hasFirst()
True
>>> results = resultSet.getFirst()
>>> for result in results:
... result
...
<cmislib.model.Document object at 0x10480bc90>
Returns the last page of results as a dictionary of CmisObject objects or its appropriate sub-type. This only works when the server is returning a “last” link. Not all of them do.
>>> resultSet.hasLast()
True
>>> results = resultSet.getLast()
>>> for result in results:
... result
...
<cmislib.model.Document object at 0x10480bc90>
Returns the results that were fetched and cached by the get*Page call.
>>> resultSet = repo.getCheckedOutDocs()
>>> resultSet.hasNext()
False
>>> for result in resultSet.getResults():
... result
...
<cmislib.model.Document object at 0x104851810>
Returns True if this page contains a first link. Not all CMIS providers implement first links consistently.
>>> resultSet.hasFirst()
True
Returns True if this page contains a last link. Not all CMIS providers implement last links consistently.
>>> resultSet.hasLast()
True
Returns True if this page contains a next link.
>>> resultSet.hasNext()
True
Returns True if this page contains a prev link. Not all CMIS providers implement prev links consistently.
>>> resultSet.hasPrev()
True
Re-invokes the self link for the current set of results.
>>> resultSet = repo.getCollection(CHECKED_OUT_COLL)
>>> resultSet.reload()
Replace in ‘text’ all occurences of any key in the given dictionary by its corresponding value. Returns the new string.
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
Generic service for interacting with an HTTP end point. Sets headers such as the USER_AGENT and builds the basic auth handler.