[kernel-team] 81/86: kconfigeditor/kconfig/config.py - Don't use lists in argument lists. - Use str.format. - Use boolean for tristate entries.

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 3b30382c0ffe5034070feb6b946a0c91addf36a9
Author: Bastian Blank <waldi at debian.org>
Date:   Sat Sep 21 16:36:25 2013 +0000

    kconfigeditor/kconfig/config.py
    - Don't use lists in argument lists.
    - Use str.format.
    - Use boolean for tristate entries.
    
    svn path=/people/waldi/utils/kconfigeditor2/; revision=20656
---
 .../kconfigeditor2/kconfigeditor/kconfig/config.py | 40 ++++++++++------------
 1 file changed, 18 insertions(+), 22 deletions(-)

diff --git a/utils/kconfigeditor2/kconfigeditor/kconfig/config.py b/utils/kconfigeditor2/kconfigeditor/kconfig/config.py
index b692bc3..6c3796e 100644
--- a/utils/kconfigeditor2/kconfigeditor/kconfig/config.py
+++ b/utils/kconfigeditor2/kconfigeditor/kconfig/config.py
@@ -125,16 +125,11 @@ class File(dict):
 
 
 class FileEntry(object):
-    __slots__ = "name", "value", "comments"
+    __slots__ = 'name', 'value', 'comments'
 
-    def __init__(self, name, value, comments=[]):
-        self.name, self.value, self.comments = name, value, comments
-
-    def __cmp__(self, other):
-        ret = cmp(self.name, other.name)
-        if ret:
-            return ret
-        return cmp(self.value, other.value)
+    def __init__(self, name, value, comments=None):
+        self.name, self.value = name, value
+        self.comments = comments or []
 
     def __eq__(self, other):
         return self.name == other.name and self.value == other.value
@@ -143,37 +138,38 @@ class FileEntry(object):
         return hash(self.name) | hash(self.value)
 
     def __repr__(self):
-        return '<%s(%r, %r, %r)>' % (self.__class__.__name__, self.name, self.value, self.comments)
+        return '<{}({!r}, {!r}, {!r})>'.format(self.__class__.__name__, self.name, self.value, self.comments)
 
     def __str__(self):
-        return "CONFIG_%s=%s" % (self.name, self.value)
+        return 'CONFIG_{}={}'.format(self.name, self.value)
 
     def write(self):
+        print("got:", repr(self))
         for comment in self.comments:
             yield '#. ' + comment
         yield str(self)
 
 
 class FileEntryTristate(FileEntry):
-    VALUE_NO = 0
-    VALUE_YES = 1
-    VALUE_MOD = 2
+    VALUE_NO = False
+    VALUE_YES = True
+    VALUE_MOD = object()
 
-    def __init__(self, name, value, comments=[]):
+    def __init__(self, name, value, comments=None):
         if value == 'n' or value is None:
             value = self.VALUE_NO
         elif value == 'y':
             value = self.VALUE_YES
         elif value == 'm':
             value = self.VALUE_MOD
+        else:
+            raise NotImplementedError
         super(FileEntryTristate, self).__init__(name, value, comments)
 
     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
+        if self.value is self.VALUE_MOD:
+            return 'CONFIG_{}=m'.format(self.name)
+        if self.value:
+            return 'CONFIG_{}=y'.format(self.name)
+        return '# CONFIG_{} is not set'.format(self.name)
 

-- 
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