Module: Copernicium::PushPull
- Included in:
- Driver
- Defined in:
- lib/pushpull.rb
Class Method Summary collapse
-
.connect ⇒ Object
Function: connect().
-
.connection_failure(str = '', err = '') ⇒ Object
tell user to set up their ssh keys.
-
.fetch ⇒ Object
Function: fetch().
-
.pclone ⇒ Object
Function: clone().
-
.ppull ⇒ Object
Function: ppull().
-
.ppush ⇒ Object
Function: ppush().
-
.transfer ⇒ Object
Function: transfer().
- .UICommandParser(comm) ⇒ Object
Class Method Details
.connect ⇒ Object
Function: connect()
Description:
a net/ssh wrapper, if given a block will execute block on server,
otherwise tests connection.
63 64 65 66 67 68 69 70 |
# 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 = '') ⇒ Object
tell user to set up their ssh keys
47 48 49 50 51 52 53 54 55 56 |
# 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 ⇒ Object
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
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# 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 ⇒ Object
Function: clone()
Description:
Grabs a repository from a remote server
77 78 79 80 81 82 83 |
# 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 ⇒ Object
Function: ppull()
Description:
pulls remote changes to the current branch from remote branch
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# 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 ⇒ Object
Function: ppush()
Description:
pushes local changes on the current branch to a remote branch
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# 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 ⇒ Object
Function: transfer()
Description:
a net/scp wrapper to copy to server
90 91 92 93 94 95 96 97 |
# 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 |
.UICommandParser(comm) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 |