MCPcopy Create free account
hub / github.com/ImageEngine/cortex / doOperation

Method doOperation

python/IECore/LsHeaderOp.py:81–118  ·  view source on GitHub ↗
( self, operands )

Source from the content-addressed store, hash-verified

79 )
80
81 def doOperation( self, operands ) :
82
83 try:
84 reader = IECore.Reader.create( operands["file"].value )
85 headers = reader.readHeader()
86 except:
87 IECore.debugException( "Error reading header" )
88 headers = None
89
90 if headers is None:
91 raise Exception( "Could not get header from file " + operands["file"].value )
92
93 def formatCompound( compound, lines, level = 0 ):
94 levelStr = "";
95 i = 0
96 while( i < level ):
97 levelStr += " "
98 i += 1
99
100 for key in compound.keys():
101 value = compound[ key ]
102 if isinstance( value, IECore.CompoundObject ) or isinstance( value, IECore.CompoundData ):
103 lines.append( levelStr + key + ": " )
104 formatCompound( value, lines, level + 1 )
105 elif IECore.isSimpleDataType( value ):
106 lines.append( levelStr + key + ": " + str(value.value) )
107 elif IECore.isSequenceDataType( value ):
108 lines.append( levelStr + key + ": " + ", ".join( map( str, value ) ) )
109 else:
110 lines.append( levelStr + key + ": " + str(value) )
111
112 headerLines = []
113 formatCompound( headers, headerLines )
114
115 if operands.resultType.value == "string" :
116 return IECore.StringData( "\n".join( headerLines ) )
117 else :
118 return IECore.StringVectorData( headerLines )
119
120IECore.registerRunTimeTyped( LsHeaderOp )

Callers

nothing calls this directly

Calls 3

joinMethod · 0.80
createMethod · 0.45
readHeaderMethod · 0.45

Tested by

no test coverage detected