module Copernicium::PushPull
Public Class Methods
UICommandParser(comm)
click to toggle source
# File lib/pushpull.rb, line 15 def PushPull.UICommandParser(comm) # handle parsing out remote info # @opts - user # @repo - repo.host:/path/to/repo # OR /path/to/repo remote = comm.repo.split(':') if remote.length == 2 @@host = remote[0] @@path = remote[1] elsif remote.length == 1 @@host = "cycle1.csug.rochester.edu" @@path = remote.first else raise 'Remote host information not given.'.red end @@user = comm.opts case comm.command when "clone" PushPull.pclone when "push" PushPull.ppush when "pull" PushPull.ppull when 'test' # avoid error while doing unit testing else raise "Error: Invalid command supplied to PushPull".red end end
connect() { |ssh| ... }
click to toggle source
Function: connect()
Description:
a net/ssh wrapper, if given a block will execute block on server, otherwise tests connection.
# File lib/pushpull.rb, line 63 def PushPull.connect begin Net::SSH.start(@@host, @@user) { |ssh| yield ssh } true rescue => error connection_failure 'trying to execute a command', error end end
connection_failure(str = '', err = '')
click to toggle source
tell user to set up their ssh keys
# File lib/pushpull.rb, line 47 def PushPull.connection_failure(str = '', err = '') puts "Make sure SSH keys are setup to the host server.".grn puts "Connection error while: ".red + str puts "Error: ".red + err.to_s puts "Backtrace:\n\t".red + "#{err.backtrace.join("\n\t")}" puts "User: ".yel + @@user puts "Host: ".yel + @@host puts "Path: ".yel + @@path false end
fetch() { |scp| ... }
click to toggle source
Function: fetch()
Description:
a net/scp wrapper to copy from server, can take a block or do a one-off copy without one
local: where we want to put the file, not needed for blocked calls
# File lib/pushpull.rb, line 107 def PushPull.fetch if block_given? # fetch more than one file or folder begin Net::SCP.start(@@host, @@user) { |scp| yield scp } rescue => error connection_failure "trying to fetch files", error end else # no block given, clone the repo begin Net::SCP.start(@@host, @@user) do |scp| scp.download!(@@path, Dir.pwd, :recursive => true) end rescue => error connection_failure 'trying to clone a repo', error end end true end
pclone()
click to toggle source
Function: clone()
Description:
Grabs a repository from a remote server
# File lib/pushpull.rb, line 77 def PushPull.pclone begin PushPull.fetch rescue => error connection_failure 'trying to clone a repo', error end end
ppull()
click to toggle source
Function: ppull()
Description:
pulls remote changes to the current branch from remote branch
# File lib/pushpull.rb, line 164 def PushPull.ppull begin PushPull.fetch do |session| # uploading our history to remote session.download!( "#{@@path}/.cn/history", "#{Dir.pwd}/.cn/merging_#{@@user}") # uploading our .cn info to remote %w{revs snap}.each do |file| session.download!("#{@@path}/.cn/#{file}", "#{Dir.pwd}/.cn/", :recursive => true) end end system "cn update", @@user system "cn checkout head" puts "Remote pulled: ".grn + @@host + @@path rescue => error connection_failure "trying to pull files", error end true end
ppush()
click to toggle source
Function: ppush()
Description:
pushes local changes on the current branch to a remote branch
# File lib/pushpull.rb, line 133 def PushPull.ppush begin PushPull.transfer do |ssh| # uploading our history to remote ssh.upload!("#{Dir.pwd}/.cn/history", "#{@@path}/.cn/merging_#{@@user}") # uploading our .cn info to remote %w{revs snap}.each do |file| ssh.upload!("#{Dir.pwd}/.cn/#{file}/", "#{@@path}/.cn/", :recursive => true) end end # ssh PushPull.connect do |ssh| puts ssh.exec! "cd #{@@path} && cn update #{@@user}" puts ssh.exec! "cd #{@@path} && cn checkout head" end rescue => error connection_failure "trying to push files", error end true end
transfer() { |scp| ... }
click to toggle source
Function: transfer()
Description:
a net/scp wrapper to copy to server
# File lib/pushpull.rb, line 90 def PushPull.transfer begin Net::SCP.start(@@host, @@user) { |scp| yield scp } true rescue => error connection_failure 'trying to upload a file', error end end