Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. import glob
  2. import inspect
  3.  
  4.  
  5. # Historyjka 2: Jako programista chcę zobaczyć graf relacji między funkcjami/metodami w podanym kodzie źródłowym,
  6. # w celu analizy zależności w kodzie źródłowym.
  7.  
  8. class MethodsDependencies:
  9.  
  10. def methods_list_from_file(self, file_path):
  11.  
  12. def_lines = []
  13. py_files_path = glob.glob(file_path + '/' + '**/*.py', recursive=True)
  14.  
  15. #print(py_files_path)
  16. # ścieżki plików .py które trzeba przeszukać
  17.  
  18.  
  19. for py_files in py_files_path:
  20. with open(py_files) as file:
  21. for line in file:
  22. line = line.strip()
  23. if line.startswith("def "):
  24. def_lines.append(line)
  25.  
  26. #print(def_lines)
  27. # całe linie które zaczynają sie na "def"
  28.  
  29. methods_list = []
  30.  
  31. for d_line in def_lines:
  32. tmp = d_line.split()
  33. method_name = tmp[1].split("(")[0]
  34. methods_list.append(method_name)
  35.  
  36. #print(methods_list)
  37. # nazwy wszystkich metod w naszym projekcie
  38.  
  39. return methods_list
  40.  
  41.  
  42.  
  43.  
  44.  
  45. def funkcja2(self, methods_list, file_path):
  46.  
  47. methods_code = []
  48.  
  49. py_files_path = glob.glob(file_path + '/' + '**/*.py', recursive=True)
  50.  
  51.  
  52. for py_files in py_files_path:
  53. with open(py_files) as file:
  54.  
  55. def_lines = []
  56. tmp_methods_in_file = []
  57.  
  58. for line in file:
  59. line = line.strip()
  60. if line.startswith("def "):
  61. def_lines.append(line)
  62.  
  63. methods_list = []
  64.  
  65. for d_line in def_lines:
  66. tmp = d_line.split()
  67. method_name = tmp[1].split("(")[0]
  68. methods_list.append(method_name)
  69. tmp_methods_in_file.append(method_name)
  70.  
  71. for methods in tmp_methods_in_file:
  72. tmp = inspect.getsource(methods)
  73. methods_code.append(tmp)
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. path = "C:/Users/Kuba/Desktop/GitHub/dependency_diagrams"
  83. test1 = MethodsDependencies()
  84. method_list1 = test1.methods_list_from_file(path)
  85. test1.funkcja2(method_list1, path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement