CMIS stands for
Content Management Interoperability Services. Using CMIS within Python scripts is a handy way to export/import data from/to Alfresco (or any other CMIS-compliant document management system) or do mass updates of data within Alfresco. This can be changes to document attributes or even changes to the documents themselves. If you come from a relational database background, think of CMIS scripts fulfilling a similar role with Alfresco as SQL scripts do with relational databases.
cmislib from Apache Chemistry is a CMIS client library for Python. This tutorial shows you how to install Python and CMIS on a Ubuntu computer.
Python is an elegant readable language, with an emphasis on simplicity, and I think for that reason has become very popular. It is my personal preference for writing CMIS scripts.
From the author: Guido Van Rossum
The Zen of Python:
Python and CMIS Installation
- install setuptools for python
sudo apt-get install python python-setuptools
- install cmislib
sudo easy_install cmislib
- download the most recent version of cmislib-alfresco-extension
- install cmislib-alfresco-extension
sudo easy_install master.zip
Test Python and CMIS
Test your installation by running the script below that lists the sites in your Alfresco system.
- paste the code into a file called test.py
- change the URL to your Alfresco server
- change the ‘password’ to the correct password for your Alfresco system
#!/usr/bin/env python # Alfresco extension to CMIS import cmislibalf from cmislib import CmisClient, Repository, Folder from cmislib.model import CmisId from cmislib.exceptions import CmisException, UpdateConflictException import os, sys try: client = CmisClient('http://domain.com.au:8080/alfresco/cmisatom', 'admin', 'password') repo = client.defaultRepository except: print "failed to connect to Alfresco" quit() try: print 'Getting list of sites ..' folders = repo.query("select * from cmis:folder where cmis:objectTypeId='F:st:site'") print 'Processing list ..' for folder in folders: obj = repo.getObject(folder.id) # properties items are key-value TUPLES .. for key,val in obj.properties.items(): if key=='cm:name' or key=='cm:title' or key=='cmis:path': print key,'=',val except ValueError: print "failed to read site list"
- make test.py executable
chmod +x test.py
- run the script
- output from the script will look something like ..
Getting list .. Processing list .. cmis:path = /Sites/swsdp cm:title = Sample: Web Site Design Project cmis:path = /Sites/gpc cm:title = GPC cmis:path = /Sites/digs cm:title = DIGS
Apache Chemistry has some good tutorials and example code ..
CMIS Workbench is a great tool for querying Alfresco and doing quick edits. It is also a very useful tool for determining attributes of objects while writing CMIS scripts. You can download from http://www.apache.org/dyn/closer.cgi/chemistry/opencmis/0.13.0/chemistry-opencmis-workbench-0.13.0-full.zip
Order of the Bee – an independent organisation of the Alfresco community. Web-site includes good technical and non-technical posts and other information, focussed mainly on Alfresco Community Edition (CE).