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

Bastian Blank waldi at costa.debian.org
Mon Jan 2 21:31:32 UTC 2006


Author: waldi
Date: Mon Jan  2 21:31:28 2006
New Revision: 5177

Added:
   people/waldi/linux-2.6/debian/bin/apply.py   (contents, props changed)
Log:
First prototype of improved patch util.

debian/bin/apply.py: Add.


Added: people/waldi/linux-2.6/debian/bin/apply.py
==============================================================================
--- (empty file)
+++ people/waldi/linux-2.6/debian/bin/apply.py	Mon Jan  2 21:31:28 2006
@@ -0,0 +1,130 @@
+#!/usr/bin/env python2.4
+
+import os.path, sys
+from warnings import warn
+import debian_linux
+
+_default_home = ""
+_default_revisions = "@revisions@"
+_default_source = "@source@"
+
+version_file = 'version.Debian'
+
+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.revision = t['debian']
+
+    def __str__(self):
+        return "%s-%s" % (self.upstream, self.revision)
+
+def main():
+    options, args = parse_options()
+
+    if len(args) > 1:
+        print "Too much arguments"
+        return
+
+    home = options.home
+    revisions = [None] + 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):
+        version_string = file(version_file).readline().strip()
+        try:
+            current = version(version_string)
+        except ValueError:
+            raise RuntimeError, "Can't read version in %s" % version_file
+    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:
+        raise RuntimeError, "Target revision is not in our list of revisions"
+
+    if current.revision == target.revision:
+        print "Nothing to do"
+        return
+
+    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]
+    elif current_index > target_index:
+        print revisions[current_index + 1:target_index:-1]
+
+def parse_options():
+    from optparse import OptionParser
+    parser = OptionParser(
+        usage = "%prog [OPTION]... [TARGET]",
+    )
+    parser.add_option(
+        '-a', '--arch',
+        dest = 'arch',
+        help = "arch",
+    )
+    parser.add_option(
+        '-f', '--flavour',
+        dest = 'flavour',
+        help = "flavour",
+    )
+    parser.add_option(
+        '-s', '--subarch',
+        dest = 'subarch',
+        help = "subarch",
+    )
+    parser.add_option(
+        '-H', '--overwrite-home',
+        default = _default_home, dest = 'home',
+        help = "overwrite home [default: %default]",
+    )
+    parser.add_option(
+        '-R', '--overwrite-revisions',
+        default = _default_revisions, dest = 'revisions',
+        help = "overwrite revisions [default: %default]",
+    )
+    parser.add_option(
+        '-S', '--overwrite-source',
+        default = _default_source, dest = 'source',
+        help = "overwrite source [default: %default]",
+    )
+
+    options, args = parser.parse_args()
+
+    if options.arch is None and options.subarch is not None:
+        warn('You specified a subarch without an arch, this is not really working')
+    if options.subarch is None and options.flavour is not None:
+        warn('You specified a flavour without a subarch, this is not really working')
+
+    return options, args
+
+if __name__ == '__main__':
+    def showwarning(message, category, filename, lineno):
+        sys.stderr.write("Warning: %s\n" % message)
+    import warnings
+    warnings.showwarning = showwarning
+    try:
+        main()
+    except RuntimeError, e:
+        sys.stderr.write("Error: %s\n" % e)
+



More information about the Kernel-svn-changes mailing list