def patch_installed_packages(stage_dir_abs, patch_dirs, dver): """Apply all patches in patch_dir to the files in stage_dir_abs Assumptions: - stage_dir_abs exists and has packages installed into it - patch files are to be applied in sorted order (by filename; directory name does not matter) - patch files are -p1 - patch files end with .patch Return success or failure as a bool """ patch_dirs_abs = [os.path.abspath(x) for x in patch_dirs] oldwd = os.getcwd() try: os.chdir(stage_dir_abs) patch_files = [] for patch_dir_abs in patch_dirs_abs: patch_files += glob.glob(os.path.join(patch_dir_abs, "*.patch")) patch_files.sort(cmp=_cmp_basename) for patch_file in patch_files: statusmsg("Applying patch %r" % patch_file) #statusmsg("Applying patch %r" % os.path.basename(patch_file)) err = subprocess.call(['patch', '-p1', '--force', '--input', patch_file]) if err: raise Error("patch file %r failed to apply" % patch_file) finally: os.chdir(oldwd)
def _statusmsg(msg): statusmsg("[%r,%r]: %s" % (dver, basearch, msg))