John Anderson
2015-01-22 b8ba0f1ed25b118aeb05accb23d872b3a72dc548
Make more ways to configure [proutes] section
3 files modified
89 ■■■■■ changed files
docs/narr/commandline.rst 11 ●●●●● patch | view | raw | blame | history
pyramid/scripts/proutes.py 5 ●●●● patch | view | raw | blame | history
pyramid/tests/test_scripts/test_proutes.py 73 ●●●●● patch | view | raw | blame | history
docs/narr/commandline.rst
@@ -350,6 +350,17 @@
             name
             pattern
You can also separate the formats with commas or spaces:
.. code-block:: text
  :linenos:
    [proutes]
    format = view name pattern
    [proutes]
    format = view, name, pattern
If you want to temporarily configure the columns and order there is the
``--format`` which is a comma separated list of columns you want to include. The
current available formats are ``name``, ``pattern``, ``view``, and ``method``.
pyramid/scripts/proutes.py
@@ -2,6 +2,7 @@
import optparse
import sys
import textwrap
import re
from pyramid.paster import bootstrap
from pyramid.compat import (string_types, configparser)
@@ -291,7 +292,8 @@
            items = config.items('proutes')
            for k, v in items:
                if 'format' == k:
                    self.column_format = [x.strip() for x in v.split('\n')]
                    cols = re.split(r'[,|\s|\n]*', v)
                    self.column_format = [x.strip() for x in cols]
        except configparser.NoSectionError:
            return
@@ -314,6 +316,7 @@
        env = self.bootstrap[0](config_uri, options=parse_vars(self.args[1:]))
        registry = env['registry']
        mapper = self._get_mapper(registry)
        self.proutes_file_config(config_uri)
        if self.options.format:
pyramid/tests/test_scripts/test_proutes.py
@@ -632,7 +632,7 @@
        self.assertEqual(result, 2)
        self.assertEqual(L[0], expected)
    def test_config_format_ini(self):
    def test_config_format_ini_newlines(self):
        from pyramid.renderers import null_renderer as nr
        from pyramid.config import not_
@@ -648,14 +648,79 @@
        )
        command = self._makeOne()
        command.options.glob = '*foo*'
        command.options.format = 'method,name'
        L = []
        command.out = L.append
        command.bootstrap = (dummy.DummyBootstrap(registry=config.registry),)
        config_factory = dummy.DummyConfigParserFactory()
        command.ConfigParser = config_factory
        config_factory.items = [('format', 'method\name')]
        config_factory.items = [('format', 'method\nname')]
        result = command.run()
        self.assertEqual(result, 0)
        self.assertEqual(len(L), 3)
        compare_to = L[-1].split()
        expected = ['!POST,*', 'foo']
        self.assertEqual(compare_to, expected)
        self.assertEqual(L[0].split(), ['Method', 'Name'])
    def test_config_format_ini_spaces(self):
        from pyramid.renderers import null_renderer as nr
        from pyramid.config import not_
        def view1(context, request): return 'view1'
        config = self._makeConfig(autocommit=True)
        config.add_route('foo', '/a/b')
        config.add_view(
            route_name='foo',
            view=view1,
            renderer=nr,
            request_method=not_('POST')
        )
        command = self._makeOne()
        L = []
        command.out = L.append
        command.bootstrap = (dummy.DummyBootstrap(registry=config.registry),)
        config_factory = dummy.DummyConfigParserFactory()
        command.ConfigParser = config_factory
        config_factory.items = [('format', 'method name')]
        result = command.run()
        self.assertEqual(result, 0)
        self.assertEqual(len(L), 3)
        compare_to = L[-1].split()
        expected = ['!POST,*', 'foo']
        self.assertEqual(compare_to, expected)
        self.assertEqual(L[0].split(), ['Method', 'Name'])
    def test_config_format_ini_commas(self):
        from pyramid.renderers import null_renderer as nr
        from pyramid.config import not_
        def view1(context, request): return 'view1'
        config = self._makeConfig(autocommit=True)
        config.add_route('foo', '/a/b')
        config.add_view(
            route_name='foo',
            view=view1,
            renderer=nr,
            request_method=not_('POST')
        )
        command = self._makeOne()
        L = []
        command.out = L.append
        command.bootstrap = (dummy.DummyBootstrap(registry=config.registry),)
        config_factory = dummy.DummyConfigParserFactory()
        command.ConfigParser = config_factory
        config_factory.items = [('format', 'method,name')]
        result = command.run()
        self.assertEqual(result, 0)