Skip to content

Instantly share code, notes, and snippets.

@codephi
Last active March 16, 2018 17:37
Show Gist options
  • Save codephi/ee91bd540dd3d25f0a65a10bc3427c50 to your computer and use it in GitHub Desktop.
Save codephi/ee91bd540dd3d25f0a65a10bc3427c50 to your computer and use it in GitHub Desktop.
Lista todas as rotas slim php a partir de um diretório
#!/usr/bin/python3
'''
Author: assis@pagzoop.com
Usage: getAllRoutes.py [options] path
Options:
-h, --help show this help message and exit
--quote=QUOTE Quotation marks
'''
import os, sys
import re
from optparse import OptionParser
parser = OptionParser(usage='usage: %prog [options] path')
parser.add_option( '--quote',
dest="quote",
help="Quotation marks",
default='\''
)
(options, args) = parser.parse_args()
quote = "[{quote}]([^{quote}]*){quote}".format(quote=options.quote)
path = args[0]
def handler(rootPath):
files = os.listdir(rootPath)
for file in files:
filePath = path + "/" + file
if os.path.isfile(filePath) is True:
content = open(filePath, "r").read()
maths = re.findall("(\$app->post|$app->get|$app->delete|$app->put|$app->patch)(\(.*\))", content)
for math in maths:
if math:
route = re.findall(quote, math[1])
if route:
print(route[0])
elif os.path.isdir(filePath) is True:
handler(filePath)
handler(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment