(self, startswith,stanza,always_add=False)
| 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) |
no test coverage detected