[kernel-team] 84/86: kconfigeditor/kconfig/config.py - Add FileReader class. - Add explicit state handling.
debian-kernel at lists.debian.org
debian-kernel at lists.debian.org
Mon Dec 21 00:35:02 UTC 2015
This is an automated email from the git hooks/post-receive script.
benh pushed a commit to branch benh/kconfigeditor2
in repository kernel-team.
commit e9a3ece18f20e8b17dcb0f7733797ee657a5c753
Author: Bastian Blank <waldi at debian.org>
Date: Mon Sep 23 21:50:05 2013 +0000
kconfigeditor/kconfig/config.py
- Add FileReader class.
- Add explicit state handling.
svn path=/people/waldi/utils/kconfigeditor2/; revision=20670
---
.../kconfigeditor2/kconfigeditor/kconfig/config.py | 48 ++++++++++++++++------
1 file changed, 35 insertions(+), 13 deletions(-)
diff --git a/utils/kconfigeditor2/kconfigeditor/kconfig/config.py b/utils/kconfigeditor2/kconfigeditor/kconfig/config.py
index a5feb72..73f50ad 100644
--- a/utils/kconfigeditor2/kconfigeditor/kconfig/config.py
+++ b/utils/kconfigeditor2/kconfigeditor/kconfig/config.py
@@ -93,29 +93,51 @@ class File(dict):
fd.write(data + '\n')
def read(self, f):
- comments = []
+ for entry in FileReader.read(f):
+ self[entry.name] = entry
+
+
+class FileReader(object):
+ class State(object):
+ __slots__ = 'name', 'value', 'comments'
+
+ def __init__(self):
+ self.name = None
+ self.value = None
+ self.comments = []
+
+ reset = __init__
+
+ def entry(self):
+ if self.value in ('y', 'm', 'n', None):
+ return FileEntryTristate(self.name, self.value, self.comments)
+ return FileEntry(self.name, self.value, self.comments)
+
+ def entry_reset(self):
+ ret = self.entry()
+ self.reset()
+ return ret
+
+
+ @classmethod
+ def read(cls, f):
+ state = cls.State()
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 = FileEntry(option, value, comments)
- self[option] = entry
- comments = []
+ state.name = line[7:i]
+ state.value = line[i+1:]
+ yield state.entry_reset()
elif line.startswith("# CONFIG_"):
- option = line[9:-11]
- self[option] = FileEntryTristate(option, 'n', comments)
- comments = []
+ state.name = line[9:-11]
+ yield state.entry_reset()
elif line.startswith("#. "):
- comments.append(line[3:])
+ state.comments.append(line[3:])
elif line.startswith("#") or not line:
pass
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/kernel/kernel-team.git
More information about the Kernel-svn-changes
mailing list