Esempio n. 1
0
def update_given_file_only(current_list, path, rootDirectory, file, given_buffer_data):
    '''
    Same as iterate all on given path except this function iterates trough
    given buffer and appends these results to the output - especially useful
    since user might change stuff and then he wants correct feedback.
    '''

    finalRes = current_list
    
    data = buffer_to_string(given_buffer_data)
    lexer = python_lexer.PythonLexer()
    lexer.input(data)
    
    res = python_parser.parse_data(data,lexer)
    defAndClass = utils.node_to_defs(res)
    
    if defAndClass is not None:
        for item in defAndClass:
            checkExistence = findDictByKeyInListOfDicts(item[0], finalRes)
            if checkExistence is None:
                curLocation = path[path.rfind(rootDirectory):]
                newItem = { item[0] : (item[1], str(curLocation)+'/'+str(file))}
                finalRes.append(newItem)
            else:
                finalRes.remove(checkExistence)
                oldValue = checkExistence[item[0]]
                curLocation = path[path.rfind(rootDirectory):]
                if not str(curLocation)+'/'+str(file) in oldValue[1]:
                    newValue = (item[1], oldValue[1] + ','+ str(curLocation)+'/'+str(file))
                else:
                    newValue = (item[1], oldValue[1])
                     
                newItem = { item[0] : newValue}
                finalRes.append(newItem)
    return finalRes
Esempio n. 2
0
def iterate_all_on_given_path(path, rootDirectory, extension='.py'):
    '''
    Function iterates recursively trough all .py files under given root directory and 
    appends results to the list
    '''
    finalRes = []
    f = []
    d = []
    for (dirpath, dirnames, filenames) in os.walk(path):
        f.extend(filenames)
        d.extend(dirnames)
        break

    #Recursively call this function on all subdirectories
    for dir in d:
        recursiveOutput = iterate_all_on_given_path(path + '/' + str(dir),
                                                    rootDirectory)
        for item in recursiveOutput:
            finalRes.append(item)

    #Iterate all .py files in f
    for file in f:
        if str(file).endswith(extension):
            try:
                myfile = open(path + '/' + str(file))

                data = myfile.read()
                lexer = python_lexer.PythonLexer()
                lexer.input(data)

                res = python_parser.parse_data(data, lexer)
                defAndClass = utils.node_to_defs(res)

                if defAndClass is not None:
                    for item in defAndClass:
                        checkExistence = findDictByKeyInListOfDicts(
                            item[0], finalRes)
                        if checkExistence is None:
                            curLocation = path[path.rfind(rootDirectory):]
                            newItem = {
                                item[0]:
                                (item[1], str(curLocation) + '/' + str(file))
                            }
                            finalRes.append(newItem)
                        else:
                            finalRes.remove(checkExistence)
                            oldValue = checkExistence[item[0]]
                            curLocation = path[path.rfind(rootDirectory):]
                            newValue = (item[1], oldValue[1] + ',' +
                                        str(curLocation) + '/' + str(file))
                            newItem = {item[0]: newValue}
                            finalRes.append(newItem)
            except Exception as error:
                #print("Iterate error "+str(error))
                pass
    return finalRes
Esempio n. 3
0
def iterate_all_on_given_path(path, rootDirectory, extension = '.py'):
    '''
    Function iterates recursively trough all .py files under given root directory and 
    appends results to the list
    '''
    finalRes = []
    f = []
    d = []
    for (dirpath, dirnames, filenames) in os.walk(path):
        f.extend(filenames)
        d.extend(dirnames)
        break
    
    #Recursively call this function on all subdirectories
    for dir in d:
        recursiveOutput = iterate_all_on_given_path(path+'/'+str(dir), rootDirectory)
        for item in recursiveOutput: 
            finalRes.append(item)
    
    #Iterate all .py files in f    
    for file in f:
        if str(file).endswith(extension):
            try:
                myfile = open(path + '/' + str(file))
                
                data = myfile.read()
                lexer = python_lexer.PythonLexer()
                lexer.input(data)
                
                res = python_parser.parse_data(data,lexer)
                defAndClass = utils.node_to_defs(res)
                
                if defAndClass is not None:
                    for item in defAndClass:
                        checkExistence = findDictByKeyInListOfDicts(item[0], finalRes)
                        if checkExistence is None:
                            curLocation = path[path.rfind(rootDirectory):]
                            newItem = { item[0] : (item[1], str(curLocation)+'/'+str(file))}
                            finalRes.append(newItem)
                        else:
                            finalRes.remove(checkExistence)
                            oldValue = checkExistence[item[0]]
                            curLocation = path[path.rfind(rootDirectory):]
                            newValue = (item[1], oldValue[1] + ','+ str(curLocation)+'/'+str(file))
                            newItem = { item[0] : newValue}
                            finalRes.append(newItem)
            except Exception as error:
                #print("Iterate error "+str(error))
                pass
    return finalRes
Esempio n. 4
0
def setup_test(test, filename):
    print("--------------------", test)
    f = open('inf/parsing/' + filename)
    data = f.read()
    f.close()
    gl = {}
    lc = {}
    lexer = python_lexer.PythonLexer()
    lexer.input(data)
    res = parser.parse_data(data, lexer)

    code = utils.node_to_str(res)
    anotherTest = utils.node_to_defs(res)
    test.gl = gl
    test.lc = lc
    test.code = code
    test.node = res
Esempio n. 5
0
def setup_test(test, filename):
    print("--------------------",test)
    f = open('inf/parsing/'+filename)
    data = f.read()
    f.close()
    gl={}
    lc={}
    lexer = python_lexer.PythonLexer()
    lexer.input(data)
    res=parser.parse_data(data, lexer)
    
    code=utils.node_to_str(res)
    anotherTest = utils.node_to_defs(res)
    test.gl=gl
    test.lc=lc
    test.code=code
    test.node=res
Esempio n. 6
0
def update_given_file_only(current_list, path, rootDirectory, file,
                           given_buffer_data):
    '''
    Same as iterate all on given path except this function iterates trough
    given buffer and appends these results to the output - especially useful
    since user might change stuff and then he wants correct feedback.
    '''

    finalRes = current_list

    data = buffer_to_string(given_buffer_data)
    lexer = python_lexer.PythonLexer()
    lexer.input(data)

    res = python_parser.parse_data(data, lexer)
    defAndClass = utils.node_to_defs(res)

    if defAndClass is not None:
        for item in defAndClass:
            checkExistence = findDictByKeyInListOfDicts(item[0], finalRes)
            if checkExistence is None:
                curLocation = path[path.rfind(rootDirectory):]
                newItem = {
                    item[0]: (item[1], str(curLocation) + '/' + str(file))
                }
                finalRes.append(newItem)
            else:
                finalRes.remove(checkExistence)
                oldValue = checkExistence[item[0]]
                curLocation = path[path.rfind(rootDirectory):]
                if not str(curLocation) + '/' + str(file) in oldValue[1]:
                    newValue = (item[1], oldValue[1] + ',' + str(curLocation) +
                                '/' + str(file))
                else:
                    newValue = (item[1], oldValue[1])

                newItem = {item[0]: newValue}
                finalRes.append(newItem)
    return finalRes