Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import glob
- import inspect
- # Historyjka 2: Jako programista chcę zobaczyć graf relacji między funkcjami/metodami w podanym kodzie źródłowym,
- # w celu analizy zależności w kodzie źródłowym.
- class MethodsDependencies:
- def methods_list_from_file(self, file_path):
- def_lines = []
- py_files_path = glob.glob(file_path + '/' + '**/*.py', recursive=True)
- #print(py_files_path)
- # ścieżki plików .py które trzeba przeszukać
- for py_files in py_files_path:
- with open(py_files) as file:
- for line in file:
- line = line.strip()
- if line.startswith("def "):
- def_lines.append(line)
- #print(def_lines)
- # całe linie które zaczynają sie na "def"
- methods_list = []
- for d_line in def_lines:
- tmp = d_line.split()
- method_name = tmp[1].split("(")[0]
- methods_list.append(method_name)
- #print(methods_list)
- # nazwy wszystkich metod w naszym projekcie
- return methods_list
- def funkcja2(self, methods_list, file_path):
- methods_code = []
- py_files_path = glob.glob(file_path + '/' + '**/*.py', recursive=True)
- for py_files in py_files_path:
- with open(py_files) as file:
- def_lines = []
- tmp_methods_in_file = []
- for line in file:
- line = line.strip()
- if line.startswith("def "):
- def_lines.append(line)
- methods_list = []
- for d_line in def_lines:
- tmp = d_line.split()
- method_name = tmp[1].split("(")[0]
- methods_list.append(method_name)
- tmp_methods_in_file.append(method_name)
- for methods in tmp_methods_in_file:
- tmp = inspect.getsource(methods)
- methods_code.append(tmp)
- path = "C:/Users/Kuba/Desktop/GitHub/dependency_diagrams"
- test1 = MethodsDependencies()
- method_list1 = test1.methods_list_from_file(path)
- test1.funkcja2(method_list1, path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement