[pypy-svn] r30628 - in pypy/dist/pypy/config: . test
guido at codespeak.net
guido at codespeak.net
Thu Jul 27 13:01:39 CEST 2006
Author: guido
Date: Thu Jul 27 13:01:38 2006
New Revision: 30628
Modified:
pypy/dist/pypy/config/config.py
pypy/dist/pypy/config/pypyoption.py
pypy/dist/pypy/config/test/test_config.py
Log:
Moved function get_paths to method Config.getpaths()
Modified: pypy/dist/pypy/config/config.py
==============================================================================
--- pypy/dist/pypy/config/config.py (original)
+++ pypy/dist/pypy/config/config.py Thu Jul 27 13:01:38 2006
@@ -87,7 +87,24 @@
result += substr
return result
-
+ def getpaths(self, 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 attr, value in self.__dict__.iteritems():
+ if attr.startswith('_'):
+ continue
+ if isinstance(value, Config):
+ currpath.append(attr)
+ paths += value.getpaths(currpath)
+ currpath.pop()
+ else:
+ paths.append('.'.join(currpath + [attr]))
+ return paths
class Option(object):
def __init__(self, name, doc, cmdline=None):
Modified: pypy/dist/pypy/config/pypyoption.py
==============================================================================
--- pypy/dist/pypy/config/pypyoption.py (original)
+++ pypy/dist/pypy/config/pypyoption.py Thu Jul 27 13:01:38 2006
@@ -1,6 +1,6 @@
import py
from pypy.config.config import OptionDescription, BoolOption, IntOption
-from pypy.config.config import ChoiceOption, to_optparse, Config, get_paths
+from pypy.config.config import ChoiceOption, to_optparse, Config
modulepath = py.magic.autopath().dirpath().dirpath().join("module")
all_modules = [p.basename for p in modulepath.listdir()
@@ -79,7 +79,7 @@
if __name__ == '__main__':
config = Config(pypy_optiondescription)
- paths = get_paths(config)
+ paths = config.getpaths()
parser = to_optparse(config, paths)
option, args = parser.parse_args()
print config
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 Jul 27 13:01:38 2006
@@ -204,10 +204,10 @@
assert config.gc.name == 'framework'
-def test_get_paths():
+def test_getpaths():
descr = make_description()
config = Config(descr)
- assert get_paths(config), ['gc.name', 'gc.dummy', 'gc.float', 'bool',
+ assert config.getpaths(), ['gc.name', 'gc.dummy', 'gc.float', 'bool',
'objspace', 'wantref', 'int']
- assert get_paths(config.gc), ['name', 'dummy', 'float']
+ assert config.gc.getpaths(), ['name', 'dummy', 'float']
More information about the Pypy-commit
mailing list