Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. import os
  2.  
  3.  
  4. class ModuleDependencies:
  5.  
  6. # zwraca listę wszystkich katalogów w folderze
  7. def get_directory_names(self, path='.'):
  8. list_of_folders = next(os.walk(path))[1]
  9. list_of_folders = [path + '/' + x for x in list_of_folders if x not in ['.idea', 'venv', '__pycache__', '.git']]
  10. return list_of_folders
  11.  
  12. def get_current_filenames_in_directory(self, name_of_curent_directory):
  13. file_names = []
  14. for root, dirs, files in os.walk(name_of_curent_directory):
  15. for file_name in files:
  16. if file_name[-3:] == '.py':
  17. file_names.append(name_of_curent_directory + '/' + file_name)
  18. return file_names
  19.  
  20. def get_relation_names(self, path='.'):
  21. list_nodes = ModuleDependencies().get_directory_names(path)
  22. tmp = []
  23. for dir_name in list_nodes:
  24. current_filenames_in_directory_list = ModuleDependencies().get_current_filenames_in_directory(dir_name)
  25. for current_file in current_filenames_in_directory_list:
  26. if os.path.isfile(current_file):
  27. with open(current_file) as file:
  28. for line in file:
  29. line = line.strip()
  30. if line.startswith("from "):
  31. file_package = line.split(' ')[1].split('.')[0]
  32. if file_package in list_nodes:
  33. if file_package == dir_name:
  34. continue
  35. tmp.append(tuple((dir_name, file_package)))
  36. else:
  37. continue
  38. #
  39. elif line.startswith('def'):
  40. tmp.append(tuple((line.split(' ')[1].split('(')[0], dir_name.split('/')[-1])))
  41. tmp2 = []
  42. for i in tmp:
  43. tmp2.append(tuple((tmp.count(i), i)))
  44. return list(set([i for i in tmp2]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement