[pypy-svn] r29866 - pypy/branch/objspace-config-cleanup/pypy/config
cfbolz at codespeak.net
cfbolz at codespeak.net
Sat Jul 8 19:21:35 CEST 2006
Author: cfbolz
Date: Sat Jul 8 19:21:33 2006
New Revision: 29866
Modified:
pypy/branch/objspace-config-cleanup/pypy/config/config.py
pypy/branch/objspace-config-cleanup/pypy/config/pypyoption.py
Log:
add nice __str__ method for options and a __name__ == '__main__' to pypyoption
to try out the cmdline parsing.
Modified: pypy/branch/objspace-config-cleanup/pypy/config/config.py
==============================================================================
--- pypy/branch/objspace-config-cleanup/pypy/config/config.py (original)
+++ pypy/branch/objspace-config-cleanup/pypy/config/config.py Sat Jul 8 19:21:33 2006
@@ -2,14 +2,6 @@
import optparse
class Config(object):
- """main config
-
- there's 3 levels of configuration values: default ones, stuff from
- config files and command-line options, all cascading
-
- config is divided in groups, each group is an instance on the root
- (this object)
- """
_frozen = False
def __init__(self, descr, **overrides):
@@ -81,6 +73,22 @@
if isinstance(child, Option):
yield child._name, getattr(self, child._name)
+ def __str__(self):
+ result = "[%s]\n" % (self._descr._name, )
+ for child in self._descr._children:
+ if isinstance(child, Option):
+ if self._value_owners[child._name] == 'default':
+ continue
+ result += " %s = %s\n" % (
+ child._name, getattr(self, child._name))
+ else:
+ substr = str(getattr(self, child._name))
+ substr = " " + substr.replace("\n", "\n ")
+ result += substr
+ return result
+
+
+
class Option(object):
def __init__(self, name, doc, cmdline=None):
self._name = name
Modified: pypy/branch/objspace-config-cleanup/pypy/config/pypyoption.py
==============================================================================
--- pypy/branch/objspace-config-cleanup/pypy/config/pypyoption.py (original)
+++ pypy/branch/objspace-config-cleanup/pypy/config/pypyoption.py Sat Jul 8 19:21:33 2006
@@ -1,6 +1,6 @@
import py
from pypy.config.config import OptionDescription, BoolOption, IntOption
-from pypy.config.config import ChoiceOption
+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()
@@ -75,3 +75,11 @@
BoolOption("translating", "indicates whether we are translating currently",
default=False),
])
+
+if __name__ == '__main__':
+ config = Config(pypy_optiondescription)
+ parser = to_optparse(config, ["objspace.name",
+ "objspace.std.oldstyle",
+ "objspace.std.withstrdict"])
+ option, args = parser.parse_args()
+ print config
More information about the Pypy-commit
mailing list