Author: waldi Date: Tue Mar 11 13:59:36 2008 New Revision: 10784 Log: kconfigeditor/kconfig/menu/file.py: Update.
Modified: people/waldi/utils/kconfigeditor2/kconfigeditor/kconfig/menu/file.py Modified: people/waldi/utils/kconfigeditor2/kconfigeditor/kconfig/menu/file.py ============================================================================== --- people/waldi/utils/kconfigeditor2/kconfigeditor/kconfig/menu/file.py (original) +++ people/waldi/utils/kconfigeditor2/kconfigeditor/kconfig/menu/file.py Tue Mar 11 13:59:36 2008 @@ -1,27 +1,33 @@ import re -class File(object): - pass +class File(list): + def __init__(self, filename): + self.filename = filename + +class FileConfig(object): + def __init__(self, name): + self.name = name + + def __repr__(self): + return "<%s(%s)>" % (self.__class__.__name__, self.name) class _Parser(object): - def __call__(self, fd): + def __call__(self, filename): lineno = 0 stack = _Stack() - _BlockRoot(stack) + _BlockRoot(stack, File(filename)) - for line in fd: + for line in file(filename): line = line.rstrip() if not line: stack.top().process_line_empty() elif line.lstrip()[0] == '#': pass else: - print stack._list - print line stack.top().process_line(line) lineno += 1 - stack.top().stop(lineno, 0) + return stack.top().stop(lineno, 0) class _Text(object): __slots__ = "text", "lineno", "column" @@ -63,6 +69,9 @@ return self._list[-1] class _Element(object): + entry = None + stack = None + def __init__(self, parent): self.stack = parent.stack self.stack.push(self) @@ -76,7 +85,7 @@ def recurse(self, name, *args): self.pop() - getattr(self.stack.top(), name)(*args) + return getattr(self.stack.top(), name)(*args) class _BlockContainer(object): split_rules = r""" @@ -97,7 +106,6 @@ if not match: raise Exception, "Can't parse: '%s'" % text rest = match.group('rest1') or match.group('rest2') - print "rest:", rest getattr(self, "process_%s" % match.group('word'))(rest, match.group('ind')) def process_line_empty(self): @@ -112,13 +120,13 @@ _BlockComment(self) def process_config(self, text, ind): - _BlockConfig(self) + _BlockConfig(self, text) def process_if(self, text, ind): - _BlockIf(self) + _BlockIf(self, text) def process_menuconfig(self, text, ind): - _BlockMenuconfig(self, ind) + _BlockMenuconfig(self, text) def process_source(self, text, ind): pass @@ -134,7 +142,7 @@ class _BlockObject(_Element): def __getattr__(self, name): def ret(*args): - self.recurse(name, *args) + return self.recurse(name, *args) return ret class _BlockObjectIndentation(_BlockObject): @@ -161,8 +169,8 @@ _BlockContainerCommon, _BlockContainerMenu, ): - def __init__(self, stack): - self.stack = stack + def __init__(self, stack, entry): + self.stack, self.entry = stack, entry stack.push(self) def __getattr__(self, name): @@ -173,11 +181,13 @@ def stop(self, lineno, column): self.stack.pop(self) + return self.entry class _BlockChoice(_BlockObject, _BlockContainerCommon): def __init__(self, parent): super(_BlockChoice, self).__init__(parent) - _BlockConfig(self) + self.entry = parent.entry + _BlockConfigData(self) def process_default(self, text, ind): _BlockType(self, text, ind) @@ -188,7 +198,7 @@ class _BlockComment(_BlockObject, _BlockContainerDepends): pass -class _BlockConfig(_BlockObject, _BlockContainerDepends): +class _BlockConfigData(_BlockObject, _BlockContainerDepends): def process_bool(self, text, ind): _BlockType(self, text, ind) @@ -233,6 +243,12 @@ def process_tristate(self, text, ind): _BlockType(self, text, ind) +class _BlockConfig(_BlockConfigData): + def __init__(self, parent, name): + super(_BlockConfig, self).__init__(parent) + self.entry = FileConfig(name) + parent.entry.append(self.entry) + class _BlockDepends(_BlockObjectIndentation): pass @@ -244,6 +260,9 @@ _BlockContainerCommon, _BlockContainerMenu, ): + def __init__(self, parent, name): + super(_BlockIf, self).__init__(parent) + self.entry = parent.entry def process_endif(self, text, ind): self.pop() @@ -255,7 +274,8 @@ ): def __init__(self, parent, text): super(_BlockMenu, self).__init__(parent) - pass + # TODO + self.entry = parent.entry def process_depends(self, text, ind): pass @@ -263,8 +283,11 @@ def process_endmenu(self, text, ind): self.pop() -class _BlockMenuconfig(_BlockConfig, _BlockMenu): - pass +class _BlockMenuconfig(_BlockMenu): + def __init__(self, parent, name): + super(_BlockMenuconfig, self).__init__(parent, "") + self.entry = parent.entry + _BlockConfigData(self) class _BlockType(_BlockObject): def __init__(self, parent, text, ind): _______________________________________________ Kernel-svn-changes mailing list Kernel-svn-changes@lists.alioth.debian.org http://lists.alioth.debian.org/mailman/listinfo/kernel-svn-changes