12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import os
  2. import sys
  3. import glob
  4. from xml.etree import ElementTree
  5. # NOTE: this files needs to be in same directory as gitstats executable
  6. # python execution.py <source_folder> <output_folder>
  7. def generateGitstatsOnFolders ():
  8. # root location
  9. source_folder = sys.argv[1]
  10. # final destination
  11. output_folder_path = sys.argv[2]
  12. print (source_folder)
  13. dirs_name=[]
  14. subdir_name=''
  15. for subdir, dirs, files in os.walk(source_folder):
  16. dirs_name=dirs
  17. subdir_name=subdir
  18. # weirdly keeps looping...
  19. break;
  20. # print (dirs_name)
  21. for directory in dirs_name:
  22. fullPath=(os.path.join(subdir_name, directory))
  23. os.system("./gitstats "+fullPath+" "+output_folder_path+"/"+directory)
  24. def gitDirectoryExists(path):
  25. '''Checks if .git directory exists in <path> directory
  26. Returns True if there is .git directory, else False
  27. '''
  28. assert (os.path.isdir(path)), "This directory doesnt exist!"
  29. search_path=os.path.join(path,".git")
  30. pos_git_directory = glob.glob(search_path)
  31. print ("\nSearching for .git directories in %s" %(path))
  32. if pos_git_directory==[search_path]:
  33. print ("\n.git Directory found at %s" %(search_path) )
  34. return True
  35. else:
  36. print ("\nNo .git directory found in %s" %(path) )
  37. return False
  38. def parseXML(manifestPath):
  39. '''Parse manifest.xml and return and array of git repos'''
  40. with open(manifestPath, 'rt') as f:
  41. tree = ElementTree.parse(f)
  42. gitPaths=[]
  43. for node in tree.iter('project'):
  44. git_path = node.attrib.get('path')
  45. print (git_path)
  46. gitPaths.append(git_path)
  47. for path in gitPaths:
  48. runGitstats(path, "bleh")
  49. def runGitstats(pathsArr):
  50. ''' Runs gitstats on each of <pathsArr>, into output directory <output>
  51. This file should be in the same directory as the gitstats executable'''
  52. output_dir=sys.argv[2]
  53. for path in pathsArr:
  54. if gitDirectoryExists(path):
  55. os.system("./gitstats "+os.path.join("/home/gschultz/8956n/.repo/projects",path)+" "+output_dir)
  56. os.system("./gitstats " +path)
  57. def repoController(manifest_path):
  58. gitPaths=parseXML(manifest_path)
  59. if __name__ == "__main__":
  60. manifest_location=sys.argv[1]
  61. repoController(manifest_location)
  62. # parseXML()
  63. # gitDirectoryExists("C:\Users\GSCHULTZ\Desktop\gitstats\output")
  64. # generateGitstatsOnFolders()