diff options
author | Mark Haines <mark.haines@matrix.org> | 2016-02-05 15:17:47 +0000 |
---|---|---|
committer | Mark Haines <mark.haines@matrix.org> | 2016-02-05 15:18:58 +0000 |
commit | b052621f679103052426baf086fd48074199e81b (patch) | |
tree | 0a567b63b395852ea0c8e46e437cf71976cb54d7 /scripts-dev/list_url_patterns.py | |
parent | Merge pull request #550 from matrix-org/daniel/guestnames (diff) | |
download | synapse-b052621f679103052426baf086fd48074199e81b.tar.xz |
List the URL patterns in synapse
Diffstat (limited to 'scripts-dev/list_url_patterns.py')
-rwxr-xr-x | scripts-dev/list_url_patterns.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/scripts-dev/list_url_patterns.py b/scripts-dev/list_url_patterns.py new file mode 100755 index 0000000000..23bcc6b034 --- /dev/null +++ b/scripts-dev/list_url_patterns.py @@ -0,0 +1,54 @@ +#! /usr/bin/python + +import ast +import argparse +import os +import sys +import yaml + +PATTERNS = [] + + +class CallVisitor(ast.NodeVisitor): + def visit_Call(self, node): + if isinstance(node.func, ast.Name): + name = node.func.id + else: + return + + if name == "client_path_patterns": + PATTERNS.append(node.args[0].s) + elif name == "client_v2_patterns": + PATTERNS.append(node.args[0].s) + + +def find_patterns_in_code(input_code): + input_ast = ast.parse(input_code) + visitor = CallVisitor() + visitor.visit(input_ast) + + +def find_patterns_in_file(filepath): + with open(filepath) as f: + find_patterns_in_code(f.read()) + + +parser = argparse.ArgumentParser(description='Find url patterns.') + +parser.add_argument( + "directories", nargs='+', metavar="DIR", + help="Directories to search for definitions" +) + +args = parser.parse_args() + + +for directory in args.directories: + for root, dirs, files in os.walk(directory): + for filename in files: + if filename.endswith(".py"): + filepath = os.path.join(root, filename) + find_patterns_in_file(filepath) + + +yaml.dump(sorted(PATTERNS), sys.stdout, default_flow_style=False) |