copernicium 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pushpull.rb +38 -37
  3. data/lib/ui.rb +10 -8
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd169e6af9efa888468a19d10ad6f35d24dbb73f
4
- data.tar.gz: cd05372657960e8983bbffc8d8a0a754be1176a8
3
+ metadata.gz: 7a5ffa814cbc75d8cef5aa496ae365e64055544f
4
+ data.tar.gz: dcdc64d513fc8d4ab767ca371446fd04897984a8
5
5
  SHA512:
6
- metadata.gz: 089e0411d8b921641843ce1e4baca1fb07f6f25f28cb31825d63c18f008c8205e29e9ff87cd0a58249b5d37d0d7b684f00060118d9b72f68002638a802edce13
7
- data.tar.gz: 8bbadc0b3ca53af1fa3d65475081594732a101667e20cf06df03e159039ed1d22a3f1bea6c604f82d9d9201f9adae2b14e93f4be86d61e28e1a105d47fdd0c83
6
+ metadata.gz: dfa00b3ba05c58cb3c7f5fe99c7c910bc3e3ea09500d1473adaccd50640a11e0c8e554d234d14fb9e3609f09f7e58feb7bbca4d6813500b33c9c7ec37fe2d927
7
+ data.tar.gz: 2c29c875e7dcc63d6e0698e4c6ff414b1fb7806d277ce66718cb2e5a6f7bf7d300d0a8a73b72b2defa9888522894cbdb535489228597e3dfd4bba6f6f1bab1ce
data/lib/pushpull.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # Frank Tamburrino
2
- # CSC 253
2
+ # CSC 254
3
3
  # PushPull Module
4
- # November 6, 2015
4
+ # November 7, 2015
5
5
  #
6
6
  # How to use for Push, Pull and Clone:
7
7
  # Push - cn push <user> <repo.host:/dir/of/repo> <branch-name>
@@ -11,7 +11,6 @@
11
11
 
12
12
 
13
13
  module Copernicium
14
- include Workspace
15
14
  module PushPull
16
15
  def PushPull.UICommandParser(comm)
17
16
  # handle parsing out remote info
@@ -32,11 +31,11 @@ module Copernicium
32
31
  @@user = comm.opts
33
32
  case comm.command
34
33
  when "clone"
35
- clone
34
+ PushPull.pclone
36
35
  when "push"
37
- push
36
+ PushPull.ppush
38
37
  when "pull"
39
- pull
38
+ PushPull.ppull
40
39
  when 'test'
41
40
  # avoid error while doing unit testing
42
41
  else
@@ -45,9 +44,11 @@ module Copernicium
45
44
  end
46
45
 
47
46
  # tell user to set up their ssh keys
48
- def PushPull.connection_failure(str = '')
47
+ def PushPull.connection_failure(str = '', err = '')
48
+ puts "Make sure SSH keys are setup to the host server.".grn
49
49
  puts "Connection error while: ".red + str
50
- puts "Make sure SSH keys are setup.".yel
50
+ puts "Error: ".red + err.to_s
51
+ puts "Backtrace:\n\t".red + "#{err.backtrace.join("\n\t")}"
51
52
  puts "User: ".yel + @@user
52
53
  puts "Host: ".yel + @@host
53
54
  puts "Path: ".yel + @@path
@@ -63,8 +64,8 @@ module Copernicium
63
64
  begin
64
65
  Net::SSH.start(@@host, @@user) { |ssh| yield ssh }
65
66
  true
66
- rescue
67
- connection_failure 'trying to execute a command'
67
+ rescue => error
68
+ connection_failure 'trying to execute a command', error
68
69
  end
69
70
  end
70
71
 
@@ -73,11 +74,11 @@ module Copernicium
73
74
  #
74
75
  # Description:
75
76
  # Grabs a repository from a remote server
76
- def PushPull.clone
77
+ def PushPull.pclone
77
78
  begin
78
79
  PushPull.fetch
79
- rescue
80
- connection_failure 'trying to clone a repo'
80
+ rescue => error
81
+ connection_failure 'trying to clone a repo', error
81
82
  end
82
83
  end
83
84
 
@@ -90,8 +91,8 @@ module Copernicium
90
91
  begin
91
92
  Net::SCP.start(@@host, @@user) { |scp| yield scp }
92
93
  true
93
- rescue
94
- connection_failure 'trying to upload a file'
94
+ rescue => error
95
+ connection_failure 'trying to upload a file', error
95
96
  end
96
97
  end
97
98
 
@@ -102,34 +103,34 @@ module Copernicium
102
103
  # a net/scp wrapper to copy from server, can take a block or do a one-off copy without one
103
104
  #
104
105
  # local: where we want to put the file, not needed for blocked calls
105
- def PushPull.fetch(local = Dir.pwd, &block)
106
- if block.nil? # we are cloning a repo in this section of code
106
+ def PushPull.fetch
107
+ if block_given? # fetch more than one file or folder
107
108
  begin
108
- Net::SCP.start(@@host, @@user) do |scp|
109
- scp.download! @@path, local, :recursive => true
110
- end
111
- rescue # no ssh keys are setup, die
112
- connection_failure 'trying to copy a file'
109
+ Net::SCP.start(@@host, @@user) { |scp| yield scp }
110
+ rescue => error
111
+ connection_failure "trying to fetch files", error
113
112
  end
114
113
 
115
- else # fetch more than one file or folder
114
+ else # no block given, clone the repo
116
115
  begin
117
- Net::SCP.start(@@host, @@user) { |scp| yield scp }
118
- rescue
119
- connection_failure "trying to fetch files"
116
+ Net::SCP.start(@@host, @@user) do |scp|
117
+ scp.download!(@@path, Dir.pwd, :recursive => true)
118
+ end
119
+ rescue => error
120
+ connection_failure 'trying to clone a repo', error
120
121
  end
121
122
  end
122
123
  true
123
124
  end
124
125
 
125
126
 
126
- # Function: push()
127
+ # Function: ppush()
127
128
  #
128
129
  # Description:
129
130
  # pushes local changes on the current branch to a remote branch
130
- def PushPull.push
131
+ def PushPull.ppush
131
132
  begin
132
- transfer do |ssh|
133
+ PushPull.transfer do |ssh|
133
134
  # uploading our history to remote
134
135
  ssh.upload!("#{Dir.pwd}/.cn/history",
135
136
  "#{@@path}/.cn/merging_#{@@user}")
@@ -142,25 +143,25 @@ module Copernicium
142
143
  end
143
144
  end # ssh
144
145
 
145
- connect do |ssh|
146
+ PushPull.connect do |ssh|
146
147
  ssh.exec! "cd #{@@path}"
147
148
  puts ssh.exec! "cn update #{@@user}"
148
149
  end
149
- rescue
150
- connection_failure "trying to push files"
150
+ rescue => error
151
+ connection_failure "trying to push files", error
151
152
  end
152
153
  true
153
154
  end
154
155
 
155
156
 
156
- # Function: pull()
157
+ # Function: ppull()
157
158
  #
158
159
  # Description:
159
160
  # pulls remote changes to the current branch from remote branch
160
161
  #
161
- def PushPull.pull
162
+ def PushPull.ppull
162
163
  begin
163
- fetch do |session|
164
+ PushPull.fetch do |session|
164
165
  # uploading our history to remote
165
166
  session.download!("#{@@path}/.cn/merging_#{@@user}",
166
167
  "#{Dir.pwd}/.cn/history")
@@ -174,8 +175,8 @@ module Copernicium
174
175
  end
175
176
  system "cn update", @@user
176
177
  puts "Remote pulled: ".grn + @@host + @@path
177
- rescue
178
- connection_failure "trying to pull files"
178
+ rescue => error
179
+ connection_failure "trying to pull files", error
179
180
  end
180
181
  true
181
182
  end
data/lib/ui.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # user interface module - parse and execute commands
2
2
  # integrates all modules, central module
3
3
 
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
+
6
+ include Copernicium::PushPull
5
7
 
6
8
  module Copernicium
7
9
  # Communication object that will pass commands to backend modules
@@ -21,10 +23,10 @@ module Copernicium
21
23
  end
22
24
  end
23
25
 
24
- # todo - consider refactoring some UIComm usage
25
26
  # main driver for the command line user interface
26
27
  module Driver
27
28
  include Workspace # needed for most high level commands
29
+ include PushPull # needed for most high level commands
28
30
  # Executes the required action for a given user command.
29
31
  #
30
32
  # Parameters:
@@ -53,7 +55,7 @@ module Copernicium
53
55
  if cmd == 'init'
54
56
  noroot?? init(args) : puts(IN_REPO_WARNING.yel, getroot)
55
57
  elsif cmd == 'clone' # allow cloning a new repo
56
- clone args
58
+ clonecn args
57
59
  elsif noroot? # if not in a repo, warn them, tell how to create
58
60
  puts NO_REPO_WARNING.yel
59
61
  else # now, assume we are in a copernicum project
@@ -172,12 +174,12 @@ module Copernicium
172
174
  end
173
175
  end
174
176
 
175
- def clone(args)
177
+ def clonecn(args)
176
178
  user = args.first
177
179
  host = args.last
178
180
  user = get "username for push" if user.nil?
179
181
  host = get "host path (<host:/dir/of/repo>)" if host.nil? || user == host
180
- comm = UIComm.new(command: 'clone', opts: user, repo: host)
182
+ comm = UIComm.new(command: 'clone', repo: host, opts: user)
181
183
  PushPull.UICommandParser(comm)
182
184
  return comm
183
185
  end
@@ -187,7 +189,7 @@ module Copernicium
187
189
  host = args.last
188
190
  user = get "username for push" if user.nil?
189
191
  host = get "host path (<host:/dir/of/repo>)" if host.nil? || user == host
190
- comm = UIComm.new(command: 'push', opts: user, repo: host)
192
+ comm = UIComm.new(command: 'push', repo: host, opts: user)
191
193
  PushPull.UICommandParser(comm)
192
194
  return comm
193
195
  end
@@ -197,7 +199,7 @@ module Copernicium
197
199
  host = args.last
198
200
  user = get "username for push" if user.nil?
199
201
  host = get "host path (<host:/dir/of/repo>)" if host.nil? || user == host
200
- comm = UIComm.new(command: 'pull', opts: user, repo: host)
202
+ comm = UIComm.new(command: 'pull', repo: host, opts: user)
201
203
  PushPull.UICommandParser(comm)
202
204
  return comm
203
205
  end
@@ -282,7 +284,7 @@ module Copernicium
282
284
  else
283
285
  username = args.first
284
286
  end
285
- Repos.update(UIComm.new(command: 'update', ops: username))
287
+ Repos.update(UIComm.new(command: 'update', opts: username))
286
288
  end
287
289
  end # Driver
288
290
  end # Copernicium
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: copernicium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Team Copernicium
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-08 00:00:00.000000000 Z
11
+ date: 2015-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diffy