Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r54980:51326a2c5f7b
Date: 2012-05-09 09:02 +0200
http://bitbucket.org/pypy/pypy/changeset/51326a2c5f7b/

Log:    Improve the output of "pypy --info" to follow the style output by
        translate.py. It still prints all options instead of the non-
        default ones, but maybe it's not a bad idea anyway.

diff --git a/pypy/translator/goal/app_main.py b/pypy/translator/goal/app_main.py
--- a/pypy/translator/goal/app_main.py
+++ b/pypy/translator/goal/app_main.py
@@ -121,8 +121,18 @@
     else:
         optitems = options.items()
         optitems.sort()
-        for name, value in optitems:
-            print ' %51s: %s' % (name, value)
+        current = []
+        for key, value in optitems:
+            group = key.split('.')
+            name = group.pop()
+            n = 0
+            while n < min(len(current), len(group)) and current[n] == group[n]:
+                n += 1
+            while n < len(group):
+                print '%s[%s]' % ('    ' * n, group[n])
+                n += 1
+            print '%s%s = %r' % ('    ' * n, name, value)
+            current = group
     raise SystemExit
 
 def print_help(*args):
diff --git a/pypy/translator/goal/test2/test_app_main.py 
b/pypy/translator/goal/test2/test_app_main.py
--- a/pypy/translator/goal/test2/test_app_main.py
+++ b/pypy/translator/goal/test2/test_app_main.py
@@ -787,6 +787,37 @@
         assert data.startswith("15\xe2\x82\xac")
 
 
+class TestAppMain:
+    
+    def test_print_info(self):
+        from pypy.translator.goal import app_main
+        import sys, cStringIO
+        prev_so = sys.stdout
+        prev_ti = getattr(sys, 'pypy_translation_info', 'missing')
+        sys.pypy_translation_info = {
+            'translation.foo': True,
+            'translation.bar': 42,
+            'translation.egg.something': None,
+            'objspace.x': 'hello',
+        }
+        try:
+            sys.stdout = f = cStringIO.StringIO()
+            py.test.raises(SystemExit, app_main.print_info)
+        finally:
+            sys.stdout = prev_so
+            if prev_ti == 'missing':
+                del sys.pypy_translation_info
+            else:
+                sys.pypy_translation_info = prev_ti
+        assert f.getvalue() == ("[objspace]\n"
+                                "    x = 'hello'\n"
+                                "[translation]\n"
+                                "    bar = 42\n"
+                                "    [egg]\n"
+                                "        something = None\n"
+                                "    foo = True\n")
+
+
 class AppTestAppMain:
 
     def setup_class(self):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to