Files
linux/debian/lib/python/debian_linux/config.py
Bastian Blank b37871ac10 * Set compiler build dependencies from config informations.
* Install debian/lib into headers-all package.
* Unlink version file before writing to them.
* debian/README: Remove outdated information.

r5275:  waldi | 2006-01-05 14:00:15 +0100
* debian/lib/python/debian_linux/debian.py: Move package class from utils.
* debian/lib/python/debian_linux/utils.py: Use package class from debian.

r5277:  waldi | 2006-01-05 14:41:45 +0100
* debian/lib/python/debian_linux/debian.py
  - Add package_relation, package_relation_list and package_relation_group
    classes.
  - Use them in the package class.
* debian/lib/python/debian_linux/gencontrol.py
  - Support new relation classes.

r5278:  waldi | 2006-01-05 14:46:55 +0100
debian/bin/gencontrol.py: Use relation objects for tree entry.

r5279:  waldi | 2006-01-05 15:20:00 +0100
* debian/bin/gencontrol.py: Don't fail if some relation fields are empty.
* debian/lib/python/debian_linux/debian.py: Merge relation entries.

r5280:  waldi | 2006-01-05 15:24:08 +0100
* debian/arch/defines, debian/arch/hppa/defines: Set relations for compiler.
* debian/lib/python/debian_linux/gencontrol.py: Set compiler build dependencies
  from config informations.
* debian/templates/control.source.in: Remove compiler from Build-Depends.

r5281:  waldi | 2006-01-05 15:39:45 +0100
* debian/rules.real
  - Install debian/lib into headers-all package.
  - Call dh_python with python version 2.4.
* debian/templates/control.source.in:
  Add python to build-depends, needed by dh_python.

r5282:  waldi | 2006-01-05 16:36:33 +0100
debian/rules.real
- Remove outdated comment about include_common_config.
- Remove support for headers_dirs.

r5283:  waldi | 2006-01-05 16:38:05 +0100
debian/arch/amd64/Makefile.inc, debian/arch/arm/Makefile.inc,
debian/arch/hppa/Makefile.inc, debian/arch/powerpc/Makefile.inc,
debian/arch/sparc/Makefile.inc: Remove not longer supported variables.

r5284:  waldi | 2006-01-05 16:42:33 +0100
debian/lib/python/debian_linux/gencontrol.py:
Warn if the class setting is not available.

r5287:  waldi | 2006-01-05 19:07:05 +0100
debian/arch/powerpc/defines: Set kernel-arch for all except powerpc64 to ppc.

r5288:  waldi | 2006-01-05 19:08:35 +0100
debian/lib/python/debian_linux/config.py:
Only bail out if a section is not found in any config file.

r5294:  waldi | 2006-01-05 19:26:57 +0100
debian/lib/python/debian_linux/gencontrol.py
- Support config underlay.
- Add some small default implementations.

r5295:  waldi | 2006-01-05 19:39:55 +0100
debian/README: Remove outdated information.

r5325:  waldi | 2006-01-06 22:40:17 +0100
debian/bin/apply.py
- Don't reference the debian_linux module, it is not available.
- Unlink version file before writing to them.

svn path=/dists/trunk/linux-2.6/; revision=5327
2006-01-06 22:32:16 +00:00

223 lines
6.7 KiB
Python

import os, os.path, re, sys, textwrap, ConfigParser
__all__ = 'config_reader',
_marker = object()
class config_reader(dict):
"""
Read configs in debian/arch and in the underlay directory.
"""
class schema_item_boolean(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 schema_item_list(object):
def __init__(self, type = "\s+"):
self.type = type
def __call__(self, i):
return [j.strip() for j in re.split(self.type, i.strip())]
schema = {
'arches': schema_item_list(),
'available': schema_item_boolean(),
'flavours': schema_item_list(),
'subarches': schema_item_list(),
}
config_name = "defines"
def __init__(self, underlay = None):
self._underlay = underlay
self._read_base()
def __getitem__(self, key):
return self.get(key)
def _get_files(self, name):
ret = []
if self._underlay is not None:
ret.append(os.path.join(self._underlay, name))
ret.append(os.path.join('debian/arch', name))
return ret
def _read_arch(self, arch):
files = self._get_files("%s/%s" % (arch, self.config_name))
config = config_parser(self.schema, files)
subarches = config['base',].get('subarches', [])
flavours = config['base',].get('flavours', [])
for section in iter(config):
real = list(section)
if real[-1] in subarches:
real[0:0] = ['base', arch]
elif real[-1] in flavours:
real[0:0] = ['base', arch, 'none']
else:
real[0:] = [real.pop(), arch]
real = tuple(real)
s = self.get(real, {})
s.update(config[section])
self[tuple(real)] = s
for subarch in subarches:
if self.has_key(('base', arch, subarch)):
avail = self['base', arch, subarch].get('available', True)
else:
avail = True
if avail:
self._read_subarch(arch, subarch)
if flavours:
base = self['base', arch]
subarches.insert(0, 'none')
base['subarches'] = subarches
del base['flavours']
self['base', arch] = base
self['base', arch, 'none'] = {'flavours': flavours}
for flavour in flavours:
self._read_flavour(arch, 'none', flavour)
def _read_base(self):
files = self._get_files(self.config_name)
config = config_parser(self.schema, files)
arches = config['base',]['arches']
for section in iter(config):
real = list(section)
if real[-1] in arches:
real.insert(0, 'base')
else:
real.insert(0, real.pop())
self[tuple(real)] = config[section]
for arch in arches:
try:
avail = self['base', arch].get('available', True)
except KeyError:
avail = True
if avail:
self._read_arch(arch)
def _read_flavour(self, arch, subarch, flavour):
if not self.has_key(('base', arch, subarch, flavour)):
import warnings
warnings.warn('No config entry for flavour %s, subarch %s, arch %s' % (flavour, subarch, arch), DeprecationWarning)
self['base', arch, subarch, flavour] = {}
def _read_subarch(self, arch, subarch):
files = self._get_files("%s/%s/%s" % (arch, subarch, self.config_name))
config = config_parser(self.schema, files)
flavours = config['base',].get('flavours', [])
for section in iter(config):
real = list(section)
if real[-1] in flavours:
real[0:0] = ['base', arch, subarch]
else:
real[0:] = [real.pop(), arch, subarch]
real = tuple(real)
s = self.get(real, {})
s.update(config[section])
self[tuple(real)] = s
for flavour in flavours:
self._read_flavour(arch, subarch, flavour)
def _update(self, ret, inputkey):
for key, value in super(config_reader, self).get(tuple(inputkey), {}).iteritems():
ret[key] = value
def get(self, key, default = _marker):
if isinstance(key, basestring):
key = key,
ret = super(config_reader, self).get(tuple(key), default)
if ret == _marker:
raise KeyError, key
return ret
def merge(self, section, *args):
ret = {}
for i in xrange(0, len(args) + 1):
ret.update(self.get(tuple([section] + list(args[:i])), {}))
if section == 'base':
for i in ('abiname', 'arches', 'flavours', 'subarches'):
try:
del ret[i]
except KeyError: pass
return ret
def sections(self):
return super(config_reader, self).keys()
class config_parser(object):
__slots__ = 'configs', 'schema'
def __init__(self, schema, files):
self.configs = []
self.schema = schema
for file in files:
config = ConfigParser.ConfigParser()
config.read(file)
self.configs.append(config)
def __getitem__(self, key):
return self.items(key)
def __iter__(self):
return iter(self.sections())
def items(self, section, var = {}):
ret = {}
section = '_'.join(section)
exceptions = []
for config in self.configs:
try:
items = config.items(section)
except ConfigParser.NoSectionError, e:
exceptions.append(e)
else:
for key, value in items:
try:
value = self.schema[key](value)
except KeyError: pass
ret[key] = value
if len(exceptions) == len(self.configs):
raise exceptions[0]
return ret
def sections(self):
sections = []
for config in self.configs:
for section in config.sections():
section = tuple(section.split('_'))
if section not in sections:
sections.append(section)
return sections
if __name__ == '__main__':
import sys
config = config_reader()
sections = config.sections()
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