Source

UnrealMagicOfDoomOhYeah / Create Class Hirarchical Functions and Events.py

import os
ClassExtendsFromHierarchy = dict()
for file in os.listdir(""):
        if os.path.isfile(file) and not ".py" in file:
                className = file.rsplit('.', 1)[0]
                className =className.strip()
                ClassExtendsFromHierarchy[className] = ""
                filepath = os.path.join(os.getcwd(), file)
                openedFile = open(filepath, 'r')
                currentRow = openedFile.readline()
                foundExtendsFrom = False
                while currentRow and foundExtendsFrom == False :
                        currentRow = openedFile.readline()
                        if "extends" in currentRow :
                                startindex = currentRow.find("extends") + len("extends ")
                                extendsFromName = currentRow[startindex:]
                                extendsFromName =extendsFromName.strip();
                                foundExtendsFrom = True
                                if not len(extendsFromName) == 0 :
                                        ClassExtendsFromHierarchy[className] = extendsFromName

classHierarchy = dict()

for item in ClassExtendsFromHierarchy.iteritems() :
        output = item[0]
        extendsFromName = item[1]
        classHierarchy[item[0]] = list()
        classHierarchy[item[0]].append(item[1])
        while Hierarchy.has_key(extendsFromName):
                extendsFromName = Hierarchy[extendsFromName]
                if extendsFromName != "" :
                        output += "->" + extendsFromName
                        classHierarchy[item[0]].append(extendsFromName)


ClassFunctions = dict()

for currentClass in classHierarchy.iteritems() :
        ClassFunctions[currentClass[0]] = list()
        for file in os.listdir(""):
                targetFileName = currentClass[0] +".txt"
                if targetFileName == file:
                        classFile = open(file,'r')
                        classFileCurrentLine = classFile.readline()
                        while classFileCurrentLine  :
                                classFileCurrentLine = classFile.readline()
                                if "function" in classFileCurrentLine or "event" in classFileCurrentLine :
                                        ClassFunctions[currentClass[0]].append(classFileCurrentLine)

for currentClass in ClassFunctions.iteritems() :
        print currentClass[1][0]

##outputFileName = os.path.join("AllFunctions__Output",currentClass[0])
##outputFileName+= "__AllFunctions.txt"
##outputFileName = os.path.join(os.getcwd(),outputFileName)
##print outputFileName



##OutputFolderName = "Class__Output"
##for i in os.listdir(""):
##        if not os.path.isfile(i) and not "__" in i:
##                newpath = i;
##                newpath = newpath + "/Classes"
##                for j in os.listdir(os.path.join(os.getcwd(),newpath)):
##                        fp = os.path.join(os.getcwd(),newpath,j)
##                        FunctionsList = []
##                        EventsList = []
##                        ClassName = ""
##                        if os.path.isfile(fp):
##                                f = open(fp, 'r')
##                                line = f.readline()
##                                classWriten = False
##                                while(line):
##                                        if "/*" in line and "*/" in line :
##                                                line = f.readline()
##                                        elif "//" in line:
##                                                line = f.readline()
##                                        elif "/*" in line and not "*/" in line :
##                                                while not "*/" in line :
##                                                        line = f.readline()                                        
##                                        if not classWriten and "class" in line and not "var" in line and not "*" in line and not '//' in line :
##                                                ClassName = line
##                                                classWriten = True
##                                        elif "function" in line and not "var" in line and not "*" in line and not '//' in line:
##                                                FunctionsList.append(line)
##                                        elif "event" in line and not "var" in line and not "*" in line and not '//' in line:
##                                                EventsList.append(line)
##                                        line = f.readline()
##
##                                EventsList.sort()
##                                FunctionsList.sort()
##
##                                listlength = len(EventsList)
##                                if listlength !=0:
##                                        outputPath = os.path.join(os.getcwd(),OutputFolderName)
##                                        if not os.access(outputPath,os.F_OK):
##                                                os.makedirs(outputPath)
##                                        outputPath = os.path.join(outputPath,j)
##                                        outputPath = outputPath.rsplit('.', 1)[0]
##                                        outputPath += "__Events.txt"
##                                        fileEventsOut = open(outputPath, 'w')
##
##                                        fileLocation = newpath+"/"+j+"\n"
##                                        fileEventsOut.write(fileLocation)
##                                        fileEventsOut.write(ClassName)
##                                        fileEventsOut.write("\n")
##                                        for event in EventsList :
##                                                fileEventsOut.write("    ")
##                                                fileEventsOut.write(event)
##                                        fileEventsOut.close()
##
##                                listlength = len(FunctionsList)
##                                if  listlength != 0:
##                                        outputPath = os.path.join(os.getcwd(),OutputFolderName)
##                                        if not os.access(outputPath,os.F_OK):
##                                                os.makedirs(outputPath)
##                                        outputPath = os.path.join(outputPath,j)
##                                        outputPath = outputPath.rsplit('.', 1)[0]
##                                        outputPath += "__Functions.txt"
##                                        
##                                        fileFunctionsOut = open(outputPath, 'w')
##
##                                        fileLocation = newpath+"/"+j+"\n"
##                                        fileFunctionsOut.write(fileLocation)                                        
##                                        fileFunctionsOut.write(ClassName)
##                                        fileFunctionsOut.write("\n")
##                                        
##                                        for function in FunctionsList :
##                                                fileFunctionsOut.write ("    ")
##                                                fileFunctionsOut.write(function)
##                                        fileFunctionsOut.close()