Applies patches to the specified file. patches is a list of tuples (old string, new string).
(filename, patches, multiLineMatches=False)
| 433 | return (int(major), int(minor), int(patch)) |
| 434 | |
| 435 | def PatchFile(filename, patches, multiLineMatches=False): |
| 436 | """ |
| 437 | Applies patches to the specified file. patches is a list of tuples |
| 438 | (old string, new string). |
| 439 | """ |
| 440 | if multiLineMatches: |
| 441 | oldLines = [open(filename, 'r').read()] |
| 442 | else: |
| 443 | oldLines = open(filename, 'r').readlines() |
| 444 | newLines = oldLines |
| 445 | for (oldString, newString) in patches: |
| 446 | newLines = [s.replace(oldString, newString) for s in newLines] |
| 447 | if newLines != oldLines: |
| 448 | PrintInfo("Patching file {filename} (original in {oldFilename})..." |
| 449 | .format(filename=filename, oldFilename=filename + ".old")) |
| 450 | shutil.copy(filename, filename + ".old") |
| 451 | open(filename, 'w').writelines(newLines) |
| 452 | |
| 453 | def ApplyGitPatch(context, patchfile): |
| 454 | try: |
no test coverage detected