Generalize the patch application procedure

Current depth for the patch command (-p3) is tied to historical
format of patches to Puppet manifests which used to be based from
/etc/puppet/modules directory.

Change the depth to -p1 generalize patching approach for other
paths in the host file system.

Change-Id: I8538af2192aa29987404fbe130934122997a2625
This commit is contained in:
Oleg Gelbukh 2016-04-11 10:34:03 +00:00
parent 4aabc73400
commit a4ed2778ab
2 changed files with 4 additions and 4 deletions

View File

@ -36,9 +36,9 @@ class MockFile(mock.MagicMock):
def assert_calls(self): def assert_calls(self):
kwargs = {'stdin': self, 'cwd': magic_consts.PUPPET_DIR} kwargs = {'stdin': self, 'cwd': magic_consts.PUPPET_DIR}
args = [((["patch", "-R", "-p3"], ), kwargs), ] args = [((["patch", "-R", "-p1"], ), kwargs), ]
if not self.revert: if not self.revert:
args.append(((["patch", "-N", "-p3"], ), kwargs)) args.append(((["patch", "-N", "-p1"], ), kwargs))
assert args == self.call_args assert args == self.call_args

View File

@ -17,7 +17,7 @@ def patch_apply(cwd, patches, revert=False):
for path in patches: for path in patches:
with open(path, 'rb') as patch: with open(path, 'rb') as patch:
try: try:
subprocess.call(["patch", "-R", "-p3"], stdin=patch, cwd=cwd) subprocess.call(["patch", "-R", "-p1"], stdin=patch, cwd=cwd)
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
if not revert: if not revert:
pass pass
@ -25,4 +25,4 @@ def patch_apply(cwd, patches, revert=False):
raise raise
if not revert: if not revert:
patch.seek(0) patch.seek(0)
subprocess.call(["patch", "-N", "-p3"], stdin=patch, cwd=cwd) subprocess.call(["patch", "-N", "-p1"], stdin=patch, cwd=cwd)