I need some function ‘apply_patch’:
result_string = apply_patch('origin_file.txt', 'origin_file.txt.patch')
or some commands (for windows and linux):
if linux:
result_string = os.system('linux_patch --apply origin_file.txt origin_file.txt.patch')
elif windows:
result_string = os.system('windows_patch --apply origin_file.txt origin_file.txt.patch')
Helpful information: I use mercurial as version control system
Check the utility patch. It does what are you expecting to. Assuming you are in the root directory of the project, you can try:
–dry-run will tell you whether the patch applies or not, without really applying it. Eventually you will have to use the option -p n to let patch know to remove directories from the path (look at the header of the diff file).
If the patch was already applied, the utility will ask you if you would like to reverse the patch.
With mercurial you can also try ‘hg import‘. If you need it for your program, then you can import the respective modules from mercurial.