Skip to content

Instantly share code, notes, and snippets.

@Mongey
Created October 20, 2012 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mongey/3923969 to your computer and use it in GitHub Desktop.
Save Mongey/3923969 to your computer and use it in GitHub Desktop.
CS3071 Compiler Upload / Compile Script
#!/usr/bin/env ruby
# ______ _ _
# | ___ \ (_) |
# | |_/ /_ __ ___ _ __ _| | ___ _ __
# | ___ \ '__/ _ \| '_ \| | |/ _ \ '__|
# | |_/ / | | (_) | |_) | | | __/ |
# \____/|_| \___/| .__/|_|_|\___|_|
# | |
# |_|
require 'net/scp'
puts "Uploading files"
username = "user"
password = "pass"
# Establish the SSH session
ssh = Net::SSH.start("macneill.scss.tcd.ie", username, :password => password, :port => 22)
#
# # Use that session to generate an SCP object
scp = ssh.scp
#
# Download the file and run the code block each time a new chuck of data is received
scp.upload!(Dir.pwd, "users/ugrad/#{username}/bropiler", :recursive => true) do |ch, name, received, total|
#
# Calculate percentage complete and format as a two-digit percentage
percentage = format('%.2f', received.to_f / total.to_f * 100) + '%'
#
# Print on top of (replace) the same line in the terminal
# - Pad with spaces to make sure nothing remains from the previous output
# - Add a carriage return without a line feed so the line doesn't move down
print "Saving to #{name}: Received #{received} of #{total} bytes" + " (#{percentage}) \r"
# Print the output immediately - don't wait until the buffer fills up
STDOUT.flush
end
puts "Upload complete!"
puts "Compiling"
result = ssh.exec!('cd /users/ugrad/#{username}/bropiler/taste; cococs Taste.ATG -namespace Taste; mono-csc Taste.cs Scanner.cs Parser.cs SymTab.cs CodeGen.cs; ./Taste.exe Test.TAS')
puts result
puts "DONE"
@Mongey
Copy link
Author

Mongey commented Oct 20, 2012

To run

  • Download it as upload.rb
  • mv upload.rb ~/college/cs3071/compilolz/upload
  • cd ~/college/cs3071/compilolz/
  • chmod a+x upload
  • set username and password
  • all code should be in ~/college/cs3071/compilolz/taste
  • ./upload

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment