[pypy-svn] r37760 - in pypy/dist/pypy/config: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Feb 1 19:11:38 CET 2007


Author: cfbolz
Date: Thu Feb  1 19:11:38 2007
New Revision: 37760

Modified:
   pypy/dist/pypy/config/config.py
   pypy/dist/pypy/config/makerestdoc.py
   pypy/dist/pypy/config/test/test_config.py
Log:
move the getpaths function to the OptionDescription, to not have to make a
Config object only to get the paths.


Modified: pypy/dist/pypy/config/config.py
==============================================================================
--- pypy/dist/pypy/config/config.py	(original)
+++ pypy/dist/pypy/config/config.py	Thu Feb  1 19:11:38 2007
@@ -151,29 +151,10 @@
                 result += substr
         return result
 
-    def getpaths(self, include_groups=False, currpath=None):
+    def getpaths(self, include_groups=False):
         """returns a list of all paths in self, recursively
-        
-            currpath should not be provided (helps with recursion)
         """
-        if currpath is None:
-            currpath = []
-        paths = []
-        for option in self._cfgimpl_descr._children:
-            attr = option._name
-            if attr.startswith('_cfgimpl'):
-                continue
-            value = getattr(self, attr)
-            if isinstance(value, Config):
-                if include_groups:
-                    paths.append('.'.join(currpath + [attr]))
-                currpath.append(attr)
-                paths += value.getpaths(include_groups=include_groups,
-                                        currpath=currpath)
-                currpath.pop()
-            else:
-                paths.append('.'.join(currpath + [attr]))
-        return paths
+        return self._cfgimpl_descr.getpaths(include_groups=include_groups)
 
 
 DEFAULT_OPTION_NAME = object()
@@ -396,6 +377,30 @@
     def add_optparse_option(self, argnames, parser, config):
         return
 
+    def getpaths(self, include_groups=False, currpath=None):
+        """returns a list of all paths in self, recursively
+        
+            currpath should not be provided (helps with recursion)
+        """
+        if currpath is None:
+            currpath = []
+        paths = []
+        for option in self._children:
+            attr = option._name
+            if attr.startswith('_cfgimpl'):
+                continue
+            value = getattr(self, attr)
+            if isinstance(value, OptionDescription):
+                if include_groups:
+                    paths.append('.'.join(currpath + [attr]))
+                currpath.append(attr)
+                paths += value.getpaths(include_groups=include_groups,
+                                        currpath=currpath)
+                currpath.pop()
+            else:
+                paths.append('.'.join(currpath + [attr]))
+        return paths
+
 
 class OptHelpFormatter(optparse.IndentedHelpFormatter):
 

Modified: pypy/dist/pypy/config/makerestdoc.py
==============================================================================
--- pypy/dist/pypy/config/makerestdoc.py	(original)
+++ pypy/dist/pypy/config/makerestdoc.py	Thu Feb  1 19:11:38 2007
@@ -132,21 +132,20 @@
         if path:
             content.add(
                 Paragraph(Link("back to parent", path + ".html")))
-        for elt in [
+        content.join(
             Title("Basic Option Information"),
             ListItem(Strong("name:"), self._name),
             ListItem(Strong("description:"), self.doc),
-            Title("Sub-Options")
-            ]:
-            content.add(elt)
-        conf = Config(self)
+            Title("Sub-Options"))
         stack = []
         prefix = fullpath
         curr = content
-        for subpath in conf.getpaths(include_groups=True):
+        for subpath in self.getpaths(include_groups=True):
             subpath = fullpath + "." + subpath
-            while not subpath.startswith(prefix):
+            while not (subpath.startswith(prefix) and
+                       subpath[len(prefix)] == "."):
                 curr, prefix = stack.pop()
+            print subpath, fullpath, curr
             new = curr.add(ListItem(Link(subpath, subpath + ".html")))
             stack.append((curr, prefix))
             prefix = subpath

Modified: pypy/dist/pypy/config/test/test_config.py
==============================================================================
--- pypy/dist/pypy/config/test/test_config.py	(original)
+++ pypy/dist/pypy/config/test/test_config.py	Thu Feb  1 19:11:38 2007
@@ -255,10 +255,13 @@
     assert config.getpaths() == ['gc.name', 'gc.dummy', 'gc.float', 'bool',
                                  'objspace', 'wantref', 'str', 'wantframework',
                                  'int']
+    assert config.getpaths() == descr.getpaths()
     assert config.gc.getpaths() == ['name', 'dummy', 'float']
+    assert config.gc.getpaths() == descr.gc.getpaths()
     assert config.getpaths(include_groups=True) == [
         'gc', 'gc.name', 'gc.dummy', 'gc.float',
         'bool', 'objspace', 'wantref', 'str', 'wantframework', 'int']
+    assert config.getpaths(True) == descr.getpaths(True)
 
 def test_underscore_in_option_name():
     descr = OptionDescription("opt", "", [



More information about the Pypy-commit mailing list