cnvrg 0.0.150000 → 0.0.1520000

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27ff325c9bedde1af4df6c092ec091a39f726285
4
- data.tar.gz: 526fcd8e2a4ba9494895677dda0aca2b40a6ed6a
3
+ metadata.gz: 8350e6b16c815de7c51ea0020bec8e8ee3f760f4
4
+ data.tar.gz: 45a2c3cec4e0fa3450b6674a8f554c210db57af7
5
5
  SHA512:
6
- metadata.gz: f104f1192956125b983bd13f13474deff621be3a0e510d45ea5c2cfecf2758af3286cc5600236f8b547845c117b1d9710a4af7578bb0c05b1e1e3171d55403e6
7
- data.tar.gz: f97e77a186fd5122cbf9b808d62aaab51f515159104f6fb4c28067b5947d77dbdacadcd50f85bb63264c788c8b10b60c11c27d3b916d9c36489e55e582717723
6
+ metadata.gz: cb635cb17695ed08f6ee86a175ff18ed5e43fcad39a21f0b3037566605e212c3ff7ec32f535e128e58ba51d9ac446c69d90a9c57450bdede057ebfb48b02aff3
7
+ data.tar.gz: 20e44b71140893d5aeca636e9f985b92f66471596d9d83a44196f263ffbed2caae9532ffa645aeb5f20158140cadc771bf659201dc91fa9766aa06f7f5eddd3d
data/lib/cnvrg/api.rb CHANGED
@@ -60,7 +60,6 @@ module Cnvrg
60
60
  when 'POST'
61
61
  conn.options.timeout = 420
62
62
  conn.options.open_timeout =420
63
-
64
63
  response = conn.post "#{endpoint_uri}/#{resource}", data
65
64
 
66
65
  if parse_request == true
data/lib/cnvrg/cli.rb CHANGED
@@ -1151,6 +1151,7 @@ module Cnvrg
1151
1151
 
1152
1152
  end
1153
1153
 
1154
+
1154
1155
  desc 'data upload', 'push data'
1155
1156
  method_option :ignore, :type => :array, :aliases => ["-i", "--i"], :desc => "ignore following files"
1156
1157
  method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
@@ -1237,8 +1238,9 @@ module Cnvrg
1237
1238
  exit(1)
1238
1239
  end
1239
1240
  say "Uploading data", Thor::Shell::Color::BLUE
1241
+ log_file = "#{home_dir}/.cnvrg/tmp/upload_#{File.basename(tar_path)}.log"
1240
1242
  res = false
1241
- res = @files.upload_tar_file(tar_path, tar_path, commit_sha1)
1243
+ res = @files.upload_tar_file(tar_path, tar_path, commit_sha1)
1242
1244
 
1243
1245
  if res
1244
1246
  say "Commiting data", Thor::Shell::Color::BLUE
@@ -1257,12 +1259,19 @@ module Cnvrg
1257
1259
  end
1258
1260
 
1259
1261
  else
1262
+ if File.exist? log_file
1263
+ @files.upload_data_log_file(log_file,log_file,commit_sha1)
1264
+ end
1265
+
1266
+
1260
1267
  FileUtils.rm_rf([tar_files_path]) if File.exist? tar_files_path
1261
1268
  FileUtils.rm_rf([tar_path]) if File.exist? tar_path
1262
1269
 
1263
1270
 
1264
1271
  @files.rollback_commit(commit_sha1)
1265
1272
  say "Can't upload, Rolling Back all changes.", Thor::Shell::Color::RED
1273
+ say "Error log: #{log_file}", Thor::Shell::Color::RED
1274
+
1266
1275
  exit(1)
1267
1276
  end
1268
1277
 
@@ -1274,6 +1283,9 @@ module Cnvrg
1274
1283
  log_end(-1)
1275
1284
  FileUtils.rm_rf([tar_files_path]) if File.exist? tar_files_path
1276
1285
  FileUtils.rm_rf([tar_path]) if File.exist? tar_path
1286
+ if File.exist? log_file
1287
+ @files.upload_data_log_file(log_file,log_file,commit_sha1)
1288
+ end
1277
1289
 
1278
1290
 
1279
1291
  @files.rollback_commit(commit_sha1)
@@ -1285,39 +1297,26 @@ module Cnvrg
1285
1297
  say "Seems there is no internet connection", Thor::Shell::Color::RED
1286
1298
 
1287
1299
  end
1300
+ if File.exist? log_file
1301
+ @files.upload_data_log_file(log_file,log_file,commit_sha1)
1302
+ end
1288
1303
  FileUtils.rm_rf([tar_files_path]) if File.exist? tar_files_path
1289
1304
  FileUtils.rm_rf([tar_path]) if File.exist? tar_path
1290
1305
 
1291
1306
  log_end(-1, e.message)
1292
1307
  @files.rollback_commit(commit_sha1)
1293
1308
  say "Exception while trying to upload, Rolling back", Thor::Shell::Color::RED
1294
- exit(0)
1295
- end
1296
- if verbose
1297
- say "#{check} Done", Thor::Shell::Color::BLUE
1298
- if successful_updates.size >0
1299
- say "Updated:", Thor::Shell::Color::GREEN
1300
- suc = successful_updates.map { |x| x=Helpers.checkmark() +" "+x }
1301
- say suc.join("\n"), Thor::Shell::Color::GREEN
1302
- end
1303
- if successful_deletions.size >0
1304
- say "Deleted:", Thor::Shell::Color::GREEN
1305
- del = successful_updates.map { |x| x=Helpers.checkmark() +" "+x }
1306
- say del.join("\n"), Thor::Shell::Color::GREEN
1307
- end
1309
+ say "Error log: #{log_file}", Thor::Shell::Color::RED
1308
1310
 
1309
1311
 
1310
- say "Total of #{update_count} / #{update_total} files.", Thor::Shell::Color::GREEN
1311
- else
1312
- say "#{check} Changes were updated successfully", Thor::Shell::Color::GREEN
1313
-
1312
+ exit(0)
1314
1313
  end
1314
+ say "#{check} Changes were updated successfully", Thor::Shell::Color::GREEN
1315
+
1315
1316
 
1316
1317
 
1317
1318
  rescue => e
1318
1319
  log_end(-1, e.message)
1319
-
1320
-
1321
1320
  say "Error occurd, \nAborting", Thor::Shell::Color::RED
1322
1321
  @files.rollback_commit(commit_sha1)
1323
1322
  exit(1)
@@ -2299,32 +2298,15 @@ module Cnvrg
2299
2298
  begin
2300
2299
  stdout.each do |line|
2301
2300
  cur_time = Time.now
2302
- if remote
2303
- stats = usage_metrics_in_docker(docker_id)
2304
- cpu = stats[0]
2305
- memory = stats[1]
2306
- else
2307
- memory = memory_usage()
2308
- cpu = cpu_usage()
2309
- end
2310
-
2311
- memory_total << memory.to_f
2312
- cpu_total << cpu.to_f
2313
2301
  real_time= Time.now-real
2314
2302
 
2315
2303
  cur_log = { time: cur_time,
2316
2304
  message: line,
2317
2305
  type: "stdout",
2318
- real: real_time,
2319
- cpu: cpu,
2320
- memory: memory
2306
+ real: real_time
2307
+
2321
2308
  }
2322
- if is_on_gpu
2323
- gpu_stats = gpu_util
2324
- gpu_utilization = gpu_stats[0]
2325
- gpu_memory_util = gpu_stats[1]
2326
- cur_log.merge!(gpu_util:gpu_utilization,gpu_memory_util:gpu_memory_util)
2327
- end
2309
+
2328
2310
 
2329
2311
  if print_log
2330
2312
  puts cur_log
@@ -2334,6 +2316,28 @@ module Cnvrg
2334
2316
  begin
2335
2317
  if time_to_upload !=0
2336
2318
  if time_to_upload <= Time.now - start_loop
2319
+ if remote
2320
+ stats = usage_metrics_in_docker(docker_id)
2321
+ cpu = stats[0]
2322
+ memory = stats[1]
2323
+ if is_on_gpu
2324
+ gpu_stats = gpu_util
2325
+ gpu_utilization = gpu_stats[0]
2326
+ gpu_memory_util = gpu_stats[1]
2327
+ end
2328
+ else
2329
+ memory = memory_usage()
2330
+ cpu = cpu_usage()
2331
+ end
2332
+ log.each do |l|
2333
+ if remote and is_on_gpu
2334
+ l.merge!(cpu:cpu,memory:memory, gpu_util:gpu_utilization,gpu_memory_util:gpu_memory_util)
2335
+ else
2336
+ l.merge!(cpu:cpu,memory:memory)
2337
+ end
2338
+ end
2339
+
2340
+
2337
2341
  #upload current log
2338
2342
  # cpu_average = cpu_total.inject(0) { |sum, el| sum + el }.to_f / cpu_total.size
2339
2343
  # memory_average = memory_total.inject(0) { |sum, el| sum + el }.to_f / memory_total.size
@@ -4749,10 +4753,25 @@ module Cnvrg
4749
4753
 
4750
4754
  end
4751
4755
  $LOG = LogStashLogger.new(type: :file, path: logfile, sync: true)
4752
- rescue => e
4756
+ remove_old_log_files()
4753
4757
  end
4754
4758
  end
4755
4759
 
4760
+ def remove_old_log_files()
4761
+ begin
4762
+ last_week = (Time.now - (7*24*60*60)).strftime("%Y-%m-%d")
4763
+ home = File.expand_path('~')
4764
+ log_files = Dir["#{home}/.cnvrg/tmp/*.log"]
4765
+ log_files.each do |l|
4766
+ if File.mtime(l).strftime("%Y-%m-%d") < last_week
4767
+ FileUtils.rm_rf(l)
4768
+ end
4769
+ end
4770
+ end
4771
+
4772
+ end
4773
+
4774
+
4756
4775
 
4757
4776
  def verify_logged_in(in_dir=true)
4758
4777
  log_handler()
@@ -5119,7 +5138,7 @@ module Cnvrg
5119
5138
  if docker_id.nil?
5120
5139
  docker_id = `cat /etc/hostname`
5121
5140
  end
5122
- stats = `sudo docker stats #{docker_id} --no-stream --format "{{.CPUPerc}},{{.MemPerc}},{{.BlockIO}}"`
5141
+ stats = `sudo docker stats #{docker_id} --no-stream --format "{{.CPUPerc}},{{.MemPerc}},{{.BlockIO}}"`
5123
5142
  if !stats.nil?
5124
5143
  conv = stats.split(",")
5125
5144
  cpu = conv[0].gsub!("%","").to_f
@@ -22,10 +22,9 @@ module Cnvrg
22
22
  mime_type = MimeMagic.by_path(absolute_path)
23
23
  content_type = !(mime_type.nil? or mime_type.text?) ? mime_type.type : "text/plain"
24
24
  sha1 = Digest::SHA1.file(absolute_path).hexdigest
25
-
26
25
  upload_resp = Cnvrg::API.request(@base_resource + "upload_file", 'POST_FILE', {absolute_path: absolute_path, relative_path: relative_path,
27
26
  commit_sha1: commit_sha1, file_name: file_name,
28
- file_size: file_size, file_content_type: content_type,sha1:sha1})
27
+ file_size: file_size, file_content_type: content_type, sha1: sha1})
29
28
  if Cnvrg::CLI.is_response_success(upload_resp, false)
30
29
  path = upload_resp["result"]["path"]
31
30
  if file_size.to_f>= Cnvrg::Files::LARGE_FILE.to_f
@@ -41,44 +40,77 @@ module Cnvrg
41
40
  end
42
41
  return false
43
42
  end
43
+
44
44
  def upload_tar_file(absolute_path, relative_path, commit_sha1)
45
45
  begin
46
- file_name = File.basename relative_path
47
- file_size = File.size(absolute_path).to_f
48
- mime_type = MimeMagic.by_path(absolute_path)
49
- content_type = !(mime_type.nil? or mime_type.text?) ? mime_type.type : "text/plain"
50
- sha1 = Digest::SHA1.file(absolute_path).hexdigest
46
+ file_name = File.basename relative_path
47
+ file_size = File.size(absolute_path).to_f
48
+ mime_type = MimeMagic.by_path(absolute_path)
49
+ content_type = !(mime_type.nil? or mime_type.text?) ? mime_type.type : "text/plain"
50
+ begin
51
+ chunked_bytes = [100, (file_size*0.01)].min
52
+ total_yanked = ""
53
+ open(absolute_path, "rb") do |f|
54
+ total_yanked = f.read(chunked_bytes)
55
+ end
56
+ if !total_yanked.empty?
57
+ sha1 = Digest::SHA1.hexdigest(total_yanked)
58
+ else
59
+ sha1 = Digest::SHA1.file(absolute_path).hexdigest
60
+ end
61
+ rescue
62
+ sha1 = Digest::SHA1.file(absolute_path).hexdigest
63
+ end
51
64
 
52
- upload_resp = Cnvrg::API.request(@base_resource + "upload_tar_file", 'POST_FILE', {absolute_path: absolute_path, relative_path: relative_path,
53
- commit_sha1: commit_sha1, file_name: file_name,
54
- file_size: file_size, file_content_type: content_type,sha1:sha1})
55
- if Cnvrg::CLI.is_response_success(upload_resp, false)
56
- path = upload_resp["result"]["path"]
57
- s3_res = upload_large_files_s3(upload_resp, absolute_path)
58
- if s3_res
59
- Cnvrg::API.request(@base_resource + "update_s3", 'POST', {path: path, commit_id: upload_resp["result"]["commit_id"],
60
- blob_id: upload_resp["result"]["id"]})
61
- return true
65
+ upload_resp = Cnvrg::API.request(@base_resource + "upload_tar_file", 'POST_FILE', {absolute_path: absolute_path, relative_path: relative_path,
66
+ commit_sha1: commit_sha1, file_name: file_name,
67
+ file_size: file_size, file_content_type: content_type, sha1: sha1})
68
+ if Cnvrg::CLI.is_response_success(upload_resp, false)
69
+ path = upload_resp["result"]["path"]
70
+ s3_res = upload_large_files_s3(upload_resp, absolute_path)
71
+ if s3_res
72
+ Cnvrg::API.request(@base_resource + "update_s3", 'POST', {path: path, commit_id: upload_resp["result"]["commit_id"],
73
+ blob_id: upload_resp["result"]["id"]})
74
+ return true
75
+ end
76
+ else
77
+ return false
62
78
  end
63
- else
64
- return false
65
- end
66
79
  rescue => e
67
80
  puts e.message
68
81
  return false
69
82
  end
70
83
 
71
84
  end
72
- def upload_log_file(absolute_path, relative_path,log_date)
85
+
86
+ def upload_log_file(absolute_path, relative_path, log_date)
73
87
  file_name = File.basename relative_path
74
88
  file_size = File.size(absolute_path).to_f
75
89
  content_type = "text/x-log"
76
90
  upload_resp = Cnvrg::API.request("/users/#{@owner}/" + "upload_cli_log", 'POST_FILE', {absolute_path: absolute_path, relative_path: relative_path,
77
- file_name: file_name,log_date:log_date,
78
- file_size: file_size, file_content_type: content_type})
91
+ file_name: file_name, log_date: log_date,
92
+ file_size: file_size, file_content_type: content_type})
79
93
  if Cnvrg::CLI.is_response_success(upload_resp, false)
80
- path = upload_resp["result"]["path"]
81
- s3_res = upload_small_files_s3(path, absolute_path, "text/plain")
94
+ path = upload_resp["result"]["path"]
95
+ s3_res = upload_small_files_s3(path, absolute_path, "text/plain")
96
+ end
97
+ if s3_res
98
+ return true
99
+ end
100
+ return false
101
+
102
+ end
103
+ def upload_data_log_file(absolute_path, relative_path,data_commit_sha)
104
+ file_name = File.basename relative_path
105
+ file_size = File.size(absolute_path).to_f
106
+ content_type = "text/x-log"
107
+ upload_resp = Cnvrg::API.request("/users/#{@owner}/" + "upload_data_log", 'POST_FILE', {absolute_path: absolute_path, relative_path: relative_path,
108
+ file_name: file_name, log_date: Time.now,
109
+ file_size: file_size, file_content_type: content_type,
110
+ data_commit_sha1:data_commit_sha})
111
+ if Cnvrg::CLI.is_response_success(upload_resp, false)
112
+ path = upload_resp["result"]["path"]
113
+ s3_res = upload_small_files_s3(path, absolute_path, "text/plain")
82
114
  end
83
115
  if s3_res
84
116
  return true
@@ -86,18 +118,20 @@ module Cnvrg
86
118
  return false
87
119
 
88
120
  end
89
- def upload_exec_file(absolute_path,image_name,commit_id)
121
+
122
+
123
+ def upload_exec_file(absolute_path, image_name, commit_id)
90
124
  file_name = File.basename absolute_path
91
125
  file_size = File.size(absolute_path).to_f
92
126
  content_type = "application/zip"
93
127
  begin
94
128
  upload_resp = Cnvrg::API.request("users/#{@owner}/images/" + "upload_config", 'POST_FILE', {relative_path: absolute_path,
95
129
  file_name: file_name,
96
- image_name:image_name,
130
+ image_name: image_name,
97
131
  file_size: file_size,
98
132
  file_content_type: content_type,
99
133
  project_slug: @project_slug,
100
- commit_id:commit_id})
134
+ commit_id: commit_id})
101
135
  # puts upload_resp
102
136
  if Cnvrg::CLI.is_response_success(upload_resp, false)
103
137
  if upload_resp["result"]["image"] == -1
@@ -107,21 +141,20 @@ module Cnvrg
107
141
  s3_res = upload_small_files_s3(path, absolute_path, content_type)
108
142
 
109
143
  end
110
- if s3_res
111
- return upload_resp["result"]["id"]
144
+ if s3_res
145
+ return upload_resp["result"]["id"]
146
+ end
147
+ return false
148
+ rescue SignalException
149
+
150
+ say "\nAborting"
151
+ exit(1)
112
152
  end
113
- return false
114
- rescue SignalException
115
153
 
116
- say "\nAborting"
117
- exit(1)
118
154
  end
119
155
 
120
- end
121
-
122
-
123
156
 
124
- def upload_image(absolute_path, image_name, owner, is_public, is_base,dpkg,libraries,bash,message,commit_id)
157
+ def upload_image(absolute_path, image_name, owner, is_public, is_base, dpkg, libraries, bash, message, commit_id)
125
158
  file_name = File.basename absolute_path
126
159
  file_size = File.size(absolute_path).to_f
127
160
  if is_base
@@ -131,41 +164,42 @@ module Cnvrg
131
164
  content_type = "application/gzip"
132
165
  end
133
166
  begin
134
- upload_resp = Cnvrg::API.request("users/#{owner}/images/" + "upload_cnvrg", 'POST_FILE', {relative_path: absolute_path,
135
- file_name: file_name,
136
- image_name: image_name,
137
- file_size: file_size,
138
- file_content_type: content_type,
139
- is_public: is_public,
140
- project_slug: @project_slug,
141
- commit_id:commit_id ,
142
- dpkg: dpkg,
143
- py2: libraries,
144
- py3: libraries,
145
-
146
- bash_history: bash,
147
- commit_message:message,
148
- is_base: is_base})
149
- # puts upload_resp
150
- if Cnvrg::CLI.is_response_success(upload_resp, false)
151
- path = upload_resp["result"]["path"]
152
- s3_res = upload_small_files_s3(path, absolute_path, content_type)
153
- if s3_res
154
- commit_resp = Cnvrg::API.request("users/#{owner}/images/#{upload_resp["result"]["id"]}/" + "commit", 'GET')
155
- if Cnvrg::CLI.is_response_success(commit_resp, false)
156
- return commit_resp["result"]["image"]
157
- else
158
- return false
159
- end
167
+ upload_resp = Cnvrg::API.request("users/#{owner}/images/" + "upload_cnvrg", 'POST_FILE', {relative_path: absolute_path,
168
+ file_name: file_name,
169
+ image_name: image_name,
170
+ file_size: file_size,
171
+ file_content_type: content_type,
172
+ is_public: is_public,
173
+ project_slug: @project_slug,
174
+ commit_id: commit_id,
175
+ dpkg: dpkg,
176
+ py2: libraries,
177
+ py3: libraries,
178
+
179
+ bash_history: bash,
180
+ commit_message: message,
181
+ is_base: is_base})
182
+ # puts upload_resp
183
+ if Cnvrg::CLI.is_response_success(upload_resp, false)
184
+ path = upload_resp["result"]["path"]
185
+ s3_res = upload_small_files_s3(path, absolute_path, content_type)
186
+ if s3_res
187
+ commit_resp = Cnvrg::API.request("users/#{owner}/images/#{upload_resp["result"]["id"]}/" + "commit", 'GET')
188
+ if Cnvrg::CLI.is_response_success(commit_resp, false)
189
+ return commit_resp["result"]["image"]
190
+ else
191
+ return false
192
+ end
160
193
 
194
+ end
161
195
  end
162
- end
163
- return false
164
- rescue =>e
196
+ return false
197
+ rescue => e
165
198
  end
166
199
 
167
200
  end
168
- def upload_cnvrg_image(absolute_path, image_name, owner, is_public, is_base,dpkg,libraries,bash,message)
201
+
202
+ def upload_cnvrg_image(absolute_path, image_name, owner, is_public, is_base, dpkg, libraries, bash, message)
169
203
  file_name = File.basename absolute_path
170
204
  file_size = File.size(absolute_path).to_f
171
205
  if is_base
@@ -176,16 +210,16 @@ module Cnvrg
176
210
  end
177
211
  begin
178
212
  upload_resp = Cnvrg::API.request("users/#{owner}/images/" + "upload_cnvrg", 'POST_FILE', {relative_path: absolute_path,
179
- file_name: file_name,
180
- image_name: image_name,
181
- file_size: file_size,
182
- file_content_type: content_type,
183
- is_public: is_public,
184
- dpkg: dpkg,
185
- libraries: libraries,
186
- bash_history: bash,
187
- commit_message:message,
188
- is_base: is_base})
213
+ file_name: file_name,
214
+ image_name: image_name,
215
+ file_size: file_size,
216
+ file_content_type: content_type,
217
+ is_public: is_public,
218
+ dpkg: dpkg,
219
+ libraries: libraries,
220
+ bash_history: bash,
221
+ commit_message: message,
222
+ is_base: is_base})
189
223
  # puts upload_resp
190
224
  if Cnvrg::CLI.is_response_success(upload_resp, false)
191
225
  path = upload_resp["result"]["path"]
@@ -201,7 +235,7 @@ module Cnvrg
201
235
  end
202
236
  end
203
237
  return false
204
- rescue =>e
238
+ rescue => e
205
239
  end
206
240
 
207
241
  end
@@ -231,7 +265,7 @@ module Cnvrg
231
265
 
232
266
  end
233
267
 
234
- def upload_large_files_s3(upload_resp, file_path)
268
+ def upload_large_files_s3(upload_resp, file_path)
235
269
  begin
236
270
  sts_path = upload_resp["result"]["path_sts"]
237
271
  # s4cmd_path = upload_resp["result"]["path_s4cmd"]
@@ -246,76 +280,62 @@ module Cnvrg
246
280
  response = http.request request
247
281
  body = response.read_body
248
282
  end
249
- is_python = false
250
- s4cmd_suc = false
251
- s4cmd_install_suc = false
283
+ home_dir = File.expand_path('~')
284
+ log_file = "#{home_dir}/.cnvrg/tmp/upload_#{File.basename(file_path)}.log"
252
285
 
253
286
  URLcrypt::key = [body].pack('H*')
254
-
255
- # python_version=`python --version > /dev/null 2>&1` ; is_python=$?.success?
256
- # if is_python
287
+ client = Aws::S3::Client.new(:access_key_id => URLcrypt.decrypt(upload_resp["result"]["new_a"]),
288
+ :secret_access_key => URLcrypt.decrypt(upload_resp["result"]["new_s"]),
289
+ :region => URLcrypt.decrypt(upload_resp["result"]["region"]),
290
+ :logger => Logger.new(log_file),
291
+ :http_open_timeout => 60, :retry_limit => 20,
292
+ :http_wire_trace => true)
293
+ s3 = Aws::S3::Resource.new(client: client)
294
+
295
+ resp = s3.bucket(URLcrypt.decrypt(upload_resp["result"]["bucket"])).
296
+ object(upload_resp["result"]["path"]+"/"+File.basename(file_path)).
297
+ upload_file(file_path, {:use_accelerate_endpoint => true})
298
+ # s4cmd_path = upload_resp["result"]["path_s4cmd"]
257
299
  #
258
- # s4cmd=`pip freeze 2>/dev/null |grep -e s4cmd -e boto3 > /dev/null 2>&1` ; s4cmd_suc=$?.success?
259
- # if !s4cmd_suc
260
- # `pip install s4cmd > /dev/null 2>&1` ; s4cmd_install_suc=$?.success?
261
- # end
300
+ # s4cmd_uri = URI.parse(s4cmd_path)
301
+ # s4cmd_http_object = Net::HTTP.new(s4cmd_uri.host, s4cmd_uri.port)
302
+ # s4cmd_http_object.use_ssl = true if s4cmd_uri.scheme == 'https'
303
+ # s4cmd_request = Net::HTTP::Get.new(s4cmd_path)
262
304
  #
305
+ # s4cmd_body = ""
306
+ # s4cmd_http_object.start do |http|
307
+ # response = http.request s4cmd_request
308
+ # s4cmd_body = response.read_body
263
309
  # end
264
- resp = false
265
-
266
- if !s4cmd_suc and !s4cmd_install_suc
267
- s3 = Aws::S3::Resource.new(
268
- :access_key_id => URLcrypt.decrypt(upload_resp["result"]["new_a"]),
269
- :secret_access_key => URLcrypt.decrypt(upload_resp["result"]["new_s"]),
270
- :region => URLcrypt.decrypt(upload_resp["result"]["region"]))
271
- resp = s3.bucket(URLcrypt.decrypt(upload_resp["result"]["bucket"])).
272
- object(upload_resp["result"]["path"]+"/"+File.basename(file_path)).
273
- upload_file(file_path,{:use_accelerate_endpoint=>true})
274
-
275
- # else
276
-
277
- # s4cmd_uri = URI.parse(s4cmd_path)
278
- # s4cmd_http_object = Net::HTTP.new(s4cmd_uri.host, s4cmd_uri.port)
279
- # s4cmd_http_object.use_ssl = true if s4cmd_uri.scheme == 'https'
280
- # s4cmd_request = Net::HTTP::Get.new(s4cmd_path)
281
- #
282
- # s4cmd_body = ""
283
- # s4cmd_http_object.start do |http|
284
- # response = http.request s4cmd_request
285
- # s4cmd_body = response.read_body
286
- # end
287
- #
288
- # s4cmd_new_body = s4cmd_body.gsub(" self.client = self.boto3.client('s3',
289
- # aws_access_key_id=aws_access_key_id,
290
- # aws_secret_access_key=aws_secret_access_key)"," self.client = self.boto3.client('s3',
291
- # aws_access_key_id='#{ URLcrypt.decrypt(upload_resp["result"]["sts_a"])}',
292
- # aws_secret_access_key='#{URLcrypt.decrypt(upload_resp["result"]["sts_s"])}',
293
- # aws_session_token='#{URLcrypt.decrypt(upload_resp["result"]["sts_st"])}')")
294
- #
295
- # tmp = Tempfile.new('s4cmd.py')
296
- # tmp << s4cmd_new_body
297
- # tmp.flush
298
- # tmp.close
299
- #
300
- # is_success = false
301
- # count = 0
302
- # while !is_success and count <3
303
- # resp = `python #{tmp.path} --num-threads=8 --max-singlepart-upload-size=#{MULTIPART_SPLIT} put -f #{file_path} s3://#{URLcrypt.decrypt(upload_resp["result"]["bucket"])}/#{upload_resp["result"]["path"]+"/"+File.basename(file_path)} > /dev/null 2>&1`
304
- # is_success =$?.success?
305
- # count +=1
306
- #
307
- # end
308
- # resp= is_success
309
-
310
+ # s4cmd_new_body = s4cmd_body.gsub(" self.client = self.boto3.client('s3',
311
+ # aws_access_key_id=aws_access_key_id,
312
+ # aws_secret_access_key=aws_secret_access_key)", " self.client = self.boto3.client('s3',
313
+ # aws_access_key_id='#{ URLcrypt.decrypt(upload_resp["result"]["new_a"])}',
314
+ # aws_secret_access_key='#{URLcrypt.decrypt(upload_resp["result"]["new_s"])}')")
315
+ #
316
+ #
317
+ # tmp = Tempfile.new('s4cmd.py')
318
+ # tmp << s4cmd_new_body
319
+ # tmp.flush
320
+ # tmp.close
321
+ # #
322
+ # is_success = false
323
+ # count = 0
324
+ # while !is_success and count <3
325
+ # resp = `python #{tmp.path} --num-threads=8 --max-singlepart-upload-size=#{MULTIPART_SPLIT} put -f #{file_path} s3://#{URLcrypt.decrypt(upload_resp["result"]["bucket"])}/#{upload_resp["result"]["path"]+"/"+File.basename(file_path)} > /dev/null 2>&1 `
326
+ # is_success =$?.success?
327
+ # count +=1
328
+ #
329
+ # end
330
+ # resp= is_success
331
+ if resp == true
332
+ FileUtils.rm_rf(log_file)
310
333
  end
311
334
 
312
335
  return resp
313
336
 
314
337
  rescue => e
315
338
  puts e.message
316
- # if File.exist? tmp
317
- # FileUtils.rm_rf [tmp]
318
- # end
319
339
  return false
320
340
 
321
341
  end
@@ -366,9 +386,10 @@ module Cnvrg
366
386
  response = Cnvrg::API.request(@base_resource + "create_dir", 'POST', {absolute_path: absolute_path, relative_path: relative_path, commit_sha1: commit_sha1})
367
387
  return Cnvrg::CLI.is_response_success(response, false)
368
388
  end
369
- def download_file_s3(absolute_path, relative_path, project_home, conflict=false,commit_sha1=nil)
389
+
390
+ def download_file_s3(absolute_path, relative_path, project_home, conflict=false, commit_sha1=nil)
370
391
  begin
371
- res = Cnvrg::API.request(@base_resource + "download_file", 'POST', {absolute_path: absolute_path, relative_path: relative_path,commit_sha1:commit_sha1})
392
+ res = Cnvrg::API.request(@base_resource + "download_file", 'POST', {absolute_path: absolute_path, relative_path: relative_path, commit_sha1: commit_sha1})
372
393
  Cnvrg::CLI.is_response_success(res, false)
373
394
  if res["result"]
374
395
  download_resp = res
@@ -376,38 +397,38 @@ module Cnvrg
376
397
 
377
398
  absolute_path += ".conflict" if conflict
378
399
  sts_path = download_resp["result"]["path_sts"]
379
- uri = URI.parse(sts_path)
380
- http_object = Net::HTTP.new(uri.host, uri.port)
381
- http_object.use_ssl = true if uri.scheme == 'https'
382
- request = Net::HTTP::Get.new(sts_path)
400
+ uri = URI.parse(sts_path)
401
+ http_object = Net::HTTP.new(uri.host, uri.port)
402
+ http_object.use_ssl = true if uri.scheme == 'https'
403
+ request = Net::HTTP::Get.new(sts_path)
383
404
 
384
- body = ""
385
- http_object.start do |http|
386
- response = http.request request
387
- body = response.read_body
388
- end
389
- URLcrypt::key = [body].pack('H*')
390
- s3 = Aws::S3::Client.new(
391
- :access_key_id => URLcrypt.decrypt(download_resp["result"]["sts_a"]),
392
- :secret_access_key => URLcrypt.decrypt(download_resp["result"]["sts_s"]),
393
- :session_token => URLcrypt.decrypt(download_resp["result"]["sts_st"]),
394
- :region => URLcrypt.decrypt(download_resp["result"]["region"]))
395
- File.open(project_home+"/"+absolute_path, 'wb') do |file|
396
- resp = s3.get_object({ bucket:URLcrypt.decrypt(download_resp["result"]["bucket"]),
397
- key:URLcrypt.decrypt(download_resp["result"]["key"])}, target: file)
398
- end
405
+ body = ""
406
+ http_object.start do |http|
407
+ response = http.request request
408
+ body = response.read_body
409
+ end
410
+ URLcrypt::key = [body].pack('H*')
411
+ s3 = Aws::S3::Client.new(
412
+ :access_key_id => URLcrypt.decrypt(download_resp["result"]["sts_a"]),
413
+ :secret_access_key => URLcrypt.decrypt(download_resp["result"]["sts_s"]),
414
+ :session_token => URLcrypt.decrypt(download_resp["result"]["sts_st"]),
415
+ :region => URLcrypt.decrypt(download_resp["result"]["region"]))
416
+ File.open(project_home+"/"+absolute_path, 'wb') do |file|
417
+ resp = s3.get_object({bucket: URLcrypt.decrypt(download_resp["result"]["bucket"]),
418
+ key: URLcrypt.decrypt(download_resp["result"]["key"])}, target: file)
419
+ end
399
420
  return true
400
421
  end
401
422
 
402
- rescue =>e
423
+ rescue => e
403
424
  return false
404
425
 
405
426
  end
406
427
  end
407
428
 
408
- def download_data_file(commit_sha1,dataset_home)
429
+ def download_data_file(commit_sha1, dataset_home)
409
430
  begin
410
- res = Cnvrg::API.request(@base_resource + "download_data_file", 'POST', {commit_sha1:commit_sha1})
431
+ res = Cnvrg::API.request(@base_resource + "download_data_file", 'POST', {commit_sha1: commit_sha1})
411
432
  Cnvrg::CLI.is_response_success(res, false)
412
433
  if res["result"]
413
434
  download_resp = res
@@ -432,13 +453,13 @@ module Cnvrg
432
453
  :region => URLcrypt.decrypt(download_resp["result"]["region"]))
433
454
 
434
455
  File.open(dataset_home+"/"+filename, 'wb') do |file|
435
- resp = s3.get_object({ bucket:URLcrypt.decrypt(download_resp["result"]["bucket"]),
436
- key:URLcrypt.decrypt(download_resp["result"]["key"])}, target: file)
456
+ resp = s3.get_object({bucket: URLcrypt.decrypt(download_resp["result"]["bucket"]),
457
+ key: URLcrypt.decrypt(download_resp["result"]["key"])}, target: file)
437
458
  end
438
459
  return filename
439
460
  end
440
461
 
441
- rescue =>e
462
+ rescue => e
442
463
  return false
443
464
 
444
465
  end
@@ -468,27 +489,28 @@ module Cnvrg
468
489
  def download_dir(dataset_home, absolute_path)
469
490
  FileUtils.mkdir_p("#{dataset_home}/#{absolute_path}")
470
491
  end
492
+
471
493
  def revoke_download_dir(absolute_path)
472
494
  puts FileUtils.rmtree("#{absolute_path}")
473
495
  end
474
496
 
475
- def revoke_download_file(absolute_path,filename,conflict=false)
497
+ def revoke_download_file(absolute_path, filename, conflict=false)
476
498
  begin
477
- file_location = absolute_path.gsub(/#{filename}\/?$/, "")
499
+ file_location = absolute_path.gsub(/#{filename}\/?$/, "")
478
500
 
479
- filename += ".conflict" if conflict
480
- FileUtils.remove("#{file_location}/#{filename}")
501
+ filename += ".conflict" if conflict
502
+ FileUtils.remove("#{file_location}/#{filename}")
481
503
  return true
482
504
  rescue
483
- return false
505
+ return false
484
506
  end
485
507
  end
486
508
 
487
509
  def start_commit(new_branch)
488
510
 
489
- response = Cnvrg::API.request("#{base_resource}/commit/start", 'POST', {dataset_slug: @dataset_slug,new_branch:false,
511
+ response = Cnvrg::API.request("#{base_resource}/commit/start", 'POST', {dataset_slug: @dataset_slug, new_branch: false,
490
512
  username: @owner})
491
- Cnvrg::CLI.is_response_success(response,false)
513
+ Cnvrg::CLI.is_response_success(response, false)
492
514
  return response
493
515
  end
494
516
 
@@ -496,8 +518,9 @@ module Cnvrg
496
518
  response = Cnvrg::API.request("#{base_resource}/commit/end", 'POST', {commit_sha1: commit_sha1})
497
519
  return response
498
520
  end
499
- def end_commit_tar(commit_sha1,cur_idx)
500
- response = Cnvrg::API.request("#{base_resource}/commit/end_tar", 'POST', {commit_sha1: commit_sha1,idx: cur_idx})
521
+
522
+ def end_commit_tar(commit_sha1, cur_idx)
523
+ response = Cnvrg::API.request("#{base_resource}/commit/end_tar", 'POST', {commit_sha1: commit_sha1, idx: cur_idx})
501
524
  return response
502
525
  end
503
526
 
data/lib/cnvrg/dataset.rb CHANGED
@@ -116,7 +116,7 @@ module Cnvrg
116
116
  File.open(".cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
117
117
  File.open(".cnvrgignore", "w+") { |f| f.write cnvrgignore } unless File.exist? ".cnvrgignore"
118
118
  rescue => e
119
- "Exception in init data: #{e.message}"
119
+ "Exception in init data: #"
120
120
  return false
121
121
  end
122
122
  return true
data/lib/cnvrg/version.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  module Cnvrg
2
- VERSION = '0.0.150000'
2
+ VERSION = '0.0.1520000'
3
+
4
+
3
5
  end
4
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cnvrg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.150000
4
+ version: 0.0.1520000
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yochay Ettun
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-07-16 00:00:00.000000000 Z
12
+ date: 2017-07-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -388,9 +388,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
388
388
  version: '0'
389
389
  requirements: []
390
390
  rubyforge_project:
391
- rubygems_version: 2.5.1
391
+ rubygems_version: 2.6.12
392
392
  signing_key:
393
393
  specification_version: 4
394
394
  summary: A CLI tool for interacting with cnvrg.io.
395
395
  test_files: []
396
- has_rdoc: