diff --git a/debian/bin/gencontrol.py b/debian/bin/gencontrol.py
index ecd28b2bd..2fdcdfd93 100755
--- a/debian/bin/gencontrol.py
+++ b/debian/bin/gencontrol.py
@@ -1,29 +1,22 @@
#!/usr/bin/env python2.4
+
import sys
sys.path.append("debian/lib/python")
-import warnings
+
from debian_linux.debian import *
+from debian_linux.gencontrol import PackagesList, Makefile, MakeFlags
from debian_linux.utils import *
-class packages_list(sorted_dict):
- def append(self, package):
- self[package['Package']] = package
-
- def extend(self, packages):
- for package in packages:
- self[package['Package']] = package
-
class gencontrol(object):
makefile_targets = ('binary-arch', 'build')
def __init__(self, underlay = None):
- self.changelog = read_changelog()
- self.templates = templates()
- self.version, self.changelog_vars = self.process_changelog({})
+ self.templates = Templates(['debian/templates'])
+ self.process_changelog()
def __call__(self):
- packages = packages_list()
- makefile = []
+ packages = PackagesList()
+ makefile = Makefile()
self.do_source(packages)
self.do_main(packages, makefile)
@@ -33,61 +26,47 @@ class gencontrol(object):
def do_source(self, packages):
source = self.templates["control.source"]
- packages['source'] = self.process_package(source[0], self.changelog_vars)
+ packages['source'] = self.process_package(source[0], self.vars)
def do_main(self, packages, makefile):
- makeflags = {
- 'VERSION': self.version['linux']['version'],
- 'SOURCE_UPSTREAM': self.version['upstream'],
- 'SOURCEVERSION': self.version['linux']['source'],
- 'UPSTREAMVERSION': self.version['linux']['upstream'],
- }
-
- vars = self.changelog_vars.copy()
+ vars = self.vars.copy()
+ makeflags = MakeFlags()
self.do_main_setup(vars, makeflags)
self.do_main_packages(packages)
self.do_main_makefile(makefile, makeflags)
def do_main_setup(self, vars, makeflags):
- pass
+ makeflags.update({
+ 'MAJOR': self.version.linux_major,
+ 'VERSION': self.version.linux_version,
+ 'UPSTREAMVERSION': self.version.linux_upstream,
+ })
def do_main_makefile(self, makefile, makeflags):
- makeflags_string = ' '.join(["%s='%s'" % i for i in makeflags.iteritems()])
-
for i in self.makefile_targets:
- makefile.append(("%s:" % i, ("$(MAKE) -f debian/rules.real %s %s" % (i, makeflags_string))))
+ makefile.add(i, cmds = ["$(MAKE) -f debian/rules.real %s %s" % (i, makeflags)])
def do_main_packages(self, packages):
- vars = self.changelog_vars
-
main = self.templates["control.main"]
- packages.extend(self.process_packages(main, vars))
+ packages.extend(self.process_packages(main, self.vars))
- def process_changelog(self, in_vars):
- ret = [None, None]
- ret[0] = version = self.changelog[0]['Version']
- vars = in_vars.copy()
- vars['upstreamversion'] = version['linux']['upstream']
- vars['version'] = version['linux']['version']
- vars['source_upstream'] = version['upstream']
- vars['major'] = version['linux']['major']
- ret[1] = vars
- return ret
+ def process_changelog(self):
+ changelog = Changelog(version = VersionLinux)
+ self.version = version = changelog[0].version
+ self.vars = {
+ 'upstreamversion': version.linux_upstream,
+ 'version': version.linux_version,
+ 'source_upstream': version.upstream,
+ 'major': version.linux_major,
+ }
def process_relation(self, key, e, in_e, vars):
- in_dep = in_e[key]
- dep = package_relation_list()
- for in_groups in in_dep:
- groups = package_relation_group()
- for in_item in in_groups:
- item = package_relation()
- item.name = self.substitute(in_item.name, vars)
- if in_item.version is not None:
- item.version = self.substitute(in_item.version, vars)
- item.arches = in_item.arches
- groups.append(item)
- dep.append(groups)
+ import copy
+ dep = copy.deepcopy(in_e[key])
+ for groups in dep:
+ for item in groups:
+ item.name = self.substitute(item.name, vars)
e[key] = dep
def process_description(self, e, in_e, vars):
@@ -95,13 +74,13 @@ class gencontrol(object):
desc = in_desc.__class__()
desc.short = self.substitute(in_desc.short, vars)
for i in in_desc.long:
- desc.long.append(self.substitute(i, vars))
+ desc.append(self.substitute(i, vars))
e['Description'] = desc
def process_package(self, in_entry, vars):
- e = package()
+ e = Package()
for key, value in in_entry.iteritems():
- if isinstance(value, package_relation_list):
+ if isinstance(value, PackageRelation):
self.process_relation(key, e, in_entry, vars)
elif key == 'Description':
self.process_description(e, in_entry, vars)
@@ -129,18 +108,10 @@ class gencontrol(object):
def write_control(self, list):
self.write_rfc822(file("debian/control", 'w'), list)
- def write_makefile(self, out_list):
- out = file("debian/rules.gen", 'w')
- for item in out_list:
- if isinstance(item, (list, tuple)):
- out.write("%s\n" % item[0])
- cmd_list = item[1]
- if isinstance(cmd_list, basestring):
- cmd_list = cmd_list.split('\n')
- for j in cmd_list:
- out.write("\t%s\n" % j)
- else:
- out.write("%s\n" % item)
+ def write_makefile(self, makefile):
+ f = file("debian/rules.gen", 'w')
+ makefile.write(f)
+ f.close()
def write_rfc822(self, f, list):
for entry in list:
@@ -148,6 +119,5 @@ class gencontrol(object):
f.write("%s: %s\n" % (key, value))
f.write('\n')
-
if __name__ == '__main__':
gencontrol()()
diff --git a/debian/bin/genorig.py b/debian/bin/genorig.py
index 6a24304c5..637ecaff1 100755
--- a/debian/bin/genorig.py
+++ b/debian/bin/genorig.py
@@ -4,34 +4,39 @@ import sys
sys.path.append("debian/lib/python")
import os, os.path, re, shutil
-from debian_linux.debian import read_changelog
+from debian_linux.debian import Changelog, VersionLinux
-class main(object):
- def __init__(self, input_tar, input_patch = None):
+class Main(object):
+ def __init__(self, input_tar, input_patch, override_version):
self.log = sys.stdout.write
self.input_tar = input_tar
self.input_patch = input_patch
- changelog = read_changelog()[0]
- source = changelog['Source']
- version = changelog['Version']['linux']['source_upstream']
- self.orig = '%s-%s' % (source, version)
- self.orig_tar = '%s_%s.orig.tar.gz' % (source, version)
+ changelog = Changelog(version = VersionLinux)[0]
+ source = changelog.source
+ version = changelog.version
+
+ if override_version:
+ version = VersionLinux('%s-undef' % override_version)
+
+ self.log('Using source name %s, version %s\n' % (source, version.upstream))
+
+ self.orig = '%s-%s' % (source, version.upstream)
+ self.orig_tar = '%s_%s.orig.tar.gz' % (source, version.upstream)
def __call__(self):
import tempfile
self.dir = tempfile.mkdtemp(prefix = 'genorig', dir = 'debian')
try:
- self.extract()
- self.patch()
+ self.upstream_extract()
+ self.upstream_patch()
self.generate()
self.tar()
finally:
- pass
shutil.rmtree(self.dir)
- def extract(self):
+ def upstream_extract(self):
self.log("Extracting tarball %s\n" % self.input_tar)
match = re.match(r'(^|.*/)(?P
linux-\d+\.\d+\.\d+(-\S+)?)\.tar(\.(?P(bz2|gz)))?$', self.input_tar)
if not match:
@@ -45,11 +50,11 @@ class main(object):
raise RuntimeError("Can't extract tarball")
os.rename(os.path.join(self.dir, match.group('dir')), os.path.join(self.dir, 'temp'))
- def patch(self):
+ def upstream_patch(self):
if self.input_patch is None:
return
self.log("Patching source with %s\n" % self.input_patch)
- match = re.match(r'(^|.*/)(patch-\d+\.\d+\.\d+(-\S+)?(\.(?P(bz2|gz))))?$', self.input_patch)
+ match = re.match(r'(^|.*/)patch-\d+\.\d+\.\d+(-\S+?)?(\.(?P(bz2|gz)))?$', self.input_patch)
if not match:
raise RuntimeError("Can't identify name of patch")
cmdline = []
@@ -68,9 +73,7 @@ class main(object):
self.log("Generate orig\n")
orig = os.path.join(self.dir, self.orig)
temp = os.path.join(self.dir, 'temp')
- os.mkdir(orig)
- os.mkdir(os.path.join(orig, 'include'))
- os.mkdir(os.path.join(orig, 'include', 'linux'))
+ os.makedirs(os.path.join(orig, 'include', 'linux'))
shutil.copyfile(os.path.join(temp, 'COPYING'), os.path.join(orig, 'COPYING'))
for i in ('input.h', 'license.h', 'mod_devicetable.h'):
shutil.copyfile(os.path.join(temp, 'include', 'linux', i), os.path.join(orig, 'include', 'linux', i))
@@ -78,10 +81,35 @@ class main(object):
def tar(self):
out = os.path.join("../orig", self.orig_tar)
+ try:
+ os.mkdir("../orig")
+ except OSError: pass
+ try:
+ os.stat(out)
+ raise RuntimeError("Destination already exists")
+ except OSError: pass
self.log("Generate tarball %s\n" % out)
cmdline = ['tar -czf', out, '-C', self.dir, self.orig]
- if os.spawnv(os.P_WAIT, '/bin/sh', ['sh', '-c', ' '.join(cmdline)]):
- raise RuntimeError("Can't patch source")
+ try:
+ if os.spawnv(os.P_WAIT, '/bin/sh', ['sh', '-c', ' '.join(cmdline)]):
+ raise RuntimeError("Can't patch source")
+ os.chmod(out, 0644)
+ except:
+ try:
+ os.unlink(out)
+ except OSError:
+ pass
+ raise
if __name__ == '__main__':
- main(*sys.argv[1:])()
+ from optparse import OptionParser
+ parser = OptionParser(usage = "%prog [OPTION]... TAR [PATCH]")
+ parser.add_option("-V", "--override-version", dest = "override_version", help = "Override version", metavar = "VERSION")
+ options, args = parser.parse_args()
+
+ input_tar = args[0]
+ input_patch = None
+ if len(args) > 1:
+ input_patch = args[1]
+
+ Main(input_tar, input_patch, options.override_version)()
diff --git a/debian/changelog b/debian/changelog
index 8d4970214..ca5a48096 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,8 +1,8 @@
-linux-kbuild-2.6 (2.6.23~rc4-1) UNRELEASED; urgency=low
+linux-kbuild-2.6 (2.6.23-1) UNRELEASED; urgency=low
* New upstream version.
- -- Bastian Blank Thu, 30 Aug 2007 21:15:03 +0200
+ -- Bastian Blank Sun, 14 Oct 2007 11:28:39 +0200
linux-kbuild-2.6 (2.6.22-1) unstable; urgency=low
diff --git a/debian/lib/python/debian_linux/__init__.py b/debian/lib/python/debian_linux/__init__.py
index b989d7d15..e69de29bb 100644
--- a/debian/lib/python/debian_linux/__init__.py
+++ b/debian/lib/python/debian_linux/__init__.py
@@ -1,3 +0,0 @@
-from debian import *
-from utils import *
-
diff --git a/debian/lib/python/debian_linux/config.py b/debian/lib/python/debian_linux/config.py
new file mode 100644
index 000000000..7e3e12ae8
--- /dev/null
+++ b/debian/lib/python/debian_linux/config.py
@@ -0,0 +1,209 @@
+import os, os.path, re, sys, textwrap
+
+__all__ = [
+ 'ConfigParser',
+ 'ConfigReaderCore',
+]
+
+class SchemaItemBoolean(object):
+ def __call__(self, i):
+ i = i.strip().lower()
+ if i in ("true", "1"):
+ return True
+ if i in ("false", "0"):
+ return False
+ raise Error
+
+class SchemaItemList(object):
+ def __init__(self, type = "\s+"):
+ self.type = type
+
+ def __call__(self, i):
+ i = i.strip()
+ if not i:
+ return []
+ return [j.strip() for j in re.split(self.type, i)]
+
+class ConfigReaderCore(dict):
+ config_name = "defines"
+
+ schemas = {
+ 'base': {
+ 'arches': SchemaItemList(),
+ 'enabled': SchemaItemBoolean(),
+ 'featuresets': SchemaItemList(),
+ 'flavours': SchemaItemList(),
+ 'modules': SchemaItemBoolean(),
+ },
+ 'image': {
+ 'configs': SchemaItemList(),
+ 'initramfs': SchemaItemBoolean(),
+ 'initramfs-generators': SchemaItemList(),
+ },
+ 'relations': {
+ },
+ 'xen': {
+ 'dom0-support': SchemaItemBoolean(),
+ 'versions': SchemaItemList(),
+ }
+ }
+
+ def __init__(self, dirs = []):
+ self._dirs = dirs
+ self._read_base()
+
+ def _read_arch(self, arch):
+ config = ConfigParser(self.schemas)
+ config.read(self.get_files("%s/%s" % (arch, self.config_name)))
+
+ featuresets = config['base',].get('featuresets', [])
+ flavours = config['base',].get('flavours', [])
+
+ for section in iter(config):
+ if section[0] in featuresets:
+ real = (section[-1], arch, section[0])
+ elif len(section) > 1:
+ real = (section[-1], arch, None) + section[:-1]
+ else:
+ real = (section[-1], arch) + section[:-1]
+ s = self.get(real, {})
+ s.update(config[section])
+ self[tuple(real)] = s
+
+ for featureset in featuresets:
+ self._read_arch_featureset(arch, featureset)
+
+ if flavours:
+ base = self['base', arch]
+ featuresets.insert(0, 'none')
+ base['featuresets'] = featuresets
+ del base['flavours']
+ self['base', arch] = base
+ self['base', arch, 'none'] = {'flavours': flavours, 'implicit-flavour': True}
+
+ def _read_arch_featureset(self, arch, featureset):
+ config = ConfigParser(self.schemas)
+ config.read(self.get_files("%s/%s/%s" % (arch, featureset, self.config_name)))
+
+ flavours = config['base',].get('flavours', [])
+
+ for section in iter(config):
+ real = (section[-1], arch, featureset) + section[:-1]
+ s = self.get(real, {})
+ s.update(config[section])
+ self[tuple(real)] = s
+
+ def _read_base(self):
+ config = ConfigParser(self.schemas)
+ config.read(self.get_files(self.config_name))
+
+ arches = config['base',]['arches']
+ featuresets = config['base',]['featuresets']
+
+ for section in iter(config):
+ if section[0].startswith('featureset-'):
+ real = (section[-1], None, section[0].lstrip('featureset-'))
+ else:
+ real = (section[-1],) + section[1:]
+ self[real] = config[section]
+
+ for arch in arches:
+ self._read_arch(arch)
+ for featureset in featuresets:
+ self._read_featureset(featureset)
+
+ def _read_featureset(self, featureset):
+ config = ConfigParser(self.schemas)
+ config.read(self.get_files("featureset-%s/%s" % (featureset, self.config_name)))
+
+ for section in iter(config):
+ real = (section[-1], None, featureset)
+ s = self.get(real, {})
+ s.update(config[section])
+ self[real] = s
+
+ def get_files(self, name):
+ return [os.path.join(i, name) for i in self._dirs if i]
+
+ def merge(self, section, arch = None, featureset = None, flavour = None):
+ ret = {}
+ ret.update(self.get((section,), {}))
+ if featureset:
+ ret.update(self.get((section, None, featureset), {}))
+ if arch:
+ ret.update(self.get((section, arch), {}))
+ if arch and featureset:
+ ret.update(self.get((section, arch, featureset), {}))
+ if arch and featureset and flavour:
+ ret.update(self.get((section, arch, None, flavour), {}))
+ ret.update(self.get((section, arch, featureset, flavour), {}))
+ return ret
+
+class ConfigParser(object):
+ __slots__ = '_config', 'schemas'
+
+ def __init__(self, schemas):
+ self.schemas = schemas
+
+ from ConfigParser import RawConfigParser
+ self._config = config = RawConfigParser()
+
+ def __getitem__(self, key):
+ return self._convert()[key]
+
+ def __iter__(self):
+ return iter(self._convert())
+
+ def __str__(self):
+ return '<%s(%s)>' % (self.__class__.__name__, self._convert())
+
+ def _convert(self):
+ ret = {}
+ for section in self._config.sections():
+ data = {}
+ for key, value in self._config.items(section):
+ data[key] = value
+ s1 = section.split('_')
+ if s1[-1] in self.schemas:
+ ret[tuple(s1)] = self.SectionSchema(data, self.schemas[s1[-1]])
+ else:
+ ret[(section,)] = self.Section(data)
+ return ret
+
+ def keys(self):
+ return self._convert().keys()
+
+ def read(self, data):
+ return self._config.read(data)
+
+ class Section(dict):
+ def __init__(self, data):
+ super(ConfigParser.Section, self).__init__(data)
+
+ def __str__(self):
+ return '<%s(%s)>' % (self.__class__.__name__, self._data)
+
+ class SectionSchema(Section):
+ __slots__ = ()
+
+ def __init__(self, data, schema):
+ for key in data.keys():
+ try:
+ data[key] = schema[key](data[key])
+ except KeyError: pass
+ super(ConfigParser.SectionSchema, self).__init__(data)
+
+if __name__ == '__main__':
+ import sys
+ config = ConfigReaderCore(['debian/config'])
+ sections = config.keys()
+ sections.sort()
+ for section in sections:
+ print "[%s]" % (section,)
+ items = config[section]
+ items_keys = items.keys()
+ items_keys.sort()
+ for item in items:
+ print "%s: %s" % (item, items[item])
+ print
+
diff --git a/debian/lib/python/debian_linux/debian.py b/debian/lib/python/debian_linux/debian.py
index 7b6e9ba10..977a0bd57 100644
--- a/debian/lib/python/debian_linux/debian.py
+++ b/debian/lib/python/debian_linux/debian.py
@@ -1,103 +1,154 @@
import itertools, os.path, re, utils
-def read_changelog(dir = ''):
- r = re.compile(r"""
-^
-(
-(?P
- (?P
- \w[-+0-9a-z.]+
- )
- \
- \(
- (?P
- [^\(\)\ \t]+
- )
- \)
- \s+
- (?P
- [-0-9a-zA-Z]+
- )
- \;
-)
-)
-""", re.VERBOSE)
- f = file(os.path.join(dir, "debian/changelog"))
- entries = []
- act_upstream = None
- while True:
- line = f.readline()
- if not line:
- break
- line = line.strip('\n')
- match = r.match(line)
- if not match:
- continue
- if match.group('header'):
- e = {}
- e['Distribution'] = match.group('header_distribution')
- e['Source'] = match.group('header_source')
- version = parse_version(match.group('header_version'))
- e['Version'] = version
- if act_upstream is None:
- act_upstream = version['upstream']
- elif version['upstream'] != act_upstream:
- break
- entries.append(e)
- return entries
-
-def parse_version(version):
- ret = {
- 'complete': version,
- 'upstream': version,
- 'debian': None,
- 'linux': None,
- }
- try:
- i = len(version) - version[::-1].index('-')
- except ValueError:
- return ret
- ret['upstream'] = version[:i-1]
- ret['debian'] = version[i:]
- try:
- ret['linux'] = parse_version_linux(version)
- except ValueError:
- pass
- return ret
-
-def parse_version_linux(version):
- version_re = ur"""
+class Changelog(list):
+ _rules = r"""
^
(?P