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

Method doOperation

python/IECore/SearchReplaceOp.py:88–128  ·  view source on GitHub ↗
( self, operands )

Source from the content-addressed store, hash-verified

86 )
87
88 def doOperation( self, operands ) :
89
90 source = operands["source"].value
91 destination = operands["destination"].value
92
93 searchFor = operands["searchFor"].value
94 if not operands["regexpSearch"] :
95 searchFor = re.escape( searchFor )
96
97 replaceWith = operands["replaceWith"].value
98
99 inFileStat = os.stat( source ).st_mode
100
101 inFile = open( source, "r" )
102
103 tmpDestination = None
104 if source == destination :
105 fd, tmpDestination = tempfile.mkstemp()
106 outFile = os.fdopen( fd, "w" )
107 else :
108 outFile = open( destination, "w" )
109
110 inLine = inFile.readline()
111 while inLine :
112
113 outLine = re.sub( searchFor, replaceWith, inLine )
114 outFile.write( outLine )
115
116 inLine = inFile.readline()
117
118 inFile.close()
119 outFile.close()
120
121 if tmpDestination :
122
123 shutil.move( destination, destination + ".bak" )
124 shutil.move( tmpDestination, destination )
125
126 os.chmod( destination, inFileStat )
127
128 return IECore.StringData( destination )
129
130IECore.registerRunTimeTyped( SearchReplaceOp )

Callers

nothing calls this directly

Calls 2

closeMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected