Skip to content

Instantly share code, notes, and snippets.

Created July 13, 2016 21:06
Show Gist options
  • Save marksherman/43519cd53be522e85e694925683965d6 to your computer and use it in GitHub Desktop.
Save marksherman/43519cd53be522e85e694925683965d6 to your computer and use it in GitHub Desktop.
#! /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 =["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
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)
file = open(thisfile)
except OSError:
problem_projects.append({'attempted':thisfile, 'ls':os.listdir(git_dir)})
return "Error in doesFileContain tryig to open " + thisfile
contents =
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))]
for repo in dirs_in_user:
repo_dir = os.path.join(userFiles, user, repo)
# in the git repo!
#print(["git", "status"]))
#print(["git", "status"], stdout=subprocess.PIPE, cwd=repo_dir, universal_newlines=True).stdout)
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