vaskaloidis
4/21/2015 - 6:46 AM

Python Script to Git Clone each Apelon-VA ISAAC + OCHRE Framework

Python Script to Git Clone each Apelon-VA ISAAC + OCHRE Framework

#! /usr/bin/python
#
# Pull each Apelon-VA Repo
#

import subprocess 
import os

def git(*args):
    return subprocess.Popen(['git'] + list(args), shell=True, stdout=subprocess.PIPE).communicate()[0]

projects = ['va-isaac-parent', 'va-ochre', 'va-isaac-metadata', 'va-isaac-mojo', 'va-newtons-cradle', 'va-logic', 'va-query-service', 'va-solor-goods', 'va-isaac-gui', 'va-expression-service']

for project in projects:
	repoUrl = "https://github.com/Apelon-VA/" + project + ".git"
	gitArgs = ['git', 'clone', repoUrl]

	print("Attempting to clone: " + repoUrl)
	print("GIT Command: ")
	print(list(gitArgs))
	
	output = subprocess.Popen(gitArgs, shell=True, stdout=subprocess.PIPE).communicate()[0]
	# output = git("clone", repoUrl)
	
	# TODO: What is printed when a Git Clone fails, add that to L21
	if "usage: git [--version]" in output: 
		print("GIT COMMAND PROBLEM. Fix the Git Command")
		print(output)
	elif "git error" in output:
		print("GIT ERROR")
		print("GIT ERROR!")
		if output:
			print(output)
		raise Exception("GIT ERROR!")
	else: 
		print("GIT SUCCESS!")
		print(output)
		output = None	
	break

	# Add a hook at the end of the loop to manually create a Eclipse Project in the .project file and import these repos... dope
	
	os.chdir(os.pardir)