[kernel] r5192 - people/waldi/linux-2.6/debian/bin

Bastian Blank waldi at costa.debian.org
Tue Jan 3 14:32:44 UTC 2006


Author: waldi
Date: Tue Jan  3 14:32:43 2006
New Revision: 5192

Modified:
   people/waldi/linux-2.6/debian/bin/apply.py
Log:
debian/bin/apply.py
- Add version_file class.
- Use correct series for deapply.


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	Tue Jan  3 14:32:43 2006
@@ -8,8 +8,6 @@
 _default_revisions = "@revisions@"
 _default_source = "@source@"
 
-version_file = 'version.Debian'
-
 class series(list):
     def __init__(self, name, home):
         self.name = name
@@ -58,7 +56,9 @@
     def __repr__(self):
         return '<%s object for %s>' % (self.__class__.__name__, self.name)
 
-    def _check_add(self, add, options):
+    def _check_extra(self, add, options):
+        if not add:
+            return True
         i = []
         if options.arch is not None:
             i.append(options.arch)
@@ -69,8 +69,8 @@
         return False
 
     def apply(self, options):
-        for operation, patch, patchinfo, add in self:
-            if add and not self._check_add(add, options):
+        for operation, patch, patchinfo, extra in self:
+            if not self._check_extra(extra, options):
                 print """\
   (.) IGNORED   %s\
 """ % patch
@@ -87,8 +87,8 @@
         print "--> %s fully applied." % self.name
 
     def deapply(self, options):
-        for operation, patch, patchinfo in self[::-1]:
-            if add and not self._check_add(add, options):
+        for operation, patch, patchinfo, extra in self[::-1]:
+            if not self._check_extra(extra, options):
                 print """\
   (.) IGNORED   %s\
 """ % patch
@@ -167,6 +167,54 @@
     def __str__(self):
         return "%s-%s" % (self.upstream, self.revision)
 
+class version_file(object):
+    _file = 'version.Debian'
+    extra = []
+    in_progress = False
+
+    def __init__(self, ver = None, overwrite = False):
+        if overwrite:
+            self._read(ver)
+        elif os.path.exists(self._file):
+            s = file(self._file).readline().strip()
+            self._read(s)
+        elif ver:
+            warn('No %s file, assuming pristine Linux %s' % (self._file, ver.upstream))
+            self.version = version()
+            self.version.upstream = ver.upstream
+            self.version.revision = '0'
+        else:
+            raise RuntimeError, "Not possible to determine version"
+
+    def __str__(self):
+        if self.in_progress:
+            return "unstable"
+        if self.extra:
+            return "%s %s" % (self.version, '_'.join(self.extra))
+        return str(self.version)
+
+    def _read(self, s):
+        list = s.split(' ')
+        if len(list) > 2:
+            raise RuntimeError, "Can't parse %s" % self._file
+        try:
+            self.version = version(list[0])
+        except ValueError:
+            raise RuntimeError, 'Can\'t read version in %s: "%s"' % (self._file, list[0])
+        if len(list) == 2:
+            self.extra = list[1].split('_')
+
+    def _write(self):
+        file(self._file, 'w').write('%s\n' % self)
+
+    def begin(self):
+        self.in_progress = True
+        self._write()
+
+    def commit(self):
+        self.in_progress = False
+        self._write()
+
 def main():
     options, args = parse_options()
 
@@ -183,18 +231,10 @@
         target = source
 
     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: "%s"' % (version_file, version_string)
+        vfile = version_file(options.current, True)
     else:
-        warn('No %s file, assuming pristine Linux %s' % (version_file, source.upstream))
-        current = version()
-        current.upstream = source.upstream
-        current.revision = '0'
+        vfile = version_file(source)
+    current = vfile.version
 
     if current.revision not in revisions:
         raise RuntimeError, "Current revision is not in our list of revisions"
@@ -211,17 +251,19 @@
     if current_index < target_index:
         consider = revisions[current_index + 1:target_index + 1]
         s = series.read_all(consider, home)
-        file(version_file, 'w').write('unstable\n')
+        vfile.begin()
         for i in s:
             i.apply(options)
-        file(version_file, 'w').write('%s\n' % target)
+        vfile.version = target
+        vfile.commit()
     elif current_index > target_index:
-        consider = revisions[current_index + 1:target_index:-1]
+        consider = revisions[current_index:target_index:-1]
         s = series.read_all(consider, home)
-        file(version_file, 'w').write('unstable\n')
+        vfile.begin()
         for i in s:
             i.deapply(options)
-        file(version_file, 'w').write('%s\n' % target)
+        vfile.version = target
+        vfile.commit()
 
 def parse_options():
     from optparse import OptionParser



More information about the Kernel-svn-changes mailing list