diff options
author | Yaakov M. Nemoy <loupgaroublond@gmail.com> | 2009-01-17 03:24:59 -0500 |
---|---|---|
committer | Yaakov M. Nemoy <loupgaroublond@gmail.com> | 2009-01-17 03:24:59 -0500 |
commit | 15d2ff1cd78369cc4a2597271b3d09fb6db138b1 (patch) | |
tree | 751bb9db40bb334bce4e84f5c78850685eb414ba | |
parent | e29a9320e052ba100aa28268a2c40df3b6574b3d (diff) | |
download | fedora-devshell-15d2ff1cd78369cc4a2597271b3d09fb6db138b1.tar.gz fedora-devshell-15d2ff1cd78369cc4a2597271b3d09fb6db138b1.tar.xz fedora-devshell-15d2ff1cd78369cc4a2597271b3d09fb6db138b1.zip |
Adds clean room patch development, and patch cleanliness verification
-rw-r--r-- | modules/packagesource.py | 2 | ||||
-rw-r--r-- | modules/sourceball.py | 55 |
2 files changed, 44 insertions, 13 deletions
diff --git a/modules/packagesource.py b/modules/packagesource.py index d70ddd9..d556ef5 100644 --- a/modules/packagesource.py +++ b/modules/packagesource.py @@ -78,4 +78,4 @@ class PackageSource(Directory): raise NotImplementedError def branch_dir(self, *args): - return join(self.branches_dir, self.branch(*args)) + return join(self.dir, self.branch(*args)) diff --git a/modules/sourceball.py b/modules/sourceball.py index 3a38c01..8d102a8 100644 --- a/modules/sourceball.py +++ b/modules/sourceball.py @@ -19,6 +19,7 @@ from __future__ import with_statement import tarfile +from contextlib import contextmanager from os import makedirs, getcwd, listdir from os.path import abspath, split, basename, join from shutil import copytree @@ -101,21 +102,40 @@ class SourceBall(PackageSource): next = '0' + next return next + @contextmanager + def do_diff(self, src, tgt): + cmd = ['diff', '-r', '-u', '-X', DIFF_EXCLUDES_FILE, + src, tgt] + with pwd(self.pkg_src_dir): + with log_file('diff.log') as diff_out: + def command(fd): + p = Popen(cmd, stdout=fd, stderr=diff_out) + log.info('generating patch %s, please wait...' + % fd.name) + p.communicate() + yield command + def generate_patch(self, patch_name): prefix = self.next_patch_num + '.' patch_name = patch_name + '.patch' if not patch_name.endswith('.patch') else patch_name patch_name = prefix + patch_name log.debug('patch_name ' + patch_name) - cmd = ['diff', '-r', '-u', '-X', DIFF_EXCLUDES_FILE, - self.branch('orig'), '.'] - with pwd(self.pkg_src_dir): - with log_file('diff.log') as diff_out: - with file(patch_name, 'w') as patch_file: - with pwd(self.dir): - p = Popen(cmd, stdout=patch_file, stderr=diff_out) - log.info('generating patch %s, please wait...' - % patch_name) - p.communicate() + with self.patches_applied('orig'): + with self.do_diff(self.branch('orig'), '.') as diff: + with pwd(self.dir): + with file(join(self.pkg_src_dir, patch_name), 'w') as patch_file: + diff(patch_file) + # We have to do this last step because of the context manager + # it assumes that this last patch has also been applied + patch_name = join(self.pkg_src_dir, patch_name) + with pwd(self.branch_dir('orig')): + self.apply_patch(patch_name) + + @contextmanager + def patches_applied(self, *args): + self.apply_patches(*args) + yield + self.remove_patches(*args) def setup_sourceball(self, ver=''): return @@ -153,12 +173,12 @@ class SourceBall(PackageSource): self.do_patch(patch, ['patch', '-p0', '-R']) def apply_patches(self, *args): - with pwd(self.branch('orig')): + with pwd(self.branch(*args)): for patch in sorted(self.patches): self.apply_patch(patch) def remove_patches(self, *args): - with pwd(self.branch('orig')): + with pwd(self.branch(*args)): for patch in list(reversed(self.patches)): self.remove_patch(patch) @@ -170,5 +190,16 @@ class SourceBall(PackageSource): self.do_patch(patch_file, cmd) patch_name = basename(patch_file) self.generate_patch(patch_name) + + def verify_patches(self, *args): + test_file = join(self.pkg_src_dir, 'test.patch.') + with self.patches_applied(*args): + with self.do_diff(self.branch('orig'), '.') as diff: + with pwd(self.dir): + with file(test_file, 'w') as patch_file: + diff(patch_file) + clean = False if len(file(test_file).read()) else True + log.info('Verified clean patches: ' + str(clean)) + return clean __all__ = ['SourceBall'] |