diff options
| author | John Anderson <sontek@gmail.com> | 2015-01-22 07:29:02 -0800 |
|---|---|---|
| committer | John Anderson <sontek@gmail.com> | 2015-01-22 07:29:02 -0800 |
| commit | b8ba0f1ed25b118aeb05accb23d872b3a72dc548 (patch) | |
| tree | e8e5061ed6363ce38b3779659cd662a28739858f | |
| parent | 8724ab8301c9d5808d781bab0af1df56909c9236 (diff) | |
| download | pyramid-b8ba0f1ed25b118aeb05accb23d872b3a72dc548.tar.gz pyramid-b8ba0f1ed25b118aeb05accb23d872b3a72dc548.tar.bz2 pyramid-b8ba0f1ed25b118aeb05accb23d872b3a72dc548.zip | |
Make more ways to configure [proutes] section
| -rw-r--r-- | docs/narr/commandline.rst | 11 | ||||
| -rw-r--r-- | pyramid/scripts/proutes.py | 5 | ||||
| -rw-r--r-- | pyramid/tests/test_scripts/test_proutes.py | 73 |
3 files changed, 84 insertions, 5 deletions
diff --git a/docs/narr/commandline.rst b/docs/narr/commandline.rst index aca0ff425..3dcb092e2 100644 --- a/docs/narr/commandline.rst +++ b/docs/narr/commandline.rst @@ -350,6 +350,17 @@ For example you may remove request method and place the view first: 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``. diff --git a/pyramid/scripts/proutes.py b/pyramid/scripts/proutes.py index 2155b4983..544947724 100644 --- a/pyramid/scripts/proutes.py +++ b/pyramid/scripts/proutes.py @@ -2,6 +2,7 @@ import fnmatch import optparse import sys import textwrap +import re from pyramid.paster import bootstrap from pyramid.compat import (string_types, configparser) @@ -291,7 +292,8 @@ class PRoutesCommand(object): 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 @@ class PRoutesCommand(object): 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: diff --git a/pyramid/tests/test_scripts/test_proutes.py b/pyramid/tests/test_scripts/test_proutes.py index 446d772ff..e426eee73 100644 --- a/pyramid/tests/test_scripts/test_proutes.py +++ b/pyramid/tests/test_scripts/test_proutes.py @@ -632,7 +632,7 @@ class TestPRoutesCommand(unittest.TestCase): 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 @@ class TestPRoutesCommand(unittest.TestCase): ) 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\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')] + config_factory.items = [('format', 'method,name')] result = command.run() self.assertEqual(result, 0) |
