Created
October 19, 2012 12:55
-
-
Save petehamilton/3918104 to your computer and use it in GitHub Desktop.
Imperial College Computing UTA Helper Script
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/ruby | |
# Recommend saving (or symlinking) as /usr/bin/uta-helper | |
################################################################################ | |
# | |
# Simple ruby script to pull down student code for excercises from labranch | |
# | |
# Example: $ uta-helper pull -e html | |
# Will clone all the repos into a 'respositories' directory by default. | |
# If they already exist they will be pulled/updated. | |
# | |
# I recommend setting up SSH auth to prevent having to type your password for | |
# every repo pull/clone | |
# | |
# TODO: Pull tutee repos as branches of one single local repo (maybe nicer) | |
# TODO: Curl PDF Specs as well | |
# TODO: Curl Model Answer and Specification | |
# TODO: Pull down all of the above files into the following structure: | |
# repositories | |
# | excercise_login | |
# specification.pdf | |
# model_answer.pdf | |
# TODO: Method to diff files in all repos with the initial commits | |
# e.g uta-helper diff Tests.hs would show all Tests.hs files for each tutee | |
# diffed with the original Tris-Commit. | |
# | |
# Hacked together by Peter Hamilton (peh10), feel free to add to this :) | |
# | |
################################################################################ | |
################################################################################ | |
# Settings | |
################################################################################ | |
STUDENT_LOGINS = ["login1", "login2"] | |
UTA_LOGIN = "peh10" | |
################################################################################ | |
require 'optparse' | |
# Extend string to check for numbers (for pulling specs/results later) | |
class String | |
def is_numeric? | |
begin Float(self) ; true end rescue false | |
end | |
end | |
class UTAHelper | |
def initialize(options = {}) | |
@uta_login = options[:uta_login] | |
@exercise = options[:exercise] || nil | |
@student_logins = options[:student_logins] | |
@output_directory = options[:output_directory] | |
end | |
def pull_git_repos | |
if @exercise.nil? | |
puts "Please provide an exercise using the -e flag" | |
exit | |
end | |
puts "Pulling down git respoitories into #{@output_directory}" | |
@student_logins.each do |student_login| | |
git_dir = "#{@output_directory}/#{@exercise}_#{student_login}" | |
pulled = system(" | |
git --git-dir=#{git_dir}/.git fetch > /dev/null 2>&1 | |
git --git-dir=#{git_dir}/.git --work-tree=#{git_dir} merge origin/master > /dev/null 2>&1 | |
") | |
if $? == 0 | |
puts "Pulled #{student_login}'s code" | |
else | |
system("git clone ssh://#{@uta_login}@labranch.doc.ic.ac.uk:10022/lab/#{student_login}/1213/#{@exercise} #{git_dir} > /dev/null 2>&1") | |
if $? == 0 | |
puts "Cloned #{student_login}'s #{@exercise} exercise into #{@output_directory}" | |
else | |
puts "Couldn't Pull/Clone #{student_login}'s #{@exercise} exercise into #{@output_directory}" | |
end | |
end | |
end | |
end | |
end | |
if ARGV.length < 1 | |
puts "Usage: uta-helper [pull] [options]" | |
exit | |
end | |
cmd = ARGV.shift | |
options = {} | |
opts = OptionParser.new do |opts| | |
opts.banner = "Usage: uta-helper [pull] [options]" | |
opts.on('-u', '--uta-login LOGIN', 'UTA login e.g peh10') { |v| options[:uta_login] = v } | |
opts.on('-e', '--exercise EXERCISE', 'e.g recursion, 9 (depending on task)') { |v| options[:exercise] = v } | |
opts.on('-l', '--student-logins LOGINS', 'Student logins e.g peh10,st809') { |v| options[:student_logins] = v } | |
opts.on('-d', '--directory DIR', 'Output directory') { |v| options[:output_directory] = v } | |
end | |
begin | |
opts.parse!(ARGV) | |
rescue => e | |
puts e.message.capitalize | |
puts opts | |
exit 1 | |
end | |
options[:student_logins] ||= STUDENT_LOGINS | |
options[:uta_login] ||= UTA_LOGIN | |
options[:output_directory] ||= "repositories" | |
begin | |
Dir::mkdir(options[:output_directory]) | |
rescue | |
end | |
helper = UTAHelper.new options | |
case cmd | |
when "pull" then helper.pull_git_repos | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment