From 1264707de3f9fa2d15943da3bf321b1304556aa3 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Tue, 23 Dec 2014 14:58:13 -0800 Subject: Add a --glob option to limit output E.g.: $ proutes development.ini --glob='user*' Name Pattern View Method ---- ------- ---- ------ user /profilesvc/v1/user/{user_id} pyramid.config.views. * user /profilesvc/v1/user/{user_id} cornice.service.wrapper GET,HEAD --- pyramid/scripts/proutes.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pyramid/scripts/proutes.py b/pyramid/scripts/proutes.py index 5d860b47d..fce90c0c1 100644 --- a/pyramid/scripts/proutes.py +++ b/pyramid/scripts/proutes.py @@ -1,3 +1,4 @@ +import fnmatch import optparse import sys import textwrap @@ -234,6 +235,9 @@ class PRoutesCommand(object): usage, description=textwrap.dedent(description) ) + parser.add_option('-g', '--glob', + action='store', type='string', dest='glob', + default='', help='Display routes matching glob pattern') def __init__(self, argv, quiet=False): self.options, self.args = self.parser.parse_args(argv[1:]) @@ -280,6 +284,12 @@ class PRoutesCommand(object): route_data = get_route_data(route, registry) for name, pattern, view, method in route_data: + if self.options.glob: + match = (fnmatch.fnmatch(name, self.options.glob) or + fnmatch.fnmatch(pattern, self.options.glob)) + if not match: + continue + if len(name) > max_name: max_name = len(name) -- cgit v1.2.3