729
729
if not ("PATH" in os.environ and
730
730
[p for p in os.environ["PATH"].split(":")
731
if os.path.exists(os.path.join(p,"patch"))]):
732
logging.debug("no binary 'patch' found in PATH")
731
if os.path.exists(os.path.join(p,"sed"))]):
732
logging.debug("no binary 'sed' found in PATH")
734
734
for f in os.listdir(patchdir):
735
735
# skip, not a patch file, they all end with .$md5sum
737
logging.debug("skipping '%s' (no '.')" % f)
738
739
logging.debug("check if patch '%s' needs to be applied" % f)
739
(encoded_path, md5sum) = string.split(f, ".", 1)
740
(encoded_path, md5sum) = string.rsplit(f, ".", 1)
740
741
# FIXME: this is not clever and needs quoting support for
741
742
# filenames with "_" in the name
742
743
path = encoded_path.replace("_","/")
744
#logging.debug("target for '%s' is '%s' -> '%s'" % (
745
# f, encoded_path, path))
743
746
if (os.path.exists(path) and
744
747
md5(open(path).read()).hexdigest() == md5sum):
745
748
logging.info("applying '%s'" % f)
746
749
# dry-run first, then patch if ok
747
res = call(["patch","--dry-run","-s","-p0","-i",
750
cmd = ["sed","-n", "-f", patchdir+"/"+f, path]
751
logging.debug("runing '%s'" % cmd)
750
res = call(["patch","-p0","-s","-i",patchdir+"/"+f])
754
res = call(["sed","-i","-f", patchdir+"/"+f, path])
751
755
logging.info("applied '%s' with %i status" % (f,res))
753
757
logging.warning("dry run failed, ignoring patch '%s'" % f)