cnvrg 0.0.1422 → 0.0.1424

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: d00f4715dff9ff27fc5dce8cd6de74e5dc846302
4
- data.tar.gz: c3c218341d0d7ecba3f0b7bf0fcd09660bbeadec
3
+ metadata.gz: 175af4d0c0a0bb3bf60b921c412da5de3254927c
4
+ data.tar.gz: 97c6df1be57c4e17a5aeac38e1e0407eb9a1bdfc
5
5
  SHA512:
6
- metadata.gz: 9c01d5eb58da2edfedcce2bf7cc6754384aa133fa335e94edc9888688f9fcf20bb5ffc1879495b37661a9a1650cbfdb6ab56813270089e6cd11856ad28ffc2fc
7
- data.tar.gz: 2d2554208488d719ae4041a4c5e6dee3eaa588ded0794f06b446482f6e5c5a95d2a0e2013f1fe6e14f79c0c4e1d0a63587d24614f9acc018473afa2778475f18
6
+ metadata.gz: b8d9944d378b24808d49cd366e8e4d58ef31ea834b186d12774c369f793ecaf8fdff1b10e197121be2ec274cbde93447f9bcef60c5a9586837a907e5f88e3655
7
+ data.tar.gz: 8c36084a0068b92e58b777e2c080c132aa5df4440d7337ece94185718d4e18f0ceef2de0ab6b2edb7808d4c6fef08a31a8ce088c702e19db2030152dbcef1a3e
data/cnvrg.gemspec CHANGED
@@ -39,6 +39,8 @@ Gem::Specification.new do |spec|
39
39
  spec.add_runtime_dependency 'docker-api', '~> 1.33'
40
40
  spec.add_runtime_dependency 'rubyzip', '~> 1.2'
41
41
  spec.add_runtime_dependency 'activesupport', '~> 5.0'
42
+ spec.add_runtime_dependency 'ruby-progressbar'
43
+
42
44
 
43
45
 
44
46
  end
data/lib/cnvrg/cli.rb CHANGED
@@ -33,6 +33,7 @@ require 'zip'
33
33
  require 'active_support/all'
34
34
  require 'thor'
35
35
  require 'pathname'
36
+ require 'enumerator'
36
37
 
37
38
 
38
39
  class Thor
@@ -94,7 +95,7 @@ class Thor
94
95
  if !args.empty? and local_options.is_a? Array and !local_options.empty?
95
96
  args = args + local_options
96
97
  else
97
- args = args.flatten()
98
+ args = args.flatten()
98
99
  end
99
100
 
100
101
  end
@@ -210,7 +211,7 @@ module Cnvrg
210
211
  config = {owner: config.to_h[:owner], username: config.to_h[:username], version_last_check: config.to_h[:version_last_check], api: url}
211
212
  end
212
213
  res = Cnvrg::API.request("/users/#{owner}/custom_api", 'POST', {custom_api: url})
213
- if Cnvrg::CLI.is_response_success(res)
214
+ if Cnvrg::CLI.is_response_success(res,false)
214
215
 
215
216
  checks = Helpers.checkmark
216
217
 
@@ -1195,8 +1196,12 @@ module Cnvrg
1195
1196
  exit(1)
1196
1197
  end
1197
1198
  say "Uploading data", Thor::Shell::Color::BLUE
1198
-
1199
- res = @files.upload_tar_file(tar_path, tar_path, commit_sha1)
1199
+ eta = Time.now + 600
1200
+ start = Time.now
1201
+ res = false
1202
+ with_progress_bar do
1203
+ res = @files.upload_tar_file(tar_path, tar_path, commit_sha1)
1204
+ end
1200
1205
 
1201
1206
  if res
1202
1207
  cur_idx = @dataset.get_idx.to_h
@@ -1447,7 +1452,7 @@ module Cnvrg
1447
1452
  else
1448
1453
  # blob
1449
1454
 
1450
- if @files.download_file_s3(f[0], relative_path, project_home,commit_sha1=current_commit)
1455
+ if @files.download_file_s3(f[0], relative_path, project_home, commit_sha1=current_commit)
1451
1456
  successful_changes << relative_path
1452
1457
  end
1453
1458
  end
@@ -1846,7 +1851,7 @@ module Cnvrg
1846
1851
 
1847
1852
  result["conflicts"].each do |f|
1848
1853
  relative_path = f.gsub(/^#{@project.local_path}/, "")
1849
- if @files.download_file_s3(f, relative_path, project_home,commit_sha1=nil, conflict=true)
1854
+ if @files.download_file_s3(f, relative_path, project_home, commit_sha1=nil, conflict=true)
1850
1855
  successful_changes << relative_path
1851
1856
  end
1852
1857
 
@@ -1971,7 +1976,7 @@ module Cnvrg
1971
1976
  end
1972
1977
  else
1973
1978
  # blob
1974
- if @files.download_file_s3(f[0], relative_path, project_home,commit_sha1=commit_sha1)
1979
+ if @files.download_file_s3(f[0], relative_path, project_home, commit_sha1=commit_sha1)
1975
1980
  current_tree.delete(relative_path)
1976
1981
 
1977
1982
  successful_changes << relative_path
@@ -2063,26 +2068,26 @@ module Cnvrg
2063
2068
 
2064
2069
 
2065
2070
  desc 'run cmd', 'Runs an experiment'
2066
- method_option :local, :type => :boolean, :aliases => ["-l","--local"], :default => false
2071
+ method_option :local, :type => :boolean, :aliases => ["-l", "--local"], :default => false
2067
2072
  method_option :small, :type => :boolean, :aliases => ["-sm", "--small"], :default => false
2068
2073
  method_option :medium, :type => :boolean, :aliases => ["-md", "--medium"], :default => false
2069
2074
  method_option :large, :type => :boolean, :aliases => ["-lg", "--large"], :default => false
2070
2075
  method_option :gpu, :type => :boolean, :aliases => ["--gpu"], :default => false
2071
2076
  method_option :gpuxl, :type => :boolean, :aliases => ["--gpuxl"], :default => false
2072
2077
  method_option :gpuxxl, :type => :boolean, :aliases => ["--gpuxxl"], :default => false
2073
- method_option :sync_before, :type => :boolean, :aliases => ["-sb","--sync_before"], :default => true
2074
- method_option :sync_after, :type => :boolean, :aliases => ["-sa","--sync_after"], :default => true
2078
+ method_option :sync_before, :type => :boolean, :aliases => ["-sb", "--sync_before"], :default => true
2079
+ method_option :sync_after, :type => :boolean, :aliases => ["-sa", "--sync_after"], :default => true
2075
2080
  method_option :title, :type => :string, :aliases => ["-t", "--title"], :default => ""
2076
2081
  method_option :log, :type => :boolean, :aliases => ["--log"], :default => false
2077
- method_option :email_notification, :type => :boolean, :aliases => ["-en","--email_notification"], :default => false
2078
- method_option :upload_output, :type => :string, :aliases => ["-uo","--upload_output"], :default => ""
2079
- method_option :commit, :type => :string, :aliases => ["-c","--commit"], :default => ""
2080
- method_option :schedule, :type => :string, :aliases => ["-s","--schedule"], :default => ""
2081
- method_option :image, :type => :string, :aliases => ["-i","--image"], :default => ""
2082
+ method_option :email_notification, :type => :boolean, :aliases => ["-en", "--email_notification"], :default => false
2083
+ method_option :upload_output, :type => :string, :aliases => ["-uo", "--upload_output"], :default => ""
2084
+ method_option :commit, :type => :string, :aliases => ["-c", "--commit"], :default => ""
2085
+ method_option :schedule, :type => :string, :aliases => ["-s", "--schedule"], :default => ""
2086
+ method_option :image, :type => :string, :aliases => ["-i", "--image"], :default => ""
2082
2087
  method_option :grid, :type => :string, :aliases => ["-g", "--grid"], :default => ""
2083
2088
  method_option :data, :type => :string, :aliases => ["-d", "--data"], :default => ""
2084
2089
  method_option :data_commit, :type => :string, :aliases => ["--data_commit"], :default => ""
2085
- method_option :ignore, :type => :string, :aliases => ["-i","--ignore"], :desc => "ignore following files", :default => ""
2090
+ method_option :ignore, :type => :string, :aliases => ["-i", "--ignore"], :desc => "ignore following files", :default => ""
2086
2091
 
2087
2092
  def run(*cmd)
2088
2093
  sync_before = options["sync_before"]
@@ -2119,7 +2124,7 @@ module Cnvrg
2119
2124
  end
2120
2125
  exec_options = real_options.map { |x| "--#{x[0]}=#{x[1]}" }.flatten.join(" ")
2121
2126
  cmd_to_exec = "#{exec_options} #{cmd.join(" ")}"
2122
- invoke :exec_remote, [cmd] , :sync_before => sync_before, :sync_after => sync_after, :title => title, :machine_type => instance_type,
2127
+ invoke :exec_remote, [cmd], :sync_before => sync_before, :sync_after => sync_after, :title => title, :machine_type => instance_type,
2123
2128
  :schedule => schedule, :log => log, :email_notification => email_notification, :upload_output => upload_output, :commit => commit,
2124
2129
  :image => image, :grid => grid, :data => data, :data_commit => data_commit, :ignore => ignore
2125
2130
  return
@@ -2141,19 +2146,19 @@ module Cnvrg
2141
2146
  desc '', '', :hide => true
2142
2147
  method_option :sync_before, :type => :boolean, :aliases => ["-sb,--sync_before"], :default => true
2143
2148
  method_option :sync_after, :type => :boolean, :aliases => ["-sa,--sync_after"], :default => true
2144
- method_option :title, :type => :string, :aliases => ["-t","--title"], :default => ""
2145
- method_option :log, :type => :boolean, :aliases => [ "--log"], :default => false
2149
+ method_option :title, :type => :string, :aliases => ["-t", "--title"], :default => ""
2150
+ method_option :log, :type => :boolean, :aliases => ["--log"], :default => false
2146
2151
  method_option :email_notification, :type => :boolean, :aliases => ["-en,--email_notification"], :default => false
2147
2152
  method_option :upload_output, :type => :string, :aliases => ["-uo,--upload_output"], :default => ""
2148
- method_option :commit, :type => :string, :aliases => ["-c","--commit"], :default => ""
2149
- method_option :image, :type => :string, :aliases => ["-i","--image"], :default => ""
2153
+ method_option :commit, :type => :string, :aliases => ["-c", "--commit"], :default => ""
2154
+ method_option :image, :type => :string, :aliases => ["-i", "--image"], :default => ""
2150
2155
  method_option :indocker, :type => :boolean, :aliases => ["--indocker"], :default => false
2151
2156
  method_option :data, :type => :string, :aliases => ["-d", "--data"], :default => ""
2152
2157
  method_option :data_commit, :type => :string, :aliases => ["-dc", "--data_commit"], :default => ""
2153
- method_option :ignore, :type => :string, :aliases => ["-i","--ignore"], :desc => "ignore following files", :default => ""
2154
-
2158
+ method_option :ignore, :type => :string, :aliases => ["-i", "--ignore"], :desc => "ignore following files", :default => ""
2155
2159
 
2156
2160
  def exec(*cmd)
2161
+
2157
2162
  log = []
2158
2163
  cpu_average =0
2159
2164
  memory_average = 0
@@ -2564,20 +2569,20 @@ module Cnvrg
2564
2569
  end
2565
2570
 
2566
2571
  desc '', '', :hide => true
2567
- method_option :sync_before, :type => :boolean, :aliases => ["-sb","--sync_before"], :default => true
2568
- method_option :sync_after, :type => :boolean, :aliases => ["-sa","--sync_after"], :default => true
2569
- method_option :title, :type => :string, :aliases => ["-t","--title"], :default => ""
2570
- method_option :log, :type => :boolean, :aliases => [ "--log"], :default => false
2571
- method_option :email_notification, :type => :boolean, :aliases => ["-en","--email_notification"], :default => false
2572
- method_option :upload_output, :type => :string, :aliases => ["-uo","--upload_output"], :default => ""
2572
+ method_option :sync_before, :type => :boolean, :aliases => ["-sb", "--sync_before"], :default => true
2573
+ method_option :sync_after, :type => :boolean, :aliases => ["-sa", "--sync_after"], :default => true
2574
+ method_option :title, :type => :string, :aliases => ["-t", "--title"], :default => ""
2575
+ method_option :log, :type => :boolean, :aliases => ["--log"], :default => false
2576
+ method_option :email_notification, :type => :boolean, :aliases => ["-en", "--email_notification"], :default => false
2577
+ method_option :upload_output, :type => :string, :aliases => ["-uo", "--upload_output"], :default => ""
2573
2578
  method_option :machine_type, :type => :string, :default => ""
2574
- method_option :schedule, :type => :string, :aliases => ["-s","--schedule"], :default => ""
2579
+ method_option :schedule, :type => :string, :aliases => ["-s", "--schedule"], :default => ""
2575
2580
  method_option :commit, :type => :string, :aliases => ["-c, --commit"], :default => nil
2576
- method_option :image, :type => :string, :aliases => ["-i","--image"], :default => ""
2581
+ method_option :image, :type => :string, :aliases => ["-i", "--image"], :default => ""
2577
2582
  method_option :grid, :type => :string, :aliases => ["-g", "--grid"], :default => ""
2578
2583
  method_option :data, :type => :string, :aliases => ["-d", "--data"], :default => ""
2579
2584
  method_option :data_commit, :type => :string, :aliases => ["--data_commit"], :default => ""
2580
- method_option :ignore, :type => :string, :aliases => ["-i","--ignore"], :desc => "ignore following files", :default => ""
2585
+ method_option :ignore, :type => :string, :aliases => ["-i", "--ignore"], :desc => "ignore following files", :default => ""
2581
2586
 
2582
2587
  def exec_remote(*cmd)
2583
2588
  verify_logged_in(true)
@@ -2589,6 +2594,7 @@ module Cnvrg
2589
2594
  grid = options["grid"] || nil
2590
2595
  data = options["data"] || nil
2591
2596
  data_commit = options["data_commit"] || nil
2597
+ sync_before = options["sync_before"]
2592
2598
 
2593
2599
  instance_type = options["machine_type"] || nil
2594
2600
  schedule = options["schedule"] || ""
@@ -2652,9 +2658,23 @@ module Cnvrg
2652
2658
  image_slug = image.image_slug
2653
2659
  end
2654
2660
 
2661
+ invoke :sync, [false], [] if sync_before
2655
2662
 
2656
- invoke :sync, [false], []
2657
2663
 
2664
+ if command.include? "'"
2665
+ oc = command.to_enum(:scan, /'/).map { Regexp.last_match }
2666
+ pairs = oc.enum_for(:each_slice, 2).to_a
2667
+ pairs.each_with_index do |p,i|
2668
+ add=0
2669
+ if i!=0
2670
+ add=2*i
2671
+ end
2672
+ total_loc = command[p[0].offset(0)[0]+add..p[1].offset(0)[0]+add]
2673
+ command[p[0].offset(0)[0]+add..p[1].offset(0)[0]+add] = "\"#{total_loc}\""
2674
+ end
2675
+
2676
+
2677
+ end
2658
2678
  say "Running remote experiment", Thor::Shell::Color::BLUE
2659
2679
  exp = Experiment.new(project.owner, project.slug)
2660
2680
  res = exp.exec_remote(command, commit_to_run, instance_type, image_slug, schedule, local_timestamp, grid, path_to_cmd, data, data_commit)
@@ -4573,6 +4593,9 @@ module Cnvrg
4573
4593
 
4574
4594
  config = YAML.load_file(File.expand_path('~')+"/.cnvrg/config.yml")
4575
4595
  version_date = config.to_h[:version_last_check]
4596
+ if version_date.nil?
4597
+ version_date = get_start_day()
4598
+ end
4576
4599
  next_day = get_start_day+ 86399
4577
4600
  if not (version_date..next_day).cover?(Time.now)
4578
4601
  if should_update_version()
@@ -4848,73 +4871,30 @@ module Cnvrg
4848
4871
  `tar -xvf #{file_path} -C #{dir_path} > /dev/null 2>&1`
4849
4872
  return $?.success?
4850
4873
  end
4851
- end
4852
- end
4853
- class Data < SubCommandBase
4854
- desc "data init", "init data folder"
4855
- method_option :public, :type => :boolean, :aliases => ["-p", "--public"], :default => false
4856
-
4857
- def init
4858
- cli = Cnvrg::CLI.new()
4859
- public = options["public"]
4860
- cli.init_data(public)
4861
- end
4862
-
4863
- desc "data upload", "upload data folder"
4864
- method_option :ignore, :type => :array, :aliases => ["-i", "--i"], :desc => "ignore following files"
4865
- method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
4866
- method_option :sync, :type => :boolean, :aliases => ["-s"], :default => false
4867
-
4868
- def upload
4869
- cli = Cnvrg::CLI.new()
4870
- ignore = options["ignore"]
4871
- verbose = options["verbose"]
4872
- sync = options["sync"]
4873
-
4874
- cli.upload_data_tar(ignore, verbose, sync)
4875
- end
4876
-
4877
- desc 'data download', 'pull data'
4878
- method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
4879
- method_option :sync, :type => :boolean, :aliases => ["-s"], :default => false
4880
-
4881
- def download()
4882
- cli = Cnvrg::CLI.new()
4883
- verbose = options["verbose"]
4884
- sync = options["sync"]
4885
-
4886
- cli.download_data(verbose, sync, Dir.pwd)
4887
-
4888
- end
4889
4874
 
4890
- desc 'data clone', 'clone datset'
4875
+ def with_progress_bar
4876
+ not_done = true
4877
+ upload_progress_bar = ProgressBar.create(:title => "Upload progress",
4878
+ :format => '%a <%B> %p%% %t',
4879
+ :starting_at => 0,
4880
+ :total => 600)
4881
+ pb = Thread.new do
4882
+ while not_done do
4883
+ upload_progress_bar.increment
4884
+ sleep(1)
4891
4885
 
4892
- def clone(dataset_url)
4893
- cli = Cnvrg::CLI.new()
4894
- cli.clone_data(dataset_url)
4895
-
4896
- end
4897
-
4898
- desc 'data list', 'list of datasets'
4899
-
4900
- def list()
4901
- cli = Cnvrg::CLI.new()
4902
-
4903
- cli.list_dataset()
4886
+ end
4887
+ end
4904
4888
 
4889
+ yield.tap do # After yielding to the block, save the return value
4890
+ not_done = false # Tell the thread to exit, cleaning up after itself…
4891
+ pb.join # …and wait for it to do so.
4892
+ end
4893
+ end
4905
4894
  end
4906
4895
 
4907
- desc 'data commits', 'pull data'
4908
-
4909
- def commits()
4910
- cli = Cnvrg::CLI.new()
4911
- cli.list_dataset_commits()
4912
-
4913
- end
4914
4896
 
4915
4897
  end
4916
-
4917
4898
  end
4918
4899
 
4919
4900
 
4920
-
@@ -241,20 +241,23 @@ module Cnvrg
241
241
  response = http.request request
242
242
  body = response.read_body
243
243
  end
244
+ is_python = false
245
+ s4cmd_suc = false
246
+ s4cmd_install_suc = false
244
247
 
245
248
  URLcrypt::key = [body].pack('H*')
246
249
 
247
- python_version=`python --version > /dev/null 2>&1` ; is_python=$?.success?
248
- if is_python
249
-
250
- s4cmd=`pip freeze 2>/dev/null |grep -e s4cmd -e boto3 > /dev/null 2>&1` ; s4cmd_suc=$?.success?
251
- if !s4cmd_suc
252
- `pip install s4cmd > /dev/null 2>&1` ; s4cmd_install_suc=$?.success?
253
- end
254
-
255
- end
256
-
257
- if !s4cmd_suc or !s4cmd_suc or !s4cmd_install_suc
250
+ # python_version=`python --version > /dev/null 2>&1` ; is_python=$?.success?
251
+ # if is_python
252
+ #
253
+ # s4cmd=`pip freeze 2>/dev/null |grep -e s4cmd -e boto3 > /dev/null 2>&1` ; s4cmd_suc=$?.success?
254
+ # if !s4cmd_suc
255
+ # `pip install s4cmd > /dev/null 2>&1` ; s4cmd_install_suc=$?.success?
256
+ # end
257
+ #
258
+ # end
259
+
260
+ if !s4cmd_suc and !s4cmd_install_suc
258
261
  s3 = Aws::S3::Resource.new(
259
262
  :access_key_id => URLcrypt.decrypt(upload_resp["result"]["sts_a"]),
260
263
  :secret_access_key => URLcrypt.decrypt(upload_resp["result"]["sts_s"]),
@@ -289,10 +292,10 @@ module Cnvrg
289
292
  tmp.flush
290
293
  tmp.close
291
294
 
292
- is_success = false
295
+ is_success = false
293
296
  count = 0
294
297
  while !is_success and count <3
295
- resp = `python #{tmp.path} --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`
298
+ 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`
296
299
  is_success =$?.success?
297
300
  count +=1
298
301
 
@@ -479,7 +482,7 @@ module Cnvrg
479
482
 
480
483
  response = Cnvrg::API.request("#{base_resource}/commit/start", 'POST', {dataset_slug: @dataset_slug,new_branch:false,
481
484
  username: @owner})
482
- Cnvrg::CLI.is_response_success(response)
485
+ Cnvrg::CLI.is_response_success(response,false)
483
486
  return response
484
487
  end
485
488
 
data/lib/cnvrg/dataset.rb CHANGED
@@ -168,8 +168,6 @@ module Cnvrg
168
168
 
169
169
  File.open(".cnvrgignore", "w+") { |f| f.write cnvrgignore } unless File.exist? ".cnvrgignore"
170
170
  rescue => e
171
- puts e
172
- puts e.backtrace
173
171
  return false
174
172
  end
175
173
  return true
@@ -230,7 +228,7 @@ module Cnvrg
230
228
  def downlowd_updated_data(current_commit)
231
229
 
232
230
  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/downlowd_updated_data", 'POST', {current_commit: current_commit})
233
- CLI.is_response_success(response)
231
+ CLI.is_response_success(response,false)
234
232
  return response
235
233
  end
236
234
  def compare_idx(new_branch, commit=last_local_commit,local_idx=nil)
@@ -239,7 +237,7 @@ module Cnvrg
239
237
  end
240
238
 
241
239
  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/status", 'POST', {idx: local_idx, new_branch: new_branch, current_commit: commit})
242
- CLI.is_response_success(response)
240
+ CLI.is_response_success(response,false)
243
241
  return response
244
242
  end
245
243
 
@@ -247,7 +245,7 @@ module Cnvrg
247
245
 
248
246
  def compare_commits(commit)
249
247
  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/compare_commits", 'POST', {compare_commit: commit,current_commit:last_local_commit})
250
- CLI.is_response_success(response)
248
+ CLI.is_response_success(response,false)
251
249
  return response
252
250
  end
253
251
 
@@ -256,7 +254,7 @@ module Cnvrg
256
254
  commit = last_local_commit
257
255
  end
258
256
  response = Cnvrg::API.request("users/#{self.owner}/projects/#{self.slug}/commit/compare", 'POST', {current_commit: commit})
259
- CLI.is_response_success(response)
257
+ CLI.is_response_success(response,false)
260
258
  update_is_new_branch(response["result"]["new_branch"])
261
259
  return response["result"]["new_branch"]
262
260
  end
@@ -13,7 +13,7 @@ module Cnvrg
13
13
  res = Cnvrg::API.request(@base_resource + "experiment/start", 'POST',
14
14
  {input: input, platform: platform, machine_name: machine_name, start_commit: start_commit,
15
15
  title: name, email_notification: email_notification, machine_activity: machine_activity,script_path:script_path})
16
- Cnvrg::CLI.is_response_success(res)
16
+ Cnvrg::CLI.is_response_success(res,false)
17
17
 
18
18
  @slug = res.to_h["result"].to_h["slug"]
19
19
 
@@ -37,7 +37,7 @@ module Cnvrg
37
37
  def end_notebook_session(notebook_slug, end_commit)
38
38
  res = Cnvrg::API.request(@base_resource + "notebook/end_session", 'POST',
39
39
  {notebook_slug: notebook_slug, end_commit: end_commit})
40
- Cnvrg::CLI.is_response_success(res)
40
+ Cnvrg::CLI.is_response_success(res,false)
41
41
 
42
42
  return res
43
43
 
@@ -94,7 +94,7 @@ module Cnvrg
94
94
  response = Cnvrg::API.request(@base_resource + "experiment/upload_temp_log", 'POST', {output: temp_log,
95
95
  exp_slug: @slug, cpu_average: cpu_average,
96
96
  memory_average: memory_average})
97
- Cnvrg::CLI.is_response_success(response)
97
+ Cnvrg::CLI.is_response_success(response,false)
98
98
  end
99
99
 
100
100
  def end(output, exit_status, end_commit, cpu_average, memory_average)
@@ -102,7 +102,7 @@ module Cnvrg
102
102
  response = Cnvrg::API.request(@base_resource + "experiment/end", 'POST', {output: output, exp_slug: @slug,
103
103
  exit_status: exit_status, end_commit: end_commit,
104
104
  cpu_average: cpu_average, memory_average: memory_average})
105
- Cnvrg::CLI.is_response_success(response)
105
+ Cnvrg::CLI.is_response_success(response,false)
106
106
 
107
107
  begin
108
108
  FileUtils.rm_rf(["/home/ds/.cnvrg/tmp/exec.log"])
data/lib/cnvrg/files.rb CHANGED
@@ -26,7 +26,7 @@ module Cnvrg
26
26
 
27
27
  upload_resp = Cnvrg::API.request(@base_resource + "upload_file", 'POST_FILE', {absolute_path: absolute_path, relative_path: relative_path,
28
28
  commit_sha1: commit_sha1, file_name: file_name,
29
- file_size: file_size, file_content_type: content_type, sha1:sha1})
29
+ file_size: file_size, file_content_type: content_type, sha1: sha1})
30
30
  if Cnvrg::CLI.is_response_success(upload_resp, false)
31
31
  path = upload_resp["result"]["path"]
32
32
  if file_size.to_f>= Cnvrg::Files::LARGE_FILE.to_f
@@ -36,24 +36,25 @@ module Cnvrg
36
36
  end
37
37
  return s3_res
38
38
  # if s3_res
39
- # update_s3_resp = Cnvrg::API.request(@base_resource + "update_s3", 'POST', {path: path, commit_id: upload_resp["result"]["commit_id"],
40
- # blob_id: upload_resp["result"]["id"]})
41
- # is_suc = Cnvrg::CLI.is_response_success(update_s3_resp, false)
42
- #
43
- # return is_suc
39
+ # update_s3_resp = Cnvrg::API.request(@base_resource + "update_s3", 'POST', {path: path, commit_id: upload_resp["result"]["commit_id"],
40
+ # blob_id: upload_resp["result"]["id"]})
41
+ # is_suc = Cnvrg::CLI.is_response_success(update_s3_resp, false)
42
+ #
43
+ # return is_suc
44
44
  end
45
45
  return false
46
46
  end
47
- def upload_log_file(absolute_path, relative_path,log_date)
47
+
48
+ def upload_log_file(absolute_path, relative_path, log_date)
48
49
  file_name = File.basename relative_path
49
50
  file_size = File.size(absolute_path).to_f
50
51
  content_type = "text/x-log"
51
52
  upload_resp = Cnvrg::API.request("/users/#{@owner}/" + "upload_cli_log", 'POST_FILE', {absolute_path: absolute_path, relative_path: relative_path,
52
- file_name: file_name,log_date:log_date,
53
- file_size: file_size, file_content_type: content_type})
53
+ file_name: file_name, log_date: log_date,
54
+ file_size: file_size, file_content_type: content_type})
54
55
  if Cnvrg::CLI.is_response_success(upload_resp, false)
55
- path = upload_resp["result"]["path"]
56
- s3_res = upload_small_files_s3(path, absolute_path, "text/plain")
56
+ path = upload_resp["result"]["path"]
57
+ s3_res = upload_small_files_s3(path, absolute_path, "text/plain")
57
58
  end
58
59
  if s3_res
59
60
  return true
@@ -61,18 +62,19 @@ module Cnvrg
61
62
  return false
62
63
 
63
64
  end
64
- def upload_exec_file(absolute_path,image_name,commit_id)
65
+
66
+ def upload_exec_file(absolute_path, image_name, commit_id)
65
67
  file_name = File.basename absolute_path
66
68
  file_size = File.size(absolute_path).to_f
67
69
  content_type = "application/zip"
68
70
  begin
69
71
  upload_resp = Cnvrg::API.request("users/#{@owner}/images/" + "upload_config", 'POST_FILE', {relative_path: absolute_path,
70
72
  file_name: file_name,
71
- image_name:image_name,
73
+ image_name: image_name,
72
74
  file_size: file_size,
73
75
  file_content_type: content_type,
74
76
  project_slug: @project_slug,
75
- commit_id:commit_id})
77
+ commit_id: commit_id})
76
78
  # puts upload_resp
77
79
  if Cnvrg::CLI.is_response_success(upload_resp, false)
78
80
  if upload_resp["result"]["image"] == -1
@@ -82,21 +84,20 @@ module Cnvrg
82
84
  s3_res = upload_small_files_s3(path, absolute_path, content_type)
83
85
 
84
86
  end
85
- if s3_res
86
- return upload_resp["result"]["id"]
87
+ if s3_res
88
+ return upload_resp["result"]["id"]
89
+ end
90
+ return false
91
+ rescue SignalException
92
+
93
+ say "\nAborting"
94
+ exit(1)
87
95
  end
88
- return false
89
- rescue SignalException
90
96
 
91
- say "\nAborting"
92
- exit(1)
93
97
  end
94
98
 
95
- end
96
99
 
97
-
98
-
99
- def upload_image(absolute_path, image_name, owner, is_public, is_base,dpkg,libraries,bash,message,commit_id)
100
+ def upload_image(absolute_path, image_name, owner, is_public, is_base, dpkg, libraries, bash, message, commit_id)
100
101
  file_name = File.basename absolute_path
101
102
  file_size = File.size(absolute_path).to_f
102
103
  if is_base
@@ -106,41 +107,42 @@ module Cnvrg
106
107
  content_type = "application/gzip"
107
108
  end
108
109
  begin
109
- upload_resp = Cnvrg::API.request("users/#{owner}/images/" + "upload_cnvrg", 'POST_FILE', {relative_path: absolute_path,
110
- file_name: file_name,
111
- image_name: image_name,
112
- file_size: file_size,
113
- file_content_type: content_type,
114
- is_public: is_public,
115
- project_slug: @project_slug,
116
- commit_id:commit_id ,
117
- dpkg: dpkg,
118
- py2: libraries,
119
- py3: libraries,
120
-
121
- bash_history: bash,
122
- commit_message:message,
123
- is_base: is_base})
124
- # puts upload_resp
125
- if Cnvrg::CLI.is_response_success(upload_resp, false)
126
- path = upload_resp["result"]["path"]
127
- s3_res = upload_small_files_s3(path, absolute_path, content_type)
128
- if s3_res
129
- commit_resp = Cnvrg::API.request("users/#{owner}/images/#{upload_resp["result"]["id"]}/" + "commit", 'GET')
130
- if Cnvrg::CLI.is_response_success(commit_resp, false)
131
- return commit_resp["result"]["image"]
132
- else
133
- return false
134
- end
110
+ upload_resp = Cnvrg::API.request("users/#{owner}/images/" + "upload_cnvrg", 'POST_FILE', {relative_path: absolute_path,
111
+ file_name: file_name,
112
+ image_name: image_name,
113
+ file_size: file_size,
114
+ file_content_type: content_type,
115
+ is_public: is_public,
116
+ project_slug: @project_slug,
117
+ commit_id: commit_id,
118
+ dpkg: dpkg,
119
+ py2: libraries,
120
+ py3: libraries,
121
+
122
+ bash_history: bash,
123
+ commit_message: message,
124
+ is_base: is_base})
125
+ # puts upload_resp
126
+ if Cnvrg::CLI.is_response_success(upload_resp, false)
127
+ path = upload_resp["result"]["path"]
128
+ s3_res = upload_small_files_s3(path, absolute_path, content_type)
129
+ if s3_res
130
+ commit_resp = Cnvrg::API.request("users/#{owner}/images/#{upload_resp["result"]["id"]}/" + "commit", 'GET')
131
+ if Cnvrg::CLI.is_response_success(commit_resp, false)
132
+ return commit_resp["result"]["image"]
133
+ else
134
+ return false
135
+ end
135
136
 
137
+ end
136
138
  end
137
- end
138
- return false
139
- rescue =>e
139
+ return false
140
+ rescue => e
140
141
  end
141
142
 
142
143
  end
143
- def upload_cnvrg_image(absolute_path, image_name, owner, is_public, is_base,dpkg,libraries,bash,message)
144
+
145
+ def upload_cnvrg_image(absolute_path, image_name, owner, is_public, is_base, dpkg, libraries, bash, message)
144
146
  file_name = File.basename absolute_path
145
147
  file_size = File.size(absolute_path).to_f
146
148
  if is_base
@@ -151,16 +153,16 @@ module Cnvrg
151
153
  end
152
154
  begin
153
155
  upload_resp = Cnvrg::API.request("users/#{owner}/images/" + "upload_cnvrg", 'POST_FILE', {relative_path: absolute_path,
154
- file_name: file_name,
155
- image_name: image_name,
156
- file_size: file_size,
157
- file_content_type: content_type,
158
- is_public: is_public,
159
- dpkg: dpkg,
160
- libraries: libraries,
161
- bash_history: bash,
162
- commit_message:message,
163
- is_base: is_base})
156
+ file_name: file_name,
157
+ image_name: image_name,
158
+ file_size: file_size,
159
+ file_content_type: content_type,
160
+ is_public: is_public,
161
+ dpkg: dpkg,
162
+ libraries: libraries,
163
+ bash_history: bash,
164
+ commit_message: message,
165
+ is_base: is_base})
164
166
  # puts upload_resp
165
167
  if Cnvrg::CLI.is_response_success(upload_resp, false)
166
168
  path = upload_resp["result"]["path"]
@@ -176,7 +178,7 @@ module Cnvrg
176
178
  end
177
179
  end
178
180
  return false
179
- rescue =>e
181
+ rescue => e
180
182
  end
181
183
 
182
184
  end
@@ -208,225 +210,260 @@ module Cnvrg
208
210
 
209
211
  def upload_large_files_s3(upload_resp, file_path)
210
212
  begin
211
- sts_path = upload_resp["result"]["path_sts"]
212
- s4cmd_path = upload_resp["result"]["path_s4cmd"]
213
-
214
- uri = URI.parse(sts_path)
215
- http_object = Net::HTTP.new(uri.host, uri.port)
216
- http_object.use_ssl = true if uri.scheme == 'https'
217
- request = Net::HTTP::Get.new(sts_path)
218
-
219
- body = ""
220
- http_object.start do |http|
221
- response = http.request request
222
- body = response.read_body
223
- end
224
-
225
- URLcrypt::key = [body].pack('H*')
226
-
227
- python_version=`python --version > /dev/null 2>&1` ; is_python=$?.success?
228
- if is_python
229
-
230
- s4cmd=`pip freeze 2>/dev/null |grep -e s4cmd -e boto3 > /dev/null 2>&1` ; s4cmd_suc=$?.success?
231
- if !s4cmd_suc
232
- `pip install s4cmd > /dev/null 2>&1` ; s4cmd_install_suc=$?.success?
213
+ # speed_uri = URI.parse("https://s3-us-west-2.amazonaws.com/cnvrgw2-dev/speedtest-cli")
214
+ # speed_http_object = Net::HTTP.new(speed_uri.host, speed_uri.port)
215
+ # speed_http_object.use_ssl = true if speed_uri.scheme == 'https'
216
+ # speed_request = Net::HTTP::Get.new("https://s3-us-west-2.amazonaws.com/cnvrgw2-dev/speedtest-cli")
217
+ #
218
+ # speed_body = ""
219
+ # speed_http_object.start do |http|
220
+ # response = http.request speed_request
221
+ # speed_body = response.read_body
222
+ # end
223
+ # speed_tmp = Tempfile.new('speed')
224
+ # speed_tmp << speed_body
225
+ # speed_tmp.flush
226
+ # speed_tmp.close
227
+ # count = 0
228
+ # sum = 0
229
+ # speed_res = `python #{speed_tmp.path} --json`
230
+ # if !speed_res.nil? and !speed_res.empty?
231
+ # upload = JSON.parse(speed_res)["upload"]
232
+ # if !upload.nil?
233
+ # up_spped = (upload/1000000).round(2)
234
+ # end
235
+ #
236
+ #
237
+ # file_size = File.size(file_path)/1048576
238
+ # est_up = ((file_size*8)/up_spped)/60
239
+ # puts est_up
240
+ # end
241
+
242
+
243
+ sts_path = upload_resp["result"]["path_sts"]
244
+ s4cmd_path = upload_resp["result"]["path_s4cmd"]
245
+
246
+ uri = URI.parse(sts_path)
247
+ http_object = Net::HTTP.new(uri.host, uri.port)
248
+ http_object.use_ssl = true if uri.scheme == 'https'
249
+ request = Net::HTTP::Get.new(sts_path)
250
+
251
+ body = ""
252
+ http_object.start do |http|
253
+ response = http.request request
254
+ body = response.read_body
233
255
  end
234
256
 
235
- end
236
- if !s4cmd_suc or !s4cmd_suc or !s4cmd_install_suc
237
- s3 = Aws::S3::Resource.new(
238
- :access_key_id => URLcrypt.decrypt(upload_resp["result"]["sts_a"]),
239
- :secret_access_key => URLcrypt.decrypt(upload_resp["result"]["sts_s"]),
240
- :session_token => URLcrypt.decrypt(upload_resp["result"]["sts_st"]),
241
- :region => URLcrypt.decrypt(upload_resp["result"]["region"]))
242
- resp = s3.bucket(URLcrypt.decrypt(upload_resp["result"]["bucket"])).
243
- object(upload_resp["result"]["path"]+"/"+File.basename(file_path)).
244
- upload_file(file_path,{:use_accelerate_endpoint=>true})
245
- else
246
- s4cmd_uri = URI.parse(s4cmd_path)
247
- s4cmd_http_object = Net::HTTP.new(s4cmd_uri.host, s4cmd_uri.port)
248
- s4cmd_http_object.use_ssl = true if s4cmd_uri.scheme == 'https'
249
- s4cmd_request = Net::HTTP::Get.new(s4cmd_path)
250
-
251
- s4cmd_body = ""
252
- s4cmd_http_object.start do |http|
253
- response = http.request s4cmd_request
254
- s4cmd_body = response.read_bodyo
255
- end
256
- s4cmd_new_body = s4cmd_body.gsub(" self.client = self.boto3.client('s3',
257
+ URLcrypt::key = [body].pack('H*')
258
+ is_python = false
259
+ s4cmd_suc = false
260
+ s4cmd_install_suc = false
261
+ # python_version=`python --version > /dev/null 2>&1`; is_python=$?.success?
262
+ # if is_python
263
+ #
264
+ # s4cmd=`pip freeze 2>/dev/null |grep -e s4cmd -e boto3 > /dev/null 2>&1`; s4cmd_suc=$?.success?
265
+ # if !s4cmd_suc
266
+ # `pip install s4cmd > /dev/null 2>&1`; s4cmd_install_suc=$?.success?
267
+ # end
268
+ #
269
+ # end
270
+ if !s4cmd_suc and !s4cmd_install_suc
271
+ s3 = Aws::S3::Resource.new(
272
+ :access_key_id => URLcrypt.decrypt(upload_resp["result"]["sts_a"]),
273
+ :secret_access_key => URLcrypt.decrypt(upload_resp["result"]["sts_s"]),
274
+ :session_token => URLcrypt.decrypt(upload_resp["result"]["sts_st"]),
275
+ :region => URLcrypt.decrypt(upload_resp["result"]["region"]))
276
+ resp = s3.bucket(URLcrypt.decrypt(upload_resp["result"]["bucket"])).
277
+ object(upload_resp["result"]["path"]+"/"+File.basename(file_path)).
278
+ upload_file(file_path, {:use_accelerate_endpoint => true})
279
+ else
280
+ s4cmd_uri = URI.parse(s4cmd_path)
281
+ s4cmd_http_object = Net::HTTP.new(s4cmd_uri.host, s4cmd_uri.port)
282
+ s4cmd_http_object.use_ssl = true if s4cmd_uri.scheme == 'https'
283
+ s4cmd_request = Net::HTTP::Get.new(s4cmd_path)
284
+
285
+ s4cmd_body = ""
286
+ s4cmd_http_object.start do |http|
287
+ response = http.request s4cmd_request
288
+ s4cmd_body = response.read_body
289
+ end
290
+ s4cmd_new_body = s4cmd_body.gsub(" self.client = self.boto3.client('s3',
257
291
  aws_access_key_id=aws_access_key_id,
258
- aws_secret_access_key=aws_secret_access_key)"," self.client = self.boto3.client('s3',
292
+ aws_secret_access_key=aws_secret_access_key)", " self.client = self.boto3.client('s3',
259
293
  aws_access_key_id='#{ URLcrypt.decrypt(upload_resp["result"]["sts_a"])}',
260
294
  aws_secret_access_key='#{URLcrypt.decrypt(upload_resp["result"]["sts_s"])}',
261
295
  aws_session_token='#{URLcrypt.decrypt(upload_resp["result"]["sts_st"])}')")
262
296
 
263
297
 
264
- tmp = Tempfile.new('s4cmd.py')
265
- tmp << s4cmd_new_body
266
- tmp.flush
267
- tmp.close
298
+ tmp = Tempfile.new('s4cmd.py')
299
+ tmp << s4cmd_new_body
300
+ tmp.flush
301
+ tmp.close
302
+ #
303
+ is_success = false
304
+ count = 0
305
+ while !is_success and count <3
306
+ 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 `
307
+ is_success =$?.success?
308
+ count +=1
268
309
 
269
- is_success = false
270
- count = 0
271
- while !is_success and count <3
272
- resp = `python #{tmp.path} --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`
273
- is_success =$?.success?
274
- count +=1
310
+ end
311
+ resp= is_success
275
312
 
276
313
  end
277
- resp= is_success
278
314
 
279
- end
315
+ return resp
280
316
 
281
- return resp
317
+ rescue => e
318
+ if File.exist? tmp
319
+ FileUtils.rm_rf [tmp]
320
+ end
321
+ return false
282
322
 
283
- rescue =>e
284
- if File.exist? tmp
285
- FileUtils.rm_rf [tmp]
286
323
  end
287
- return false
324
+ return true
288
325
 
289
326
  end
290
- return true
291
327
 
292
- end
328
+ def upload_small_files_s3(url_path, file_path, content_type)
329
+ url = URI.parse(url_path)
330
+ file = File.open(file_path, "rb")
331
+ body = file.read
332
+ begin
333
+ Net::HTTP.start(url.host) do |http|
334
+ http.send_request("PUT", url.request_uri, body, {
335
+ "content-type" => content_type,
336
+ })
337
+ end
338
+ return true
339
+ rescue Interrupt
340
+ return false
341
+ rescue
342
+ return false
343
+ end
344
+ end
293
345
 
294
- def upload_small_files_s3(url_path, file_path, content_type)
295
- url = URI.parse(url_path)
296
- file = File.open(file_path, "rb")
297
- body = file.read
298
- begin
299
- Net::HTTP.start(url.host) do |http|
300
- http.send_request("PUT", url.request_uri, body, {
301
- "content-type" => content_type,
302
- })
346
+ def upload_url(file_path)
347
+ response = Cnvrg::API.request(@base_resource + "upload_url", 'POST', {file_s3_path: file_path})
348
+ if Cnvrg::CLI.is_response_success(response, false)
349
+ return response
350
+ else
351
+ return nil
303
352
  end
304
- return true
305
- rescue Interrupt
306
- return false
307
- rescue
308
- return false
353
+
309
354
  end
310
- end
311
355
 
312
- def upload_url(file_path)
313
- response = Cnvrg::API.request(@base_resource + "upload_url", 'POST', {file_s3_path: file_path})
314
- if Cnvrg::CLI.is_response_success(response, false)
315
- return response
316
- else
317
- return nil
356
+ def delete_file(absolute_path, relative_path, commit_sha1)
357
+ response = Cnvrg::API.request(@base_resource + "delete_file", 'DELETE', {absolute_path: absolute_path, relative_path: relative_path, commit_sha1: commit_sha1})
358
+ return Cnvrg::CLI.is_response_success(response, false)
318
359
  end
319
360
 
320
- end
361
+ def delete_dir(absolute_path, relative_path, commit_sha1)
362
+ response = Cnvrg::API.request(@base_resource + "delete_dir", 'DELETE', {absolute_path: absolute_path, relative_path: relative_path, commit_sha1: commit_sha1})
363
+ return Cnvrg::CLI.is_response_success(response, false)
364
+ end
321
365
 
322
- def delete_file(absolute_path, relative_path, commit_sha1)
323
- response = Cnvrg::API.request(@base_resource + "delete_file", 'DELETE', {absolute_path: absolute_path, relative_path: relative_path, commit_sha1: commit_sha1})
324
- return Cnvrg::CLI.is_response_success(response, false)
325
- end
366
+ def create_dir(absolute_path, relative_path, commit_sha1)
367
+ response = Cnvrg::API.request(@base_resource + "create_dir", 'POST', {absolute_path: absolute_path, relative_path: relative_path, commit_sha1: commit_sha1})
368
+ return Cnvrg::CLI.is_response_success(response, false)
369
+ end
326
370
 
327
- def delete_dir(absolute_path, relative_path, commit_sha1)
328
- response = Cnvrg::API.request(@base_resource + "delete_dir", 'DELETE', {absolute_path: absolute_path, relative_path: relative_path, commit_sha1: commit_sha1})
329
- return Cnvrg::CLI.is_response_success(response, false)
330
- end
371
+ def download_file_s3(absolute_path, relative_path, project_home, commit_sha1=nil, conflict=false)
372
+ begin
373
+ res = Cnvrg::API.request(@base_resource + "download_file", 'POST', {absolute_path: absolute_path, relative_path: relative_path, commit_sha1: commit_sha1})
374
+ Cnvrg::CLI.is_response_success(res, false)
375
+ if res["result"]
376
+ download_resp = res
377
+ filename = download_resp["result"]["filename"]
378
+
379
+ absolute_path += ".conflict" if conflict
380
+ sts_path = download_resp["result"]["path_sts"]
381
+ uri = URI.parse(sts_path)
382
+ http_object = Net::HTTP.new(uri.host, uri.port)
383
+ http_object.use_ssl = true if uri.scheme == 'https'
384
+ request = Net::HTTP::Get.new(sts_path)
385
+
386
+ body = ""
387
+ http_object.start do |http|
388
+ response = http.request request
389
+ body = response.read_body
390
+ end
391
+ URLcrypt::key = [body].pack('H*')
392
+ s3 = Aws::S3::Client.new(
393
+ :access_key_id => URLcrypt.decrypt(download_resp["result"]["sts_a"]),
394
+ :secret_access_key => URLcrypt.decrypt(download_resp["result"]["sts_s"]),
395
+ :session_token => URLcrypt.decrypt(download_resp["result"]["sts_st"]),
396
+ :region => URLcrypt.decrypt(download_resp["result"]["region"]))
397
+ File.open(project_home+"/"+absolute_path, 'wb') do |file|
398
+ resp = s3.get_object({bucket: URLcrypt.decrypt(download_resp["result"]["bucket"]),
399
+ key: URLcrypt.decrypt(download_resp["result"]["key"])}, target: file)
400
+ end
401
+ return true
402
+ end
331
403
 
332
- def create_dir(absolute_path, relative_path, commit_sha1)
333
- response = Cnvrg::API.request(@base_resource + "create_dir", 'POST', {absolute_path: absolute_path, relative_path: relative_path, commit_sha1: commit_sha1})
334
- return Cnvrg::CLI.is_response_success(response, false)
335
- end
336
- def download_file_s3(absolute_path, relative_path, project_home,commit_sha1=nil, conflict=false)
337
- begin
338
- res = Cnvrg::API.request(@base_resource + "download_file", 'POST', {absolute_path: absolute_path, relative_path: relative_path,commit_sha1:commit_sha1})
404
+ rescue => e
405
+ return false
406
+
407
+ end
408
+ end
409
+
410
+ def download_file(absolute_path, relative_path, project_home, conflict=false)
411
+ res = Cnvrg::API.request(@base_resource + "download_file", 'POST', {absolute_path: absolute_path, relative_path: relative_path})
339
412
  Cnvrg::CLI.is_response_success(res, false)
340
413
  if res["result"]
341
- download_resp = res
342
- filename = download_resp["result"]["filename"]
343
-
344
- absolute_path += ".conflict" if conflict
345
- sts_path = download_resp["result"]["path_sts"]
346
- uri = URI.parse(sts_path)
347
- http_object = Net::HTTP.new(uri.host, uri.port)
348
- http_object.use_ssl = true if uri.scheme == 'https'
349
- request = Net::HTTP::Get.new(sts_path)
350
-
351
- body = ""
352
- http_object.start do |http|
353
- response = http.request request
354
- body = response.read_body
355
- end
356
- URLcrypt::key = [body].pack('H*')
357
- s3 = Aws::S3::Client.new(
358
- :access_key_id => URLcrypt.decrypt(download_resp["result"]["sts_a"]),
359
- :secret_access_key => URLcrypt.decrypt(download_resp["result"]["sts_s"]),
360
- :session_token => URLcrypt.decrypt(download_resp["result"]["sts_st"]),
361
- :region => URLcrypt.decrypt(download_resp["result"]["region"]))
362
- File.open(project_home+"/"+absolute_path, 'wb') do |file|
363
- resp = s3.get_object({ bucket:URLcrypt.decrypt(download_resp["result"]["bucket"]),
364
- key:URLcrypt.decrypt(download_resp["result"]["key"])}, target: file)
365
- end
366
- return true
367
- end
414
+ res = res["result"]
415
+ return false if res["link"].empty? or res["filename"].empty?
416
+ filename = res["filename"]
417
+ file_location = absolute_path.gsub(/#{filename}\/?$/, "")
368
418
 
369
- rescue =>e
370
- return false
419
+ FileUtils.mkdir_p project_home + "/" + file_location
420
+ filename += ".conflict" if conflict
371
421
 
372
- end
373
- end
374
- def download_file(absolute_path, relative_path, project_home, conflict=false)
375
- res = Cnvrg::API.request(@base_resource + "download_file", 'POST', {absolute_path: absolute_path, relative_path: relative_path})
376
- Cnvrg::CLI.is_response_success(res, false)
377
- if res["result"]
378
- res = res["result"]
379
- return false if res["link"].empty? or res["filename"].empty?
380
- filename = res["filename"]
381
- file_location = absolute_path.gsub(/#{filename}\/?$/, "")
382
-
383
- FileUtils.mkdir_p project_home + "/" + file_location
384
- filename += ".conflict" if conflict
385
-
386
- File.open("#{project_home}/#{file_location}/#{filename}", "wb") do |file|
387
- file.write open(res["link"]).read
422
+ File.open("#{project_home}/#{file_location}/#{filename}", "wb") do |file|
423
+ file.write open(res["link"]).read
424
+ end
425
+ else
426
+ return false
388
427
  end
389
- else
390
- return false
428
+ return true
391
429
  end
392
- return true
393
- end
394
430
 
395
- def download_dir(absolute_path, relative_path, project_home)
396
- FileUtils.mkdir_p("#{project_home}/#{absolute_path}")
397
- end
398
- def revoke_download_dir(absolute_path, relative_path, project_home)
399
- puts FileUtils.rmtree("#{absolute_path}")
400
- end
431
+ def download_dir(absolute_path, relative_path, project_home)
432
+ FileUtils.mkdir_p("#{project_home}/#{absolute_path}")
433
+ end
401
434
 
402
- def revoke_download_file(project_home,absolute_path,filename,conflict=false)
403
- begin
404
- file_location = absolute_path.gsub(/#{filename}\/?$/, "")
435
+ def revoke_download_dir(absolute_path, relative_path, project_home)
436
+ puts FileUtils.rmtree("#{absolute_path}")
437
+ end
405
438
 
406
- filename += ".conflict" if conflict
407
- FileUtils.remove("#{file_location}/#{filename}")
408
- return true
409
- rescue
410
- return false
439
+ def revoke_download_file(project_home, absolute_path, filename, conflict=false)
440
+ begin
441
+ file_location = absolute_path.gsub(/#{filename}\/?$/, "")
442
+
443
+ filename += ".conflict" if conflict
444
+ FileUtils.remove("#{file_location}/#{filename}")
445
+ return true
446
+ rescue
447
+ return false
448
+ end
411
449
  end
412
- end
413
450
 
414
- def start_commit(new_branch)
451
+ def start_commit(new_branch)
415
452
 
416
- response = Cnvrg::API.request("#{base_resource}/commit/start", 'POST', {project_slug: @project_slug,new_branch:new_branch,
417
- username: @owner})
418
- Cnvrg::CLI.is_response_success(response)
419
- return response
420
- end
453
+ response = Cnvrg::API.request("#{base_resource}/commit/start", 'POST', {project_slug: @project_slug, new_branch: new_branch,
454
+ username: @owner})
455
+ Cnvrg::CLI.is_response_success(response,false)
456
+ return response
457
+ end
421
458
 
422
- def end_commit(commit_sha1)
423
- response = Cnvrg::API.request("#{base_resource}/commit/end", 'POST', {commit_sha1: commit_sha1})
424
- return response
425
- end
459
+ def end_commit(commit_sha1)
460
+ response = Cnvrg::API.request("#{base_resource}/commit/end", 'POST', {commit_sha1: commit_sha1})
461
+ return response
462
+ end
426
463
 
427
- def rollback_commit(commit_sha1)
428
- response = Cnvrg::API.request("#{base_resource}/commit/rollback", 'POST', {commit_sha1: commit_sha1})
429
- Cnvrg::CLI.is_response_success(response, false)
464
+ def rollback_commit(commit_sha1)
465
+ response = Cnvrg::API.request("#{base_resource}/commit/rollback", 'POST', {commit_sha1: commit_sha1})
466
+ Cnvrg::CLI.is_response_success(response, false)
467
+ end
430
468
  end
431
469
  end
432
- end
data/lib/cnvrg/project.rb CHANGED
@@ -23,9 +23,7 @@ module Cnvrg
23
23
  idx = YAML.load_file(@local_path + "/.cnvrg/idx.yml")
24
24
  return idx[:commit]
25
25
  end
26
- def get_last_commit
27
26
 
28
- end
29
27
 
30
28
  def url
31
29
  url = Cnvrg::Helpers.remote_url
@@ -293,7 +291,7 @@ module Cnvrg
293
291
 
294
292
  local_idx = self.generate_idx
295
293
  response = Cnvrg::API.request("users/#{self.owner}/projects/#{self.slug}/status", 'POST', {idx: local_idx, new_branch: new_branch, current_commit: commit})
296
- CLI.is_response_success(response)
294
+ CLI.is_response_success(response,false)
297
295
  return response
298
296
  end
299
297
 
@@ -302,7 +300,7 @@ module Cnvrg
302
300
  commit = last_local_commit
303
301
  end
304
302
  response = Cnvrg::API.request("users/#{self.owner}/projects/#{self.slug}/commit/compare", 'POST', {current_commit: commit})
305
- CLI.is_response_success(response)
303
+ CLI.is_response_success(response,false)
306
304
  update_is_new_branch(response["result"]["new_branch"])
307
305
  return response["result"]["new_branch"]
308
306
  end
data/lib/cnvrg/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Cnvrg
2
- VERSION = '0.0.1422'
2
+ VERSION = '0.0.1424'
3
3
 
4
4
  end
5
5
 
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.1422
4
+ version: 0.0.1424
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-06-17 00:00:00.000000000 Z
12
+ date: 2017-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -315,6 +315,20 @@ dependencies:
315
315
  - - "~>"
316
316
  - !ruby/object:Gem::Version
317
317
  version: '5.0'
318
+ - !ruby/object:Gem::Dependency
319
+ name: ruby-progressbar
320
+ requirement: !ruby/object:Gem::Requirement
321
+ requirements:
322
+ - - ">="
323
+ - !ruby/object:Gem::Version
324
+ version: '0'
325
+ type: :runtime
326
+ prerelease: false
327
+ version_requirements: !ruby/object:Gem::Requirement
328
+ requirements:
329
+ - - ">="
330
+ - !ruby/object:Gem::Version
331
+ version: '0'
318
332
  description: A CLI tool for interacting with cnvrg.io.
319
333
  email:
320
334
  - info@cnvrg.io