summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorYaakov M. Nemoy <loupgaroublond@gmail.com>2009-01-17 01:12:13 -0500
committerYaakov M. Nemoy <loupgaroublond@gmail.com>2009-01-17 01:12:13 -0500
commit29fcdf293be6a8a65624e9bebccecce4d48ec9f0 (patch)
tree702f235a72d9edb7f4863d6692b7f649e3b83aca /modules
parentc5b381c3af851468406f8ee71cbf24b5f11becdf (diff)
downloadfedora-devshell-29fcdf293be6a8a65624e9bebccecce4d48ec9f0.tar.gz
fedora-devshell-29fcdf293be6a8a65624e9bebccecce4d48ec9f0.tar.xz
fedora-devshell-29fcdf293be6a8a65624e9bebccecce4d48ec9f0.zip
Adds patch management to SourceBall
Diffstat (limited to 'modules')
-rw-r--r--modules/packagesource.py11
-rw-r--r--modules/sourceball.py101
2 files changed, 103 insertions, 9 deletions
diff --git a/modules/packagesource.py b/modules/packagesource.py
index 95b3cca..b98f21e 100644
--- a/modules/packagesource.py
+++ b/modules/packagesource.py
@@ -41,12 +41,12 @@ class PackageSource(Directory):
return join(self.dir, self.pkg_src)
@property
- def branch(self):
+ def branches(self):
return join(self.pkg_src, 'branches')
@property
- def branch_dir(self):
- return join(self.dir, self.branch)
+ def branches_dir(self):
+ return join(self.dir, self.branches)
@property
def sourceball(self):
@@ -74,3 +74,8 @@ class PackageSource(Directory):
'''
return join(self.dir, self.source)
+ def branch(self, *args):
+ raise NotImplementedError
+
+ def branch_dir(self, *args):
+ return join(self.branch_dir, self.branch(*args))
diff --git a/modules/sourceball.py b/modules/sourceball.py
index 17d6def..3a38c01 100644
--- a/modules/sourceball.py
+++ b/modules/sourceball.py
@@ -19,7 +19,7 @@ from __future__ import with_statement
import tarfile
-from os import makedirs, getcwd
+from os import makedirs, getcwd, listdir
from os.path import abspath, split, basename, join
from shutil import copytree
from subprocess import Popen, PIPE
@@ -28,10 +28,17 @@ from tempfile import mkdtemp
from base.base import log
from base.dirfactory import DirFactory
from base.exceptions import ExecutionException
-from base.util import pwd, copy, move, base_dir
+from base.util import pwd, copy, move, base_dir, log_file, rm
+from base.vars import DIFF_EXCLUDES_FILE
from modules.packagesource import PackageSource
+# 4's what git uses
+# if we go over 4 digits, then weird stuff will happen
+# but if we go over 4 digits, we're probably doing packaging wrong
+# TODO: decide if this should be a hardcode constant or what
+patch_num_len = 4
+
class SourceBall(PackageSource):
'''a type of package that is a single sourceball, a spec file, and some patches'''
def __init__(self, name=None, tarball=''):
@@ -51,12 +58,12 @@ class SourceBall(PackageSource):
if tarball:
with pwd(self.parent):
sourceball.extractall()
- with pwd(self.branch_dir):
+ with pwd(self.branches_dir):
sourceball.extractall()
move(self.name, self.orig_dir(self.name))
with pwd(self.pkg_src_dir):
move(join(tmp_dir, sourceball_name), sourceball_name)
- self.cfg['sourceball'] = sourceball_name
+ self.cfg['sourceball'] = sourceball_name
def orig_dir(self, dir):
'''where is the original source kept
@@ -64,6 +71,10 @@ class SourceBall(PackageSource):
use for making patches against modified source'''
return dir + '_orig'
+ def branch(self, *args):
+ if len(args) == 1 and args[0] == 'orig':
+ return join(self.branches, self.orig_dir(self.name))
+
def set_cur_to(self, *args):
'''gives source directory
@@ -72,8 +83,39 @@ class SourceBall(PackageSource):
'''
if len(args) == 1 and args[0] == 'head':
self.cfg['source'] = '.'
- elif len(args) == 1 and args[0] == 'orig':
- self.cfg['source'] = join(self.branch, self.orig_dir(self.name))
+ else:
+ self.cfg['source'] = self.branch(arg[0])
+
+
+ @property
+ def cur_patch_num(self):
+ if len(self.patches):
+ return max(int(basename(pfname)[:patch_num_len]) for pfname in self.patches)
+ else:
+ return 0
+
+ @property
+ def next_patch_num(self):
+ next = str(self.cur_patch_num + 1)
+ while len(next) < patch_num_len:
+ next = '0' + next
+ return next
+
+ 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()
def setup_sourceball(self, ver=''):
return
@@ -81,5 +123,52 @@ class SourceBall(PackageSource):
def setup_sourceball_w_patches(self, ver=''):
raise NotImplementedError
+ def clean_orig(self):
+ with pwd(self.pkg_src_dir):
+ sourceball = tarfile.open(self.sourceball)
+ with pwd(self.branches_dir):
+ rm(self.orig_dir(self.name))
+ sourceball.extractall()
+ move(self.name, self.orig_dir(self.name))
+
+ @property
+ def patches(self):
+ with pwd(self.pkg_src_dir):
+ files = [abspath(f) for f in listdir('.') if f.endswith('.patch')]
+ return files
+
+ def do_patch(self, patch, cmd):
+ with log_file(join(self.pkg_src_dir, 'patch.log')) as patch_log:
+ patch_log.write('using patch %s...\n' % basename(patch))
+ with file(patch, 'r') as pfile:
+ p = Popen(cmd, stdin=pfile,
+ stdout=patch_log, stderr=patch_log)
+ log.info('patching %s, please wait....' % basename(patch))
+ p.communicate()
+
+ def apply_patch(self, patch):
+ self.do_patch(patch, ['patch', '-p0'])
+
+ def remove_patch(self, patch):
+ self.do_patch(patch, ['patch', '-p0', '-R'])
+
+ def apply_patches(self, *args):
+ with pwd(self.branch('orig')):
+ for patch in sorted(self.patches):
+ self.apply_patch(patch)
+
+ def remove_patches(self, *args):
+ with pwd(self.branch('orig')):
+ for patch in list(reversed(self.patches)):
+ self.remove_patch(patch)
+
+ def import_other_patch(self, patch_file, patch_level):
+ if type(patch_level) is int:
+ patch_level = str(patch_level)
+ cmd = ['patch', '-p' + patch_level]
+ with pwd(self.dir):
+ self.do_patch(patch_file, cmd)
+ patch_name = basename(patch_file)
+ self.generate_patch(patch_name)
__all__ = ['SourceBall']