git_api.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from django.conf import settings
  4. from api.utils.command import list_files_and_folders
  5. from git.repo.base import Repo
  6. from git.repo.fun import is_git_dir
  7. from git.util import join_path
  8. '''
  9. '''
  10. def get_users_folders():
  11. fullpath = join_path(settings.GIT_PATH)
  12. folders = list_files_and_folders(fullpath)
  13. return folders.get('items', [])
  14. '''
  15. '''
  16. def get_repos_paths():
  17. users_folders = get_users_folders()
  18. repos = []
  19. for folder in users_folders:
  20. fullpath = join_path(settings.GIT_PATH, folder)
  21. subfolders = list_files_and_folders(fullpath)
  22. for subfolder in subfolders.get('items', []):
  23. fullpath = join_path(settings.GIT_PATH, folder, subfolder)
  24. if not is_git_dir(fullpath):
  25. continue
  26. repos.append(fullpath)
  27. return repos
  28. '''
  29. '''
  30. def get_odoo_modules_repos_paths():
  31. repos_paths = get_repos_paths()
  32. modules_paths = []
  33. for repo_path in repos_paths:
  34. r = Repo(repo_path)
  35. try:
  36. if '__openerp__.py' in [o.path for o in r.tree()]:
  37. modules_paths.append(repo_path)
  38. except ValueError:
  39. continue
  40. finally:
  41. r.close()
  42. return modules_paths
  43. '''
  44. '''
  45. def get_odoo_modules_repos_names(include_owners=False):
  46. repos_paths = get_odoo_modules_repos_paths()
  47. repos_names = []
  48. for repos_path in repos_paths:
  49. last_slash_index = repos_path.rindex('/')
  50. last_dot_index = repos_path.rindex('.')
  51. name = repos_path[last_slash_index + 1:last_dot_index]
  52. repos_names.append(name)
  53. return repos_names