MCPcopy Create free account
hub / github.com/apache/cloudstack / replace_line

Method replace_line

python/lib/cloudutils/configFileOps.py:110–125  ·  view source on GitHub ↗
(self, startswith,stanza,always_add=False)

Source from the content-addressed store, hash-verified

108 open(self.fileName, "w").writelines(newLines)
109
110 def replace_line(self, startswith,stanza,always_add=False):
111 lines = [ s.strip() for s in open(self.fileName).readlines() ]
112 newlines = []
113 replaced = False
114 for line in lines:
115 if re.search(startswith, line):
116 if stanza is not None:
117 newlines.append(stanza)
118 self.backups.append([line, stanza])
119 replaced = True
120 else: newlines.append(line)
121 if not replaced and always_add:
122 newlines.append(stanza)
123 self.backups.append([None, stanza])
124 newlines = [ s + '\n' for s in newlines ]
125 open(self.fileName,"w").writelines(newlines)
126
127 def replace_or_add_line(self, startswith,stanza):
128 return self.replace_line(startswith,stanza,always_add=True)

Callers 4

replace_or_add_lineMethod · 0.95
addBridgeMethod · 0.45
configMethod · 0.45
setupLiveMigrationMethod · 0.45

Calls 3

readlinesMethod · 0.80
searchMethod · 0.65
appendMethod · 0.45

Tested by

no test coverage detected