#!/usr/bin/python # reisolate - re-isolate a patch # this is used for taking a large patch, and dividing it into # smaller pieces (based on previously existing smaller patches) # # This program is used to extract a sub-patch from a larger # patch, based on the list of files in an existing patch. # example: if patch L has diffs for files A, B, and C, # and patch S has diffs for files A, and B, then # reisolate L S S-new # will take the pieces of L for files A and B and put # them into patch S-new. # # usage: reisolate new.patch prior_sub.patch new_sub.patch # import sys import os import commands def usage(): print "usage: reisolate new.patch prior_sub.patch new_sub.patch" sys.exit(1) def main(): # get filenames from command line args try: patch = sys.argv[1] prior_sub = sys.argv[2] new_sub = sys.argv[3] except: usage() # parse the filenames to extract command = "diffinfo -l %s" % prior_sub sub_file_lines = commands.getoutput(command).split("\n") sub_file_list = [] for line in sub_file_lines: sub_file_list.append(line.strip()) # get rid of new sub-patch, if it exists try: os.unlink(new_sub) except: pass # put each sub-sub-patch into a separate file # (this is only done for debugging purposes) tc = 1 # extract each file and append to new_sub for f in sub_file_list: print "extracting", f tempfile = "reisolate.tmp%03d" % tc command = "diffinfo -p ^%(f)s -n %(tempfile)s %(patch)s" % locals() (status,output) = commands.getstatusoutput(command) command = "cat %(tempfile)s >>%(new_sub)s" % locals() (status,output) = commands.getstatusoutput(command) tc += 1 os.unlink(tempfile) print "new sub-patch is:", new_sub if __name__=="__main__": main()