[kernel] r13133 - in people/waldi/utils/kconfigeditor2: bin lib/kconfigeditor lib/kconfigeditor/kconfig lib/kconfigeditor/kconfig/menu lib/kconfigeditor/kconfig/package
Bastian Blank
waldi at alioth.debian.org
Mon Mar 16 20:39:56 UTC 2009
Author: waldi
Date: Mon Mar 16 20:39:55 2009
New Revision: 13133
Log:
Split modules.
Added:
people/waldi/utils/kconfigeditor2/lib/kconfigeditor/kconfig/config.py
people/waldi/utils/kconfigeditor2/lib/kconfigeditor/package.py
Removed:
people/waldi/utils/kconfigeditor2/lib/kconfigeditor/kconfig/package/
Modified:
people/waldi/utils/kconfigeditor2/bin/process.py
people/waldi/utils/kconfigeditor2/lib/kconfigeditor/kconfig/menu/file.py
Modified: people/waldi/utils/kconfigeditor2/bin/process.py
==============================================================================
--- people/waldi/utils/kconfigeditor2/bin/process.py (original)
+++ people/waldi/utils/kconfigeditor2/bin/process.py Mon Mar 16 20:39:55 2009
@@ -4,7 +4,7 @@
def main(package, source, config_output, ignore_silent):
from kconfigeditor.kconfig.menu.all import All
- from kconfigeditor.kconfig.package.files import Files
+ from kconfigeditor.package import Files
package = Files(package)
arches = {}
Added: people/waldi/utils/kconfigeditor2/lib/kconfigeditor/kconfig/config.py
==============================================================================
--- (empty file)
+++ people/waldi/utils/kconfigeditor2/lib/kconfigeditor/kconfig/config.py Mon Mar 16 20:39:55 2009
@@ -0,0 +1,199 @@
+from __future__ import absolute_import
+
+import os
+
+from .menu.file import FileChoice, FileConfig
+
+
+class File(dict):
+ def __init__(self, fd, filename):
+ self.filename = filename
+
+ self.read(fd)
+
+ def _dump_file_choice(self, processed, ignored, have_prompt, f):
+ ret = []
+ nr = 0
+ for i in f:
+ if isinstance(i, FileConfig):
+ r = self._dump_file_config(processed, ignored, have_prompt, i)
+ if r:
+ ret.extend(r)
+ nr += 1
+ incomplete = len(f) != nr
+ if ret:
+ if incomplete:
+ ret.insert(0, "## choice: INCOMPLETE: %s" % f.prompt)
+ else:
+ ret.insert(0, "## choice: %s" % f.prompt)
+ ret.append('## end choice')
+ return ret
+
+ def _dump_file_config(self, processed, ignored, have_prompt, i):
+ e = self.get(i.name, None)
+ if e is None:
+ return []
+
+ if i.name in processed:
+ return []
+ if not i.prompt:
+ if i.name in have_prompt:
+ return []
+ if ignored is not None:
+ ignored.add(i.name)
+ return []
+ processed.add(i.name)
+ return e.dump(i)
+
+ def _dump_file(self, processed, ignored, have_prompt, f):
+ ret = []
+ for i in f:
+ if isinstance(i, FileConfig):
+ ret.extend(self._dump_file_config(processed, ignored, have_prompt, i))
+ elif isinstance(i, FileChoice):
+ ret.extend(self._dump_file_choice(processed, ignored, have_prompt, i))
+ if ret:
+ ret[0:0] = ["##", "## file: %s" % f.filename, "##"]
+ ret.append('')
+ return ret
+
+ def _dump_prompt_file_config(self, have_prompt, i):
+ e = self.get(i.name, None)
+ if e is not None:
+ if i.prompt:
+ have_prompt.add(i.name)
+
+ def _dump_prompt_file(self, have_prompt, f):
+ for i in f:
+ if isinstance(i, FileConfig):
+ self._dump_prompt_file_config(have_prompt, i)
+ elif isinstance(i, FileChoice):
+ for i1 in i:
+ if isinstance(i1, FileConfig):
+ self._dump_prompt_file_config(have_prompt, i1)
+
+ def dump(self, root, menufiles, ignore_silent = False):
+ filename = os.path.join(root, self.filename)
+ if not os.path.exists(os.path.dirname(filename)):
+ os.makedirs(os.path.dirname(filename))
+ fd = file(filename, 'w')
+
+ def menufiles_cmp_key(entry):
+ filename_list = entry.filename.split('/')
+ if filename_list[-1] == 'Kconfig':
+ filename_list.pop()
+ else:
+ filename_list[-1] = filename_list[-1].replace('Kconfig.', '')
+ return filename_list
+
+ menufiles.sort(key = menufiles_cmp_key)
+
+ have_prompt = set()
+ for f in menufiles:
+ self._dump_prompt_file(have_prompt, f)
+
+ ret = []
+ processed = set()
+ ignored_sub = ignored = set()
+ if not ignore_silent:
+ ignored_sub = None
+ for f in menufiles:
+ ret.extend(self._dump_file(processed, ignored_sub, have_prompt, f))
+
+ s = set(self.keys())
+ unprocessed = s - processed - ignored
+ if unprocessed:
+ ret.extend(["##", "## file: unknown", "##"])
+ unprocessed = list(unprocessed)
+ unprocessed.sort()
+ for i in unprocessed:
+ e = self.get(i)
+ ret.append(e)
+ ret.append('')
+
+ for i in ret:
+ fd.write(str(i) + "\n")
+
+ def read(self, f):
+ comments = []
+
+ for line in iter(f.readlines()):
+ line = line.strip()
+
+ if line.startswith("CONFIG_"):
+ i = line.find('=')
+ option = line[7:i]
+ value = line[i+1:]
+ if value in ('y', 'm', 'n'):
+ entry = FileEntryTristate(option, value, comments)
+ else:
+ entry = FileEntryString(option, value, comments)
+ self[option] = entry
+ comments = []
+
+ elif line.startswith("# CONFIG_"):
+ option = line[9:-11]
+ self[option] = FileEntryTristate(option, 'n', comments)
+ comments = []
+
+ elif line.startswith("#. "):
+ comments.append(line[3:])
+
+ elif line.startswith("#") or not line:
+ pass
+
+ else:
+ raise RuntimeError, "Can't recognize %s" % line
+
+class FileEntry(object):
+ __slots__ = "name", "comments"
+
+ def __init__(self, name, comments):
+ self.name, self.comments = name, comments
+
+ def dump(self, config):
+ ret = ["#. %s" % i for i in self.comments]
+# if config.type == FileConfig.TYPE_BOOL:
+# ret.append("# type: bool")
+# elif config.type == FileConfig.TYPE_TRISTATE:
+# ret.append("# type: tristate")
+ ret.append(str(self))
+ return ret
+
+# TODO
+class FileEntryString(FileEntry):
+ __slots__ = "value"
+
+ def __init__(self, name, value, comments):
+ super(FileEntryString, self).__init__(name, comments)
+ self.value = value
+
+ def __str__(self):
+ return "CONFIG_%s=%s" % (self.name, self.value)
+
+# TODO
+class FileEntryTristate(FileEntry):
+ __slots__ = "name", "value", "comments"
+
+ VALUE_NO = 0
+ VALUE_YES = 1
+ VALUE_MOD = 2
+
+ def __init__(self, name, value, comments):
+ super(FileEntryTristate, self).__init__(name, comments)
+ if value == 'n' or value is None:
+ self.value = self.VALUE_NO
+ elif value == 'y':
+ self.value = self.VALUE_YES
+ elif value == 'm':
+ self.value = self.VALUE_MOD
+
+ def __str__(self):
+ conf = "CONFIG_%s" % self.name
+ if self.value == self.VALUE_NO:
+ return "# %s is not set" % conf
+ elif self.value == self.VALUE_YES:
+ return "%s=y" % conf
+ elif self.value == self.VALUE_MOD:
+ return "%s=m" % conf
+
Modified: people/waldi/utils/kconfigeditor2/lib/kconfigeditor/kconfig/menu/file.py
==============================================================================
--- people/waldi/utils/kconfigeditor2/lib/kconfigeditor/kconfig/menu/file.py (original)
+++ people/waldi/utils/kconfigeditor2/lib/kconfigeditor/kconfig/menu/file.py Mon Mar 16 20:39:55 2009
@@ -123,7 +123,7 @@
split_rules = r"""
^
(?P<ind>\s*)
- (---\s*)?(?P<word>[a-z_]+)(\s*---)?
+ (-{2,}\s*)?(?P<word>[a-z_]+)(\s*-{2,})?
(
\s*(?P<rest2>["'].+)
|
Added: people/waldi/utils/kconfigeditor2/lib/kconfigeditor/package.py
==============================================================================
--- (empty file)
+++ people/waldi/utils/kconfigeditor2/lib/kconfigeditor/package.py Mon Mar 16 20:39:55 2009
@@ -0,0 +1,109 @@
+from __future__ import absolute_import
+
+import os
+
+from debian_linux.config import ConfigCoreHierarchy
+
+from .kconfig.menu.file import FileChoice, FileConfig
+from .kconfig.config import File
+
+class Files(dict):
+ def __init__(self, root):
+ self.kernelarch = {}
+ self.files = {}
+ self.filenames = {}
+ self.root = os.path.join(root, "debian/config")
+ self.config = ConfigCoreHierarchy([self.root])
+
+ self._read_base()
+
+ for key, files in self.filenames.iteritems():
+ r = self.setdefault(key, FileList())
+ for f in files:
+ if f in self.files:
+ f = self.files[f]
+ else:
+ f = self.files.setdefault(f, File(file(os.path.join(self.root, f)), f))
+ r.append_file(f)
+
+ def _read_arch(self, arch):
+ config_entry = self.config.merge('base', arch)
+ self.kernelarch[arch,] = config_entry.get('kernel-arch', arch)
+
+ kconfig = self.check_config("%s/config" % arch, True, arch)
+ self.filenames[arch,] = kconfig
+
+ for featureset in self.config['base', arch]['featuresets']:
+ self._read_featureset(arch, featureset)
+
+ def _read_base(self):
+ self.kernelarch[()] = None
+ self.filenames[()] = self.check_config('config', True)
+
+ for arch in self.config['base',]['arches']:
+ self._read_arch(arch)
+
+ def _read_featureset(self, arch, featureset):
+ # TODO
+ if featureset != 'none':
+ return
+
+ config_entry = self.config.merge('base', arch, featureset)
+ self.kernelarch[arch, featureset] = config_entry.get('kernel-arch', arch)
+
+ kconfig = []
+ kconfig.extend(self.check_config("featureset-%s/config" % featureset, False, None, featureset))
+ kconfig.extend(self.check_config("%s/%s/config" % (arch, featureset), False, arch, featureset))
+ self.filenames[arch, featureset] = kconfig
+
+ for flavour in self.config['base', arch, featureset]['flavours']:
+ self._read_flavour(arch, featureset, flavour)
+
+ def _read_flavour(self, arch, featureset, flavour):
+ config_entry = self.config.merge('base', arch, featureset, flavour)
+ self.kernelarch[arch, featureset, flavour] = config_entry.get('kernel-arch', arch)
+
+ kconfig = []
+ kconfig.extend(self.check_config("%s/config.%s" % (arch, flavour), False, arch, None, flavour))
+ kconfig.extend(self.check_config("%s/%s/config.%s" % (arch, featureset, flavour), False, arch, featureset, flavour))
+ self.filenames[arch, featureset, flavour] = kconfig
+
+ def _get_config(self, *entry_name):
+ entry_real = ('image',) + entry_name
+ entry = self.config.get(entry_real, None)
+ if entry is None:
+ return None
+ return entry.get('configs', None)
+
+ def check_config_default(self, fail, f):
+ f1 = self.root + '/' + f
+ if os.path.exists(f1):
+ return [f]
+ if fail:
+ raise RuntimeError("%s unavailable" % f)
+ return []
+
+ def check_config_files(self, files):
+ ret = []
+ for f in files:
+ f1 = self.root + '/' + f
+ if os.path.exists(f1):
+ ret.append(f)
+ break
+ else:
+ raise RuntimeError("%s unavailable" % f)
+ return ret
+
+ def check_config(self, default, fail, *entry_name):
+ configs = self._get_config(*entry_name)
+ if configs is None:
+ return self.check_config_default(fail, default)
+ return self.check_config_files(configs)
+
+class FileList(object):
+ def __init__(self):
+ self._files = []
+
+ def append_file(self, item):
+ self._files.append(item)
+
More information about the Kernel-svn-changes
mailing list