Last active
March 17, 2016 00:35
-
-
Save fkorotkov/78653b0a6a1ce175654d to your computer and use it in GitHub Desktop.
A python script to find abandoned projects in a Git repo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: `python abandoned_projects_finder.py *.gradle` | |
import os | |
import re | |
import sys | |
import subprocess | |
rootdir = os.getcwd() | |
project_file_pattern = re.compile(sys.argv[1]) | |
project_dirs = set() | |
print(rootdir) | |
for root, subFolders, files in os.walk(rootdir): | |
for file in files: | |
if (project_file_pattern.match(file)): | |
project_dirs |= {root} | |
# remove root if presented | |
project_dirs -= {rootdir} | |
print 'Found {} projects!'.format(len(project_dirs)) | |
def found_amount_of_commits(folder): | |
cmd = "git log --format=format:%H --since=24.months -- {folder}".format(folder=folder) | |
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) | |
(output, err) = p.communicate() | |
return len(output.split('\n')) | |
amounts = dict() | |
for index, project_dir in enumerate(project_dirs): | |
sys.stdout.write("\r" + str(index + 1) + "/" + str(len(project_dirs))) | |
sys.stdout.flush() | |
amounts[project_dir] = found_amount_of_commits(project_dir) | |
sys.stdout.write("\r") | |
for project in sorted(amounts, key=amounts.get, reverse=False): | |
print amounts[project], project |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment