copernicium 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pushpull.rb +65 -70
  3. data/lib/ui.rb +23 -56
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd3e9247c74ce89252cccb9a53e801ffed973358
4
- data.tar.gz: eb9c7868a7271ad1b679edea4532f5c1dac3265f
3
+ metadata.gz: fd169e6af9efa888468a19d10ad6f35d24dbb73f
4
+ data.tar.gz: cd05372657960e8983bbffc8d8a0a754be1176a8
5
5
  SHA512:
6
- metadata.gz: 22c2ad848204714087cc28d43cac3608dbeed48a874b1b47f287d68200a5fbc9436d7305909cb0d923e35d2600b5912103dde8bf832f7f384aab4ff3929e45c8
7
- data.tar.gz: a5780ed3510d641f84ca8d80e9ef6573f65636ccdb91e9b8ff8f75f3f0a652d986acc0f9742f2134140dd6321f5c777caf452478a001d01b0defc7f13ca02337
6
+ metadata.gz: 089e0411d8b921641843ce1e4baca1fb07f6f25f28cb31825d63c18f008c8205e29e9ff87cd0a58249b5d37d0d7b684f00060118d9b72f68002638a802edce13
7
+ data.tar.gz: 8bbadc0b3ca53af1fa3d65475081594732a101667e20cf06df03e159039ed1d22a3f1bea6c604f82d9d9201f9adae2b14e93f4be86d61e28e1a105d47fdd0c83
data/lib/pushpull.rb CHANGED
@@ -9,25 +9,24 @@
9
9
  # Clone - cn clone <user> <repo.host:/dir/of/repo>
10
10
  # assumes that the user has ssh keys to the remote server setup
11
11
 
12
+
12
13
  module Copernicium
13
14
  include Workspace
14
15
  module PushPull
15
- # Fields in UIComm and what they are for me:
16
- # @opts - user
17
- # @repo - repo.host:/path/to/repo
18
- # @repo - :/path/to/repo
19
- # @rev - branch name
20
16
  def PushPull.UICommandParser(comm)
21
17
  # handle parsing out remote info
18
+ # @opts - user
19
+ # @repo - repo.host:/path/to/repo
20
+ # OR /path/to/repo
22
21
  remote = comm.repo.split(':')
23
22
  if remote.length == 2
24
23
  @@host = remote[0]
25
24
  @@path = remote[1]
26
25
  elsif remote.length == 1
27
26
  @@host = "cycle3.csug.rochester.edu"
28
- @@path = remote[0].sub!(/^:/, '')
27
+ @@path = remote.first
29
28
  else
30
- raise 'Remote host information not given'.red
29
+ raise 'Remote host information not given.'.red
31
30
  end
32
31
 
33
32
  @@user = comm.opts
@@ -46,9 +45,12 @@ module Copernicium
46
45
  end
47
46
 
48
47
  # tell user to set up their ssh keys
49
- def connection_failure(str = '')
48
+ def PushPull.connection_failure(str = '')
50
49
  puts "Connection error while: ".red + str
51
50
  puts "Make sure SSH keys are setup.".yel
51
+ puts "User: ".yel + @@user
52
+ puts "Host: ".yel + @@host
53
+ puts "Path: ".yel + @@path
52
54
  false
53
55
  end
54
56
 
@@ -57,25 +59,33 @@ module Copernicium
57
59
  # Description:
58
60
  # a net/ssh wrapper, if given a block will execute block on server,
59
61
  # otherwise tests connection.
60
- #
61
- # remote: the remote server, formatted "my.server"
62
- # user: the user to connect as
63
62
  def PushPull.connect
64
63
  begin
65
- Net::SSH.start(@@host, @@user) { |scp| yield scp }
64
+ Net::SSH.start(@@host, @@user) { |ssh| yield ssh }
66
65
  true
67
66
  rescue
68
67
  connection_failure 'trying to execute a command'
69
68
  end
70
69
  end
71
70
 
71
+
72
+ # Function: clone()
73
+ #
74
+ # Description:
75
+ # Grabs a repository from a remote server
76
+ def PushPull.clone
77
+ begin
78
+ PushPull.fetch
79
+ rescue
80
+ connection_failure 'trying to clone a repo'
81
+ end
82
+ end
83
+
84
+
72
85
  # Function: transfer()
73
86
  #
74
87
  # Description:
75
88
  # a net/scp wrapper to copy to server
76
- #
77
- # remote: the remote server and directory to pull from, formatted "my.server"
78
- # user: the user to connect as
79
89
  def PushPull.transfer
80
90
  begin
81
91
  Net::SCP.start(@@host, @@user) { |scp| yield scp }
@@ -85,22 +95,19 @@ module Copernicium
85
95
  end
86
96
  end
87
97
 
98
+
88
99
  # Function: fetch()
89
100
  #
90
101
  # Description:
91
102
  # a net/scp wrapper to copy from server, can take a block or do a one-off copy without one
92
103
  #
93
- # remote: the remote server and directory to push to, formatted "my.server:/the/location/we/want"
94
- # dest: what we want of the branch, not needed for blocked calls
95
104
  # local: where we want to put the file, not needed for blocked calls
96
- # user: the user to connect as
97
105
  def PushPull.fetch(local = Dir.pwd, &block)
98
106
  if block.nil? # we are cloning a repo in this section of code
99
107
  begin
100
108
  Net::SCP.start(@@host, @@user) do |scp|
101
- scp.download!(@@path, local, :recursive => true)
109
+ scp.download! @@path, local, :recursive => true
102
110
  end
103
- true
104
111
  rescue # no ssh keys are setup, die
105
112
  connection_failure 'trying to copy a file'
106
113
  end
@@ -108,39 +115,41 @@ module Copernicium
108
115
  else # fetch more than one file or folder
109
116
  begin
110
117
  Net::SCP.start(@@host, @@user) { |scp| yield scp }
111
- true
112
118
  rescue
113
119
  connection_failure "trying to fetch files"
114
120
  end
115
121
  end
122
+ true
116
123
  end
117
124
 
125
+
118
126
  # Function: push()
119
127
  #
120
128
  # Description:
121
129
  # pushes local changes on the current branch to a remote branch
122
- #
123
- # remote: the remote server and directory to push to, formatted "my.server:/the/location/we/want"
124
- # branch: the branch that we are pushing to
125
- # user: the user to connect as
126
130
  def PushPull.push
127
- transfer do |session|
128
- # uploading our history to remote
129
- session.upload!("#{Dir.pwd}/.cn/history",
130
- "#{@@path}/.cn/merging_#{@@user}")
131
-
132
- # uploading our .cn info to remote
133
- %w{revs snap}.each do |file|
134
- session.upload!("#{Dir.pwd}/.cn/#{file}",
135
- "#{@@path}/.cn/#{file}",
136
- :recursive => true)
137
- end
138
- end # session
131
+ begin
132
+ transfer do |ssh|
133
+ # uploading our history to remote
134
+ ssh.upload!("#{Dir.pwd}/.cn/history",
135
+ "#{@@path}/.cn/merging_#{@@user}")
136
+
137
+ # uploading our .cn info to remote
138
+ %w{revs snap}.each do |file|
139
+ ssh.upload!("#{Dir.pwd}/.cn/#{file}/",
140
+ "#{@@path}/.cn/#{file}/",
141
+ :recursive => true)
142
+ end
143
+ end # ssh
139
144
 
140
- connect do |session|
141
- session.exec!("cd #{@@path}")
142
- puts session.exec!("cn update #{@@user}")
145
+ connect do |ssh|
146
+ ssh.exec! "cd #{@@path}"
147
+ puts ssh.exec! "cn update #{@@user}"
148
+ end
149
+ rescue
150
+ connection_failure "trying to push files"
143
151
  end
152
+ true
144
153
  end
145
154
 
146
155
 
@@ -149,40 +158,26 @@ module Copernicium
149
158
  # Description:
150
159
  # pulls remote changes to the current branch from remote branch
151
160
  #
152
- # remote: the remote server and directory to push to, formatted "my.server:/the/location/we/want"
153
- # branch: the branch that we are pushing to
154
- # user: the user to connect as
155
161
  def PushPull.pull
156
- fetch do |session|
157
- # uploading our history to remote
158
- session.download!("#{@@path}/.cn/merging_#{@@user}",
159
- "#{Dir.pwd}/.cn/history")
160
-
161
- # uploading our .cn info to remote
162
- %w{revs snap}.each do |file|
163
- session.download!("#{@@path}/.cn/#{file}",
164
- "#{Dir.pwd}/.cn/#{file}",
165
- :recursive => true)
166
- end
167
- end
168
- system "cn update", @@user
169
- puts "Remote #{@@repo} pulled.".grn
170
- end
171
-
172
-
173
- # Function: clone()
174
- #
175
- # Description:
176
- # Grabs a repository from a remote server
177
- #
178
- # remote: the remote server and directory to push to, formatted "my.server:/the/location/we/want"
179
- # user: the user to connect as
180
- def PushPull.clone
181
162
  begin
182
- PushPull.fetch
163
+ fetch do |session|
164
+ # uploading our history to remote
165
+ session.download!("#{@@path}/.cn/merging_#{@@user}",
166
+ "#{Dir.pwd}/.cn/history")
167
+
168
+ # uploading our .cn info to remote
169
+ %w{revs snap}.each do |file|
170
+ session.download!("#{@@path}/.cn/#{file}",
171
+ "#{Dir.pwd}/.cn/#{file}",
172
+ :recursive => true)
173
+ end
174
+ end
175
+ system "cn update", @@user
176
+ puts "Remote pulled: ".grn + @@host + @@path
183
177
  rescue
184
- connection_failure 'trying to clone a repo'
178
+ connection_failure "trying to pull files"
185
179
  end
180
+ true
186
181
  end
187
182
  end
188
183
  end
data/lib/ui.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # user interface module - parse and execute commands
2
2
  # integrates all modules, central module
3
3
 
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
 
6
6
  module Copernicium
7
7
  # Communication object that will pass commands to backend modules
@@ -172,54 +172,34 @@ module Copernicium
172
172
  end
173
173
  end
174
174
 
175
- def push(args)
176
- # Command usage is:
177
- # cn push <user> <repo.host:/dir/of/repo> <branch-name>
178
- #
179
- # If username not given, get it from the user.
180
- user = args[0]
181
- if user.nil?
182
- user = get "username for push"
183
- # Make sure username is the first arg, since PushPull is expecting this.
184
- args << user
185
- end
186
-
187
- remote = args[1]
188
- remote = get "remote path to push to (format: <repo.host:/dir/of/repo>)" if remote.nil?
189
-
190
- branchname = args[2]
191
- branchname = get "remote branch to push to" if branchname.nil?
192
-
193
- comm = UIComm.new(command: 'push', opts: args, repo: remote, rev: branchname)
194
- # Do the push
175
+ def clone(args)
176
+ user = args.first
177
+ host = args.last
178
+ user = get "username for push" if user.nil?
179
+ host = get "host path (<host:/dir/of/repo>)" if host.nil? || user == host
180
+ comm = UIComm.new(command: 'clone', opts: user, repo: host)
195
181
  PushPull.UICommandParser(comm)
182
+ return comm
183
+ end
196
184
 
197
- comm
185
+ def push(args)
186
+ user = args.first
187
+ host = args.last
188
+ user = get "username for push" if user.nil?
189
+ host = get "host path (<host:/dir/of/repo>)" if host.nil? || user == host
190
+ comm = UIComm.new(command: 'push', opts: user, repo: host)
191
+ PushPull.UICommandParser(comm)
192
+ return comm
198
193
  end
199
194
 
200
195
  def pull(args)
201
- # Command usage is:
202
- # cn pull <user> <repo.host:/dir/of/repo> <branch-name>
203
- #
204
- # If username not given, get it from the user.
205
- user = args[0]
206
- if user.nil?
207
- user = get "username for pull"
208
- # Make sure username is the first arg, since PushPull is expecting this.
209
- args << user
210
- end
211
-
212
- remote = args[1]
213
- remote = get "remote path to pull from (format: <repo.host:/dir/of/repo>)" if remote.nil?
214
-
215
- branchname = args[2]
216
- branchname = get "remote branch to pull from" if branchname.nil?
217
-
218
- comm = UIComm.new(command: 'pull', opts: args, repo: remote, rev: branchname)
219
- # Do the pull
196
+ user = args.first
197
+ host = args.last
198
+ user = get "username for push" if user.nil?
199
+ host = get "host path (<host:/dir/of/repo>)" if host.nil? || user == host
200
+ comm = UIComm.new(command: 'pull', opts: user, repo: host)
220
201
  PushPull.UICommandParser(comm)
221
-
222
- comm
202
+ return comm
223
203
  end
224
204
 
225
205
  # Take in a revision (snaptshot) id or branch
@@ -251,19 +231,6 @@ module Copernicium
251
231
  ui
252
232
  end
253
233
 
254
- # usage: cn clone <user> <repo.host:/dir/of/repo>
255
- def clone(args)
256
- user = args.shift
257
- user = get "username for clone" if user.nil?
258
-
259
- repo = args.first
260
- repo = get "url to clone (format: <repo.host:/dir/of/repo>)" if repo.nil?
261
-
262
- comm = UIComm.new(command: 'clone', opts: user, repo: repo)
263
- PushPull.UICommandParser(comm)
264
- comm
265
- end
266
-
267
234
  def commit(args)
268
235
  messflag = args.find_index('-m')
269
236
  if messflag.nil?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: copernicium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Team Copernicium