[kernel] r5178 - in people/waldi/linux-2.6/debian: . bin

Bastian Blank waldi at costa.debian.org
Mon Jan 2 22:40:12 UTC 2006


Author: waldi
Date: Mon Jan  2 22:40:11 2006
New Revision: 5178

Modified:
   people/waldi/linux-2.6/debian/bin/apply.py
   people/waldi/linux-2.6/debian/rules.real
Log:
* debian/bin/apply.py: Finish implementation.
* debian/rules.real: Use apply.py.


Modified: people/waldi/linux-2.6/debian/bin/apply.py
==============================================================================
--- people/waldi/linux-2.6/debian/bin/apply.py	(original)
+++ people/waldi/linux-2.6/debian/bin/apply.py	Mon Jan  2 22:40:11 2006
@@ -10,13 +10,129 @@
 
 version_file = 'version.Debian'
 
+class series(list):
+    def __init__(self, name, home):
+        self.name = name
+
+        filename = os.path.join(home, 'series', name)
+        if not os.path.exists(filename):
+            raise RuntimeError, "Can't find series file for %s" % name
+
+        f = file(filename)
+        for line in f.readlines():
+            line = line.strip()
+
+            if len(line) == 0 or line[0] == '#':
+                continue
+
+            items = line.split(' ')
+            operation, patch = items[:2]
+
+            if operation in ('+', '-'):
+                patchfile = os.path.join(home, patch)
+                for suffix, type in (('', 0), ('.bz2', 1), ('.gz', 2)):
+                    if os.path.exists(patchfile + suffix):
+                        patchinfo = patchfile + suffix, type
+                        break
+                else:
+                    raise RuntimeError, "Can't find patch %s for series %s" % (patchfile, name)
+            elif operation in ('X',):
+                backup = patch + ".bak"
+                if not os.path.exists(patch) and not os.path.exists(backup):
+                    raise RuntimeError, "Can't find neither original nor backup file %s for series %s" % (patch, name)
+                patchinfo = patch, backup
+            else:
+                raise RuntimeError, 'Undefined operation "%s" in series %s' % (operation, name)
+
+            self.append((operation, patch, patchinfo))
+
+    def __repr__(self):
+        return '<%s object for %s>' % (self.__class__.__name__, self.name)
+
+    def apply(self):
+        for operation, patch, patchinfo in self:
+            if operation == '+':
+                self.patch_apply(patch, patchinfo)
+            elif operation == '-':
+                self.patch_deapply(patch, patchinf)
+            elif operation == 'X':
+                os.rename(patchinfo[0], patchinfo[1])
+                print """\
+  (X) REMOVED   %s\
+""" % patch
+        print "--> %s fully applied." % self.name
+
+    def deapply(self):
+        for operation, patch, patchinfo in self[::-1]:
+            if operation == '+':
+                self.patch_deapply(patch, patchinfo)
+            elif operation == '-':
+                self.patch_apply(patch, patchinfo)
+            elif operation == 'X':
+                os.rename(patchinfo[1], patchinfo[0])
+                print """\
+  (X) RESTORED  %s\
+""" % patch
+        print "--> %s fully unapplied." % self.name
+
+    def patch_apply(self, patch, patchinfo):
+        ret = self.patch_call(patchinfo, '--fuzz=1')
+        if ret == 0:
+            print """\
+  (+) OK        %s\
+""" % patch
+        else:
+            print """\
+  (+) FAIL      %s\
+""" % patch
+            raise SystemExit, 1
+
+    def patch_call(self, patchinfo, patchargs):
+        patchfile, type = patchinfo
+        cmdline = []
+        if type == 0:
+            cmdline.append('cat')
+        elif type == 1:
+            cmdline.append('bzcat')
+        elif type == 2:
+            cmdline.append('zcat')
+        cmdline.append(patchfile + ' | patch -p1 -f -s -t --no-backup-if-mismatch')
+        cmdline.append(patchargs)
+        return os.spawnv(os.P_WAIT, '/bin/sh', ['sh', '-c', ' '.join(cmdline)])
+
+    def patch_deapply(self, patch, patchinfo):
+        ret = self.patch_call(patchinfo, '-R')
+        if ret == 0:
+            print """\
+  (-) OK        %s\
+""" % patch
+        else:
+            print """\
+  (-) FAIL      %s\
+""" % patch
+            raise SystemExit, 1
+
+    @staticmethod
+    def read_all(s, home):
+        ret = []
+
+        for name in s:
+            filename = os.path.join(home, 'series', name)
+            if not os.path.exists(filename):
+                warn("Can't find series file for %s" % name)
+            else:
+                i = series(name, home)
+                ret.append(i)
+
+        return ret
+
 class version(object):
     __slots__ = "upstream", "revision"
 
     def __init__(self, string = None):
         if string is not None:
             t = debian_linux.parse_version(string)
-            self.upstream = t['upstream']
+            self.upstream = t['source_upstream']
             self.revision = t['debian']
 
     def __str__(self):
@@ -30,30 +146,27 @@
         return
 
     home = options.home
-    revisions = [None] + options.revisions.split()
+    revisions = ['0'] + options.revisions.split()
     source = version(options.source)
     if len(args) == 1:
         target = version(args[0])
-        if target.revision == '0':
-            target.revision = None
     else:
         target = source
 
-    if os.path.exists(version_file):
+    if options.current is not None:
+        current = version(options.current)
+    elif os.path.exists(version_file):
         version_string = file(version_file).readline().strip()
         try:
             current = version(version_string)
         except ValueError:
-            raise RuntimeError, "Can't read version in %s" % version_file
+            raise RuntimeError, 'Can\'t read version in %s: "%s"' % (version_file, version_string)
     else:
         warn('No %s file, assuming pristine Linux %s' % (version_file, source.upstream))
         current = version()
         current.upstream = source.upstream
         current.revision = None
 
-    print revisions
-    print source, target, current
-
     if current.revision not in revisions:
         raise RuntimeError, "Current revision is not in our list of revisions"
     if target.revision not in revisions:
@@ -66,12 +179,20 @@
     current_index = revisions.index(current.revision)
     target_index = revisions.index(target.revision)
 
-    print current_index, target_index
-
     if current_index < target_index:
-        print revisions[current_index + 1:target_index + 1]
+        consider = revisions[current_index + 1:target_index + 1]
+        s = series.read_all(consider, home)
+        file(version_file, 'w').write('unstable\n')
+        for i in s:
+            i.apply()
+        file(version_file, 'w').write('%s\n' % target)
     elif current_index > target_index:
-        print revisions[current_index + 1:target_index:-1]
+        consider = revisions[current_index + 1:target_index:-1]
+        s = series.read_all(consider, home)
+        file(version_file, 'w').write('unstable\n')
+        for i in s:
+            i.deapply()
+        file(version_file, 'w').write('%s\n' % target)
 
 def parse_options():
     from optparse import OptionParser
@@ -94,6 +215,11 @@
         help = "subarch",
     )
     parser.add_option(
+        '-C', '--overwrite-current',
+        dest = 'current',
+        help = "overwrite current",
+    )
+    parser.add_option(
         '-H', '--overwrite-home',
         default = _default_home, dest = 'home',
         help = "overwrite home [default: %default]",

Modified: people/waldi/linux-2.6/debian/rules.real
==============================================================================
--- people/waldi/linux-2.6/debian/rules.real	(original)
+++ people/waldi/linux-2.6/debian/rules.real	Mon Jan  2 22:40:11 2006
@@ -9,6 +9,9 @@
 DEB_HOST_ARCH     := $(shell dpkg-architecture -a'$(ARCH)' -qDEB_HOST_ARCH)
 DEB_HOST_GNU_TYPE := $(shell dpkg-architecture -a'$(ARCH)' -qDEB_HOST_GNU_TYPE)
 DEB_BUILD_ARCH    := $(shell dpkg-architecture -a'$(ARCH)' -qDEB_BUILD_ARCH)
+
+export PYTHONPATH = $(CURDIR)/debian/lib/python
+
 #
 # Build the list of common config files to be included
 #
@@ -98,11 +101,11 @@
 
 srcfiles := $(filter-out debian, $(wildcard *))
 $(STAMPS_DIR)/source: DIR=$(BUILD_DIR)/source
-$(STAMPS_DIR)/source: debian/bin/apply
+$(STAMPS_DIR)/source: debian/bin/apply.py
 	rm -rf '$(DIR)'
 	mkdir -p '$(DIR)'
 	cp -al $(srcfiles) '$(DIR)'
-	cd '$(DIR)'; override_version='$(SOURCE_VERSION)' override_revisions='$(REVISIONS)' home='$(CURDIR)/debian/patches-debian' sh '$(CURDIR)/debian/bin/apply'
+	cd '$(DIR)'; python2.4 '$(CURDIR)/debian/bin/apply.py'  --overwrite-home='$(CURDIR)/debian/patches-debian' --overwrite-source='$(SOURCE_VERSION)' --overwrite-revisions='$(REVISIONS)'
 	#make-kpkg does this when building kernel-source.
 	mv '$(DIR)/scripts/package/Makefile' '$(DIR)/scripts/package/Makefile.dist'
 	mv '$(DIR)/scripts/package/builddeb' '$(DIR)/scripts/package/builddeb.dist'



More information about the Kernel-svn-changes mailing list