Created
July 13, 2016 21:06
-
-
Save marksherman/43519cd53be522e85e694925683965d6 to your computer and use it in GitHub Desktop.
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
#! /usr/bin/env python3 | |
import os | |
import subprocess | |
ingore_users = [] | |
def makeCommit(commit_hash, date_unix, date_ISO): | |
return {'hash' : commit_hash, 'date_unix' : date_unix, 'date_ISO' : date_ISO} | |
# returns a list of commit objects (just some dictionaries), in order, with oldest first, given a git directory. | |
def listCommits(git_dir): | |
result = subprocess.run(["git", 'log', '--reverse', '--format="%H,%ct,%cI"'], stdout=subprocess.PIPE, cwd=git_dir, universal_newlines=True) | |
if(result.returncode == 0): | |
list_of_commits = [] | |
for commit_line in result.stdout.splitlines(): | |
cl = commit_line.split(',') | |
list_of_commits.append( makeCommit(cl[0], cl[1], cl[2]) ) | |
return list_of_commits | |
else: | |
print("Error from git subprocess in listCommits: ", result.returncode) | |
return result.returncode | |
problem_projects = [] | |
# give it a git folder, and a file within it (relative path), and a string to match | |
# returns True if string is in file. | |
# doesFileContain(somegitpath, 'Screen1/form1.json', '"AboutScreen":"MSCSPTemperatureActivity"') | |
# can be used to filter for specific projects | |
def doesFileContain(git_dir, file_in_git, string_to_match): | |
thisfile = os.path.join(git_dir, file_in_git) | |
try: | |
file = open(thisfile) | |
except OSError: | |
problem_projects.append({'attempted':thisfile, 'ls':os.listdir(git_dir)}) | |
return "Error in doesFileContain tryig to open " + thisfile | |
contents = file.read() | |
file.close() | |
return string_to_match in contents | |
# test if git repo is MSP Temperature activity | |
def isTemperatureActivity(git_dir): | |
return doesFileContain(git_dir, 'Screen1/form.json', '"AboutScreen":"MSCSPTemperatureActivity"') | |
# test if a git repo is MSP Debugging activity | |
def isDebuggingActivity(git_dir): | |
return doesFileContain(git_dir, 'Screen1/form.json', '"AboutScreen":"MSDEBUGACTIVITY"') | |
# Find all users in the database, store as variable users | |
def isUserDir(basefolder, udir): | |
return os.path.isdir(os.path.join(basefolder, udir)) | |
# walk through all the users and all of their projects | |
def walkAllProjectsIn(folder): | |
userFiles = os.path.abspath(folder) | |
users = [user for user in os.listdir(userFiles) if isUserDir(folder, user) if user not in ingore_users] | |
for user in users: | |
dirs_in_user = [d for d in os.listdir(os.path.join(userFiles, user))] | |
#print(user) | |
for repo in dirs_in_user: | |
repo_dir = os.path.join(userFiles, user, repo) | |
# in the git repo! | |
#print(subprocess.run(["git", "status"])) | |
#print(subprocess.run(["git", "status"], stdout=subprocess.PIPE, cwd=repo_dir, universal_newlines=True).stdout) | |
#listCommits(repo_dir) | |
if(isDebuggingActivity(repo_dir)): | |
print(repo_dir) | |
if(len(problem_projects)>0): | |
print(problem_projects) | |
print("The above projects gave errors during doesFileContain") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment