June 30, 2008

Python Wrapper

Surround SCM

Works with Surround SCM 2008

For those users looking to access Surround SCM programatically, their only option is through the Command Line Interface (CLI). Many of the examples I have posted on this site show how you can access the command line interface using python. For those that are looking for an easier and more reusable option, you may find using this python library helpful.

About the wrapper

The file is simply a wrapper over the CLI. The advantage of the wrapper is that instead of having to build commands to pass the CLI, you can simple use methods and pass the parameters. Remember that this is still the CLI running in the background. This means that you still need to have the CLI installed and running. The methods are subject to how the CLI works. Make sure you review the CLI user guide to make sure you are using the command properly. If you are not getting the results you expect, run the actual command on the command line. To use this python file, just import it into your namespace within your python script.

Download

Download the python file here.

Setting the connection parameters

Instead of passing the connection parameters such as username, password, server address and port with each command, these are fields on the SCCM object.
TypeField NameDescription
stringUsernameSurround SCM username
stringPasswordPassword for the username above
stringSCMServerAddrSurround SCM server address
stringPortNumSurround SCM server port
stringSingleSignOnUsing single-signon
stringUnicodeOutputDisplay output in Unicode (Windows only)
Example:
            from PySSCM import *

            mySSCM = SSCM()
            mySSCM.SCMServerAddr='localhost'
            mySSCM.PortNum=4900
            mySSCM.Username='test
            mySSCM.Password='passtest'

Sample commands

Here are a few samples using the wrapper. Optional arguments can be skipped. If the command takes a set of known values (like FileType) then a simple class is provided for the allowed values, along with one value (called Empty) which means unspecified.

Check out

TypeParameterDescription
string or list of stringsFilesThe files to check out
stringBranchThe branch to checkout from
stringCommentThe comment associated with the check out
BooleanExclusiveCheck out files exclusively so other users cannot check them out
BooleanForceForce file retrieval from server
stringRepositoryThe repository where the file is located
BooleanRecursiveRecursively check out files if Item is a repository or file name includes wildcard characters
SCMTimestampsTimestampTimestamp to set on checked out files
stringVersionFile version to check out
SCMReplaceReplaceHow to replace writable working directory files
stringChangelistChangelist to add the file to
Example:
            from PySSCM import *

            mySSCM = SSCM()
            mySSCM.SCMServerAddr='localhost'
            mySSCM.PortNum=4900
            mySSCM.Username='test
            mySSCM.Password='passtest'
            mySSCM.checkout('Test.txt',Branch='b1',Repository='r1')

Get

TypeParameterDescription
string or list of stringsItemsThe files to get
stringBranchThe branch to checkout from
stringLocalDirLocal directory to get files to
BooleanWriteableMake local files writable
BooleanForceForce file retrieval from server
stringRepositoryThe repository where the file is located
stringLabelLabel to search for
stringTimestampTimestamp to search for
stringVersionFile version to get
BooleanRemovedInclude removed files when getting files by label or timestamp
BooleanDisplayVersionDisplay the file version retrieved
BooleanRecursiveRecursively get files if Item is a repository or file name includes wildcard characters
SCMTimestampsRetrievelTimestampTimestamp to set on retrieved files
SCMReplaceReplaceHow to replace local writable files or handle modified files in the working directory that were removed from the server
Example:
            from PySSCM import *

            mySSCM = SSCM()
            mySSCM.SCMServerAddr='localhost'
            mySSCM.PortNum=4900
            mySSCM.Username='test
            mySSCM.Password='passtest'
            mySSCM.get(['Test.txt','Test2,txt'],Branch='b1',Repository='r1')