0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-14 21:13:54 +01:00
synapse/scripts-dev/list_url_patterns.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
1.2 KiB
Python
Raw Normal View History

2016-02-05 16:17:47 +01:00
#! /usr/bin/python
import argparse
import ast
2016-02-05 16:17:47 +01:00
import os
import sys
2016-02-05 16:17:47 +01:00
import yaml
PATTERNS_V1 = []
PATTERNS_V2 = []
2016-02-05 16:17:47 +01:00
RESULT = {"v1": PATTERNS_V1, "v2": PATTERNS_V2}
2016-02-05 16:17:47 +01:00
class CallVisitor(ast.NodeVisitor):
def visit_Call(self, node):
if isinstance(node.func, ast.Name):
name = node.func.id
else:
return
if name == "client_patterns":
PATTERNS_V2.append(node.args[0].s)
2016-02-05 16:17:47 +01:00
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",
2016-02-05 16:17:47 +01:00
)
args = parser.parse_args()
for directory in args.directories:
2021-04-20 12:50:49 +02:00
for root, _, files in os.walk(directory):
2016-02-05 16:17:47 +01:00
for filename in files:
if filename.endswith(".py"):
filepath = os.path.join(root, filename)
find_patterns_in_file(filepath)
PATTERNS_V1.sort()
PATTERNS_V2.sort()
2016-02-05 16:17:47 +01:00
yaml.dump(RESULT, sys.stdout, default_flow_style=False)