fcsxml.FCSXMLObject

class fcsxml.FCSXMLObject(entityID=0, entityType='asset', id=0, configParser='')[source]

FCSXMLObject represents a Final Cut Server entity which uses Final Cut Server Read XML and Write XML watcher+response systems for RPC. This object can only perform a small subset of the tasks that fcsxml.FCSVRClient can perform.

Parameters:
  • entityID (int) – Provide the entity id
  • entityType (str) – Provide entity type, usually ‘asset’ or ‘project’ [default ‘asset’]
  • configParser (ConfigParser.SafeConfigParser or str) – An optional ConfigParser object to configure default behavior. Alternatively this can be a file system path to a configuration file to load
appendField(field)[source]

This method will add a new FCSXMLField to the objects field definition list. This function will raise an FCSDuplicate exception if a field object with same name already exists.

Parameters:field (fcsxml.FCSXMLField) – Provide an FCSXMLField object loaded with field name and value
Returns:(bool) True or False
Raises :fcsxml.FCSDuplicateError, RuntimeError
appendValueForField(fieldName, value, useTimestamp=False)

Appends a value to field, concatenating with the current field value.

Parameters:
  • fieldName (str) – Provide the field name
  • value (id) – Provide the value to append.
  • useTimeStamp (bool) – If set to true, we will prepend a timestamp to the data to be appended.
Raises :

fcsxml.FCSFieldNotFoundError

dataTypeForField(fieldName)[source]

This method returns the datatype for the passed field name.

Parameters:fieldName (str) – Provide the name of the field to query.
Raises :fcsxml.FCSFieldNotFoundError
Returns:(str) Datatype for the specified field
fieldWithName(fieldName)[source]

This method returns the fcsxml.FCSXMLField object for the passed field name.

Parameters:fieldName (str) – Provide the name of the field to query.
Raises :fcsxml.FCSFieldNotFoundError
Returns:(fcsxml.FCSXMLField) – The stored field object for the specified field
getXMLNodeText(nodes)[source]

This function accepts a list of xml.dom.minidom nodes and will return a collated text string comprised of each nodes value.

Parameters:nodes (list) –
Returns:(str) – Concatenated string of all passed nodes’ text values.
loadConfiguration(parser=None, filePath=None)

This method will load internal parameters as specified in the provided ConfigParser.SafeConfigParser object, or via the configuration file referenced via the filePath parameter.

Parameters:
  • parser (ConfigParser.SafeConfigParser) – A configuration object.
  • filePath (str) – An absolute path to a configuration file.

Note

If you subclass, you should call this parent function. If we raise a RuntimeError Exception, you should abort or perform your own exhaustive sanity checks

loadFromFCSVRClient(fcsvrClient)[source]

This function will load our object based upon values stored in the provided FCSVRClient object, this is limited to entityID, entityType and defined fields.

Parameters:fcsvrClient (fcsxml.FCSVRClient) – Provide a loaded FCSVRClient object
Raises :FCSObjectLoadError
loadFromFile(filePath)[source]

This function will load the object based upon values present in the XML file found at the provided filepath.

Parameters:filePath (str) – The path to the XML file to load.
Returns:(bool) True or False
loadXML(xml='')[source]

Method which loads our object based upon our stored xml.dom.minidom object, which is loaded by fcsxml.FCSXMLObject.loadFromFile() or :func: fcsxml.FCSXMLObject.loadXMLFromString

Parameters:xml (xml.dom.minidom) – Provide an XML dom.minidom object for which to load from.
Raises :FCSObjectLoadError
Returns:(bool) True
loadXMLFromString(xmlString='')[source]

This method allows our object to load based on the provided XML string. This method utilizes fcsxml.FCSXMLObject.loadXML() to initiate the object.

Parameters:xmlString (str) – Provide a string of XML data.
Raises :See mindom.parseString()
removeFieldWithName(fieldName)[source]

Remove FCSXMLField object registered with passed field name.

Parameters:fieldName (str or fcsxml.FCSXMLField) – Provide the field name (or an FCSXMLField object) to be removed from the current object’s field list.
Raises :fcsxml.FCSFieldNotFoundError, RuntimeError
setField(field)[source]

This method register’s the provided FCSXMLField object, replacing existing field object with same name if it should exist.

Parameters:field (fcsxml.FCSXMLField) – Provide an FCSXMLField object loaded with field name and value
Returns:(bool) True or False
setFile(filePath)[source]

Historical method, use loadFromFile()

setMD(filePath='')

This is a wrapper function for xmlOut, it is included to maintain compatability with the fcsxml.FCSVRClient class interface.

valueForField(fieldName)[source]

This method returns the stored value for the passed database field name. (i.e. “My Field”)

param fieldName:
 Provide the name of the field to query.
type fieldName:str
raises:fcsxml.FCSFieldNotFoundError
returns:(str) Value for the specified field
xmlOut(filePath='')[source]

Write our XML out to a file at the provided path. The output format will be a Final Cut Server ReadXML compatable file.

Parameters:filePath (str) – Provide the (absolute) destination path for XML output
Raises :IOError
Returns:(bool) - True or False

Example Code

The following section illustrates some example uses of FCSXMLObject.

Import the fcsxml module and instantiate an asset at entity path /asset/22:

## Import our module
>>> import fcsxml

## Create our FCSXMLObject and load our config
>>> myFCSXMLAsset = fcsxml.FCSXMLObject(id=22,entityType='asset')
>>> myFCSXMLAsset.loadConfiguration(filePath='/usr/local/etc/transmogrifier.conf')
True

Because our FCSXMLObject interacts solely with XML files, we are fairly limited with what we can do. In this case, wa have started with an empty object, so all that we can do is to write a field back to FCS. In this example, we will set the value of field Export to FM to True:

## Generate our field object.
>>> myField = fcsxml.FCSXMLField(name='Export to FM',value=True,dataType='bool')

## Associate the new field object to our asset
>>> myFCSXMLAsset.setField(myField)

## Commit the field to FCS
>>> myFCSXMLAsset.setMD()

The setMD function will write out an XML file, in this case containing only an entry for the Export to FM field, to our fcsvr_xmlin directory. By default, this will be the directory named fcsvr_xmlin residing directly inside our support folder as defined by the path variable in our configuraiton file.

A separate usage of fcsxml.FCSXMLObject will be related around ingesting and interpretting XML as provided by an FCS WriteXML response. This is achieved with the function fcsxml.FCSXMLObject.loadFromFile(), as shown below.

## Import our module
>>> import fcsxml

## Create our empty asset, load in the configuration
>>> myFCSXMLAsset = fcsxml.FCSXMLObject(configParser='/usr/local/etc/transmogrifier.conf')

## Read in our XML file
>>> myFCSXMLAsset.loadFromFile('/FCSSupport/fcsvr_xmlout/asset_10.xml')

## Read in a field value
>>> myFCSXMLAsset.valueForField('Title')
  u('My Asset Title')

## Read in a non-exististant value
>>> myFCSXMLAsset.valueForField('BadFieldName')
  Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "fcsxml.py", line 702, in valueForField
    raise FCSFieldNotFoundError(fieldName)
  fcsxml.FCSFieldNotFoundError: "No Field with key:'BadFieldName' exists!"

Lastly, we can load an fcsxml.FCSXMLObject class with values from an fcsxml.FCSVRClient class and output a FCS ReadXML compliant XML file.

## Import our module
>>> import fcsxml

## Create our :class:`fcsxml.FCSVRClient` instance
>>> myFCSVRAsset = fcsxml.FCSVRClient(entityID=32,
                            entityType='asset',
                            configParser='/usr/local/etc/transmogrifier.conf')

## Create a field object based on our DB Field name (something FCSXMLObject
## cannot do)
>>> myField = myFCSVRAsset.initFieldWithDBName('CUST_TITLE')
>>> myField.setValue('New Title')
>>> myFCSVRAsset.setField(myField)

## Create our :class:`fcsxml.FCSXMLObject` instance
>>> myFCSXMLAsset = fcsxml.FCSXMLObject()
>>> myFCSXMLAsset.loadFromFCSVRClient(myFCSVRAsset)

## Write our XML file
>>> myFCSXMLAsset.setMD()

Table Of Contents

Previous topic

fcsxml.FCSXMLField

Next topic

fcsxml.FCSVRClient

This Page