Created
June 20, 2013 13:39
-
-
Save onurdegerli/5822754 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 "******************" |
Author
onurdegerli
commented
Jun 20, 2013
- 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