Intent of this document is to describe the FMWParser library to hopefully allow easy parsing of FMW documents. This library is currently a work in progress. Demo code shown below shows what currently works and also provides a structure where future functionality would go.
Most objects that make up the 'workspace' object have a getJson object. These functions work but the output will change. When I have time the intent is that these methods will return all the information about a particular object that came from the FMW xml. Ie all the information there as a json struct.
The parser breaks an FMW document up into the following components:
- Workspace
- Feature Classes
- Sources
- Destinations
- Transformers
- Published Parameters
- Feature Classes
The indentation reflects the object model structure. Based on the bullets above you can correctly infer that you start with a Workspace, from a workspace you can retrieve Feature Classes, Transformers and Published Parameters.
To retrieve a workspace name you need to:
- create a parser
- get a workspace object
- get the workspace objects name
import FMEUtil.FMWParser
fmwFile = r'C:\somePath\to\my\fmws\test.fmw'
parser = FMEUtil.FMWParser.FMWParser(fmwFile)
wrkspcObj = parser.getFMEWorkspace()
wrkspaceName = wrkspcObj.getWorkspaceName()
print 'wrkspaceName', wrkspaceName
Steps illustrated in code:
- create the parser
- get a workspace object
- from the workspace get the feature classes
- from feature classes get the sources
- iterate over the sources printing the source name
- for each source get the dataset
- from the dataset get the dataset name.
import FMEUtil.FMWParser
parser = FMEUtil.FMWParser.FMWParser(self.fmwFile)
wrkspcObj = parser.getFMEWorkspace()
featureClasses = wrkspcObj.getFeatureClasses()
sources = featureClasses.getSources()
for src in sources:
print 'src:', src.getFeatureClassName()
print 'dataset', src.getDataSet().getDataSetName()
Basically the same as above but for destinations
...
dests = featureClasses.getDestinations()
for dest in dests:
print 'dest:', dest.getFeatureClassName()
print 'dataset:', dest.getFeatureClassName()
For more examples see the FMWParserGettingStartedDemo.py file in the FMEUtil repo.
Steps illustrated in code:
- create a parser
- get the workspace
- get the transformers
- get the names of the transformers
fmwFile = r'/mnt/fmwPlayground/parserData/demoFMWwithTransformers.fmw'
parser = FMEUtil.FMWParser.FMWParser(fmwFile)
wrkspcObj = parser.getFMEWorkspace()
transfmrs = wrkspcObj.getTransformers()
transformerNames = transfmrs.getTransformerNames()
print 'transformers used: ', transformerNames