SOURCES: kernel-symsorder.py - add basedir - support menu aka comm...

glen glen at pld-linux.org
Mon May 5 18:58:10 CEST 2008


Author: glen                         Date: Mon May  5 16:58:10 2008 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- add basedir
- support menu aka comments

---- Files affected:
SOURCES:
   kernel-symsorder.py (1.1 -> 1.2) 

---- Diffs:

================================================================
Index: SOURCES/kernel-symsorder.py
diff -u SOURCES/kernel-symsorder.py:1.1 SOURCES/kernel-symsorder.py:1.2
--- SOURCES/kernel-symsorder.py:1.1	Wed Apr 23 17:40:02 2008
+++ SOURCES/kernel-symsorder.py	Mon May  5 18:58:04 2008
@@ -2,10 +2,11 @@
 # vim: set fileencoding=utf-8
 # -*- coding: utf-8 -*-
 #
-# Parse kernel Kconfig and return all kernel symbols in orders it will write
+# Parse kernel Kconfig and return all kernel symbols in order it will write
 # likely also to .config file.  based on
 #
 # Parsing code based on http://kernel.org/doc/make/menuconfig2html.py
+# "boolean" not documented type in kconfig-language.txt line 51
 #
 # Authors
 #   Elan Ruusamäe <glen at pld-linux.org>
@@ -15,15 +16,14 @@
 #   2008-04-23
 # 
 
-# "boolean" not documented type in kconfig-language.txt line 51
-
 import os,sys
 
 class ParsingException(Exception):
   pass
 
 class MenuParser(object):
-  filename = ""
+  filename = ''
+  basedir = '.'
   lineno = 0
   helplen = 0
   result = []
@@ -49,9 +49,14 @@
       else:
         raise StopIteration
 
-  def parse(self, filename):
+  def parse(self, filename, basedir = None):
     self.result = []
-    self.readfile(filename)
+    if basedir:
+        self.basedir = basedir
+    try:
+        self.readfile(os.path.join(self.basedir, filename))
+    except IOError, e:
+        raise IOError, "%s: %s" % (self.filename, e)
     return self.result
 
   def readfile(self, filename):
@@ -78,10 +83,17 @@
       config = words[1]
       self.result.append(config)
 
+    elif words[0] in ('menu'):
+        menu = self.zapquotes(words[1])
+        self.result.append("")
+        self.result.append("#")
+        self.result.append("# " + menu)
+        self.result.append("#")
+
     elif words[0] in ('bool', 'boolean', 'mainmenu', 'option', 'def_tristate', \
             'optional', 'comment', 'choice', 'endchoice', 'range', 'def_bool', \
             'endmenu', 'tristate', 'string', 'hex', 'int', 'prompt', 'default', \
-            'depends', 'select', 'if', 'endif', 'menu'):
+            'depends', 'select', 'if', 'endif'):
        pass
 
     elif words[0] in ('help', '---help---'):
@@ -89,23 +101,28 @@
 
     elif words[0] == 'source':
       file = self.zapquotes(words[1])
-      parser = MenuParser()
-      self.result += parser.parse(file)
+      self.result += MenuParser().parse(file, basedir = self.basedir)
 
     else:
       raise ParsingException, "%s:%d: Bad line: %s\n" % (self.filename, self.lineno, line.strip())
 
 if __name__ == '__main__':
   # called as script, not as lib
-  if len(sys.argv) != 2:
-    sys.stderr.write("Usage: symsorder.py kconfigfile\n")
+  if len(sys.argv) != 3:
+    sys.stderr.write("Usage: symsorder.py dir kconfigfile\n")
     sys.exit(1)
   parser = MenuParser()
-  config = sys.argv[1]
+  dir = sys.argv[1]
+  config = sys.argv[2]
+  res = None
   try:
-    res = parser.parse(config)
-  except IOError:
-    sys.stderr.write("File %s missing\n" % config)
+    res = parser.parse(config, dir)
+  except IOError, e:
+    sys.stderr.write("Error: %s\n" % e)
+    sys.exit(1)
   except ParsingException, e:
     sys.stderr.write(e.message)
+    sys.exit(1)
 
+  for symbol in res:
+    print symbol
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SOURCES/kernel-symsorder.py?r1=1.1&r2=1.2&f=u



More information about the pld-cvs-commit mailing list