Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onurdegerli/5822754 to your computer and use it in GitHub Desktop.
Save onurdegerli/5822754 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import sys
import glob
import os
import re
# define base directory
baseDirectory = ""
# define sub directory
formsDirectory = ""
tabuFunctions = ['rules', 'attributeLabels']
def read_directory(baseDirectory, directoryName):
fullDirectory = baseDirectory + directoryName
os.chdir(fullDirectory)
files = []
for phpFile in glob.glob("*.php"):
files.append(phpFile)
return files
def get_function_names(baseDirectory, directory, files):
regex = re.compile("public function (\w+)")
functionList = {}
for fileName in files:
fileWithDirectory = baseDirectory + directory + fileName
f = open(fileWithDirectory, 'r')
f.readline()
fileFunctionsList = []
for line in f:
r = regex.search(line)
if r:
matchedFunction = r.groups()[0]
fileFunctionsList.append(matchedFunction)
functionList[fileName] = fileFunctionsList
return functionList
def remove_tabu_functions(filesAndFunctions, tabuFunctions):
for fileName, fileFunctions in filesAndFunctions.iteritems():
for tabuFunction in tabuFunctions:
if tabuFunction in fileFunctions:
filesAndFunctions[fileName].remove(tabuFunction)
return filesAndFunctions
files = read_directory(baseDirectory, formsDirectory)
filesAndFunctions = get_function_names(baseDirectory, formsDirectory, files)
filesAndFunctions = remove_tabu_functions(filesAndFunctions, tabuFunctions)
print "starting...\n"
for fileName, fileFunctions in filesAndFunctions.iteritems():
print "file name: " + fileName + " :"
print "functions: "
print fileFunctions
print "******************"
@onurdegerli
Copy link
Author

  • read all files in a given directory and return file list
  • read lines and return function names list with regex
  • remove tabu function names from given list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment