cnvrg 0.6.1 → 0.6.2
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.
- checksums.yaml +4 -4
- data/lib/cnvrg/api.rb +30 -0
- data/lib/cnvrg/cli.rb +81 -68
- data/lib/cnvrg/datafiles.rb +22 -10
- data/lib/cnvrg/dataset.rb +10 -1
- data/lib/cnvrg/experiment.rb +1 -1
- data/lib/cnvrg/helpers.rb +2 -1
- data/lib/cnvrg/project.rb +16 -0
- data/lib/cnvrg/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4256d8fe0490792ce6c903208f55fb334c090fb
|
4
|
+
data.tar.gz: 90297a245a2df22569c0f1b11135d09d35f7d1e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0abffec7afcb1f5ed6cbbf764cea7826e2aa267e3f5e7f80ba18b5c3338604f4bdb36ad10e8009438b2d2ae437406feed79d4273a7b8f9cfb76f7b2fac43befc
|
7
|
+
data.tar.gz: 8ba624643cbb0772f9fb08880ddb285012a936feb31fae3ef3ca9b0059fcc95da94801e68838a273c82f357e98c42682db96fb94488b295f0a40663ff629c249
|
data/lib/cnvrg/api.rb
CHANGED
@@ -105,6 +105,36 @@ module Cnvrg
|
|
105
105
|
else
|
106
106
|
response
|
107
107
|
end
|
108
|
+
when 'POST_JSON'
|
109
|
+
conn.options.timeout = 4200
|
110
|
+
conn.options.open_timeout =4200
|
111
|
+
conn.headers['Content-Type'] = "application/json"
|
112
|
+
new_data = JSON.dump(data)
|
113
|
+
|
114
|
+
retries = 0
|
115
|
+
success = false
|
116
|
+
|
117
|
+
while !success and retries < 20
|
118
|
+
begin
|
119
|
+
response = conn.post "#{resource}", new_data
|
120
|
+
success = true
|
121
|
+
|
122
|
+
rescue => e
|
123
|
+
sleep(5)
|
124
|
+
retries +=1
|
125
|
+
end
|
126
|
+
end
|
127
|
+
if !success
|
128
|
+
return false
|
129
|
+
end
|
130
|
+
if response.to_hash[:status] == 404
|
131
|
+
return false
|
132
|
+
end
|
133
|
+
if parse_request == true
|
134
|
+
JSON.parse(response.body)
|
135
|
+
else
|
136
|
+
response
|
137
|
+
end
|
108
138
|
when 'POST_FILE'
|
109
139
|
conn = Faraday.new do |fr|
|
110
140
|
fr.headers['Auth-Token'] = @pass
|
data/lib/cnvrg/cli.rb
CHANGED
@@ -842,20 +842,18 @@ module Cnvrg
|
|
842
842
|
:progress_mark => '=',
|
843
843
|
:format => "%b>>%i| %p%% %t",
|
844
844
|
:starting_at => 0,
|
845
|
+
:total => files_count,
|
845
846
|
:autofinish => true)
|
846
847
|
while files['keys'].length > 0
|
847
|
-
@files.download_multiple_files_s3(files, dataset_home)
|
848
|
+
@files.download_multiple_files_s3(files, dataset_home, progressbar: progressbar)
|
848
849
|
downloaded_files += files['keys'].length
|
849
|
-
progressbar.progress = (downloaded_files * 100 / files_count)
|
850
850
|
files = @files.get_clone_chunk(commit: commit, latest_id: files['latest'])
|
851
851
|
end
|
852
852
|
if downloaded_files == files_count
|
853
853
|
Dataset.verify_cnvrgignore_exist(dataset_name, false)
|
854
854
|
@dataset = Dataset.new(dataset_home)
|
855
|
-
@dataset.write_idx(nil, commit)
|
855
|
+
@dataset.write_idx(nil, commit) #nil means, generate idx
|
856
856
|
log_message("#{check} Clone finished successfully", Thor::Shell::Color::GREEN)
|
857
|
-
else
|
858
|
-
log_message(result.msg, result.msg_color)
|
859
857
|
end
|
860
858
|
else
|
861
859
|
log_message("Error: Couldn't create directory: #{dataset_name}", Thor::Shell::Color::RED)
|
@@ -1938,10 +1936,12 @@ module Cnvrg
|
|
1938
1936
|
method_option :tags, :type => :boolean, :aliases => ["--tags"], :desc => "upload file tags", :default => false
|
1939
1937
|
method_option :parallel, :type => :numeric, :aliases => ["-p", "--parallel"], :desc => "uparallel upload at the same time", :default => 15
|
1940
1938
|
def upload_data_new(new_branch, verbose,sync,force, tags, chunk_size)
|
1941
|
-
commit = invoke :start_commit_data,[], :new_branch=> new_branch, :direct=>false, :force =>force
|
1939
|
+
commit = invoke :start_commit_data,[], :new_branch=> new_branch, :direct=>false, :force =>force, :chunk_size => chunk_size
|
1942
1940
|
upload_res = invoke :upload_data_files,[commit],:new_branch=>new_branch, :verbose =>verbose, :force =>force, :sync =>sync, :chunk_size => chunk_size
|
1943
|
-
|
1944
|
-
|
1941
|
+
if !upload_res
|
1942
|
+
return
|
1943
|
+
end
|
1944
|
+
invoke :end_commit_data,[commit, success: upload_res] , :new_branch=>new_branch, :force =>force
|
1945
1945
|
if tags
|
1946
1946
|
log_message('Uploading Tags', Thor::Shell::Color::BLUE)
|
1947
1947
|
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
@@ -1970,6 +1970,7 @@ module Cnvrg
|
|
1970
1970
|
method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
|
1971
1971
|
method_option :direct, :type => :boolean, :aliases => ["-d","--direct"], :desc => "was called directed", :default => true
|
1972
1972
|
method_option :force, :type => :boolean, :aliases => ["-f","--force"], :default => false
|
1973
|
+
method_option :chunk_size, :type => :numeric, :aliases => ["-ch"], :default => 0
|
1973
1974
|
|
1974
1975
|
def start_commit_data()
|
1975
1976
|
begin
|
@@ -1979,30 +1980,38 @@ module Cnvrg
|
|
1979
1980
|
direct = options[:direct]
|
1980
1981
|
new_branch = options["new_branch"] || false
|
1981
1982
|
force = options["force"] || false
|
1983
|
+
chunk_size = options["chunk_size"] || false
|
1982
1984
|
commit_sha1 = nil
|
1983
1985
|
@dataset = Dataset.new(dataset_dir)
|
1984
1986
|
@files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug)
|
1985
|
-
next_commit = @dataset.get_next_commit
|
1986
|
-
|
1987
|
-
|
1988
|
-
|
1989
|
-
|
1990
|
-
|
1991
|
-
@dataset.set_next_commit(commit_sha1)
|
1992
|
-
else
|
1993
|
-
commit_sha1 = resp["result"]["commit_sha1"]
|
1994
|
-
end
|
1995
|
-
else
|
1996
|
-
resp = @files.start_commit(new_branch,force)
|
1997
|
-
commit_sha1 = resp["result"]["commit_sha1"]
|
1998
|
-
@dataset.set_next_commit(commit_sha1)
|
1987
|
+
next_commit = @dataset.get_next_commit #if there was a partial commit..
|
1988
|
+
chunks = (@dataset.list_all_files.length.to_f / chunk_size).ceil
|
1989
|
+
resp = @files.start_commit(new_branch, force, chunks: chunks, current_commit: next_commit || @dataset.last_local_commit)
|
1990
|
+
if !resp['result']['can_commit']
|
1991
|
+
log_message("Cant upload files because a new version of this dataset exists, please download it or upload with --force", Thor::Shell::Color::RED)
|
1992
|
+
exit(1)
|
1999
1993
|
end
|
1994
|
+
# if next_commit.present? #keep from existing commit.
|
1995
|
+
# resp = @files.get_commit(next_commit)
|
1996
|
+
# if resp["result"]["status"].eql? "new"
|
1997
|
+
# resp = @files.start_commit(new_branch,force, chunks: chunks)
|
1998
|
+
# commit_sha1 = resp["result"]["commit_sha1"]
|
1999
|
+
# @dataset.set_next_commit(commit_sha1)
|
2000
|
+
# else
|
2001
|
+
# commit_sha1 = resp["result"]["commit_sha1"]
|
2002
|
+
# end
|
2003
|
+
# else
|
2004
|
+
# resp = @files.start_commit(new_branch,force, chunks: chunks)
|
2005
|
+
# commit_sha1 = resp["result"]["commit_sha1"]
|
2006
|
+
# @dataset.set_next_commit(commit_sha1)
|
2007
|
+
# end
|
2008
|
+
commit_sha1 = resp["result"]["commit_sha1"]
|
2009
|
+
@dataset.set_next_commit(commit_sha1)
|
2000
2010
|
if direct
|
2001
2011
|
puts commit_sha1
|
2002
2012
|
end
|
2003
2013
|
return commit_sha1
|
2004
2014
|
rescue => e
|
2005
|
-
puts e
|
2006
2015
|
if commit_sha1.present?
|
2007
2016
|
@dataset.set_next_commit(commit_sha1)
|
2008
2017
|
end
|
@@ -2018,9 +2027,8 @@ module Cnvrg
|
|
2018
2027
|
desc 'end_commit', 'start data commit'
|
2019
2028
|
method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
|
2020
2029
|
method_option :force, :type => :boolean, :aliases => ["-f","--force"], :default => false
|
2021
|
-
method_option :success, :type => :boolean, :default => true, :hide=>true
|
2022
2030
|
|
2023
|
-
def end_commit_data(commit)
|
2031
|
+
def end_commit_data(commit, success: true)
|
2024
2032
|
begin
|
2025
2033
|
verify_logged_in(true)
|
2026
2034
|
log_start(__method__, args, options)
|
@@ -2028,21 +2036,14 @@ module Cnvrg
|
|
2028
2036
|
@dataset = Dataset.new(dataset_dir)
|
2029
2037
|
@files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug)
|
2030
2038
|
force = options["force"] || false
|
2031
|
-
resp = @files.end_commit(commit, force, options[:success])
|
2032
|
-
if (resp and resp["result"])
|
2033
|
-
if !options[:success]
|
2034
|
-
@dataset.set_next_commit(resp["result"]["commit_sha1"])
|
2035
|
-
@dataset.remove_next_commit
|
2036
|
-
else
|
2037
|
-
check = Helpers.checkmark
|
2038
|
-
@dataset.set_next_commit(commit)
|
2039
|
-
@dataset.remove_next_commit
|
2040
|
-
log_message("#{check} Data files were updated successfully", Thor::Shell::Color::GREEN)
|
2041
|
-
end
|
2042
|
-
|
2043
|
-
end
|
2044
|
-
|
2045
2039
|
|
2040
|
+
resp = @files.end_commit(commit, force, success: success)
|
2041
|
+
if (resp and resp["result"])
|
2042
|
+
check = Helpers.checkmark
|
2043
|
+
@dataset.set_next_commit(commit)
|
2044
|
+
@dataset.remove_next_commit
|
2045
|
+
log_message("#{check} Data files were updated successfully", Thor::Shell::Color::GREEN)
|
2046
|
+
end
|
2046
2047
|
rescue => e
|
2047
2048
|
puts e
|
2048
2049
|
rescue SignalException
|
@@ -2105,49 +2106,47 @@ module Cnvrg
|
|
2105
2106
|
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
2106
2107
|
@dataset = Dataset.new(dataset_dir)
|
2107
2108
|
@files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug)
|
2108
|
-
|
2109
|
-
if new_commit.blank?
|
2109
|
+
new_commit ||= @dataset.get_next_commit()
|
2110
|
+
if new_commit.blank?
|
2110
2111
|
log_message("You must specify commit, run start_commit to create new commit", Thor::Shell::Color::RED)
|
2111
|
-
|
2112
|
+
return false
|
2112
2113
|
end
|
2113
|
-
|
2114
2114
|
force = options[:force] || false
|
2115
2115
|
chunk_size = options[:chunk_size]
|
2116
2116
|
chunk_size = [chunk_size, 1].max
|
2117
2117
|
new_branch = options["new_branch"] || false
|
2118
|
+
new_tree = {}
|
2118
2119
|
force = options["force"] || false
|
2119
2120
|
parallel_threads = options["parallel"] || ParallelThreads
|
2120
|
-
|
2121
|
+
all_files = @dataset.list_all_files
|
2121
2122
|
progressbar = ProgressBar.create(:title => "Upload Progress",
|
2122
2123
|
:progress_mark => '=',
|
2123
2124
|
:format => "%b>>%i| %p%% %t",
|
2124
2125
|
:starting_at => 0,
|
2126
|
+
:total => all_files.length,
|
2125
2127
|
:autofinish => true)
|
2126
|
-
all_files = @dataset.list_all_files
|
2127
|
-
files_count = all_files.count
|
2128
|
-
finished_chunks = 0
|
2129
2128
|
files_uploaded = 0
|
2130
|
-
|
2131
|
-
chunked_files.each_with_index do |list_files,i|
|
2132
|
-
log_message("generating chunk #{i} / #{chunked_files.size}", Thor::Shell::Color::BLUE, false)
|
2129
|
+
all_files.each_slice(chunk_size).each do |list_files|
|
2133
2130
|
temp_tree = @dataset.generate_chunked_idx(list_files, threads: parallel_threads)
|
2131
|
+
upload_resp = @files.upload_multiple_files(new_commit, temp_tree, threads: parallel_threads, force: force, new_branch: new_branch, progressbar: progressbar)
|
2132
|
+
|
2133
|
+
if upload_resp.is_a? Cnvrg::Result
|
2134
|
+
log_message(upload_resp.msg, upload_resp.msg_color)
|
2135
|
+
|
2136
|
+
return false
|
2137
|
+
|
2138
|
+
else
|
2139
|
+
files_uploaded += upload_resp
|
2140
|
+
end
|
2134
2141
|
|
2135
|
-
log_message("uploading chunk #{i} / #{chunked_files.size}", Thor::Shell::Color::BLUE, false)
|
2136
|
-
files_uploaded += @files.upload_multiple_files(next_commit, temp_tree, threads: parallel_threads, force: force)
|
2137
2142
|
temp_tree.each do |k,v|
|
2138
|
-
|
2139
|
-
new_tree[k] = {sha1: v.try(:fetch, :sha1, nil), commit_time: nil}
|
2140
|
-
else
|
2141
|
-
new_tree[k] = nil
|
2142
|
-
end
|
2143
|
+
new_tree[k] = (v.present?) ? {sha1: v.try(:fetch, :sha1, nil), commit_time: nil} : nil
|
2143
2144
|
end
|
2144
|
-
@dataset.write_idx(new_tree,
|
2145
|
-
finished_chunks += 1
|
2146
|
-
progressbar.progress = [(finished_chunks * chunk_size*100) / files_count, 100].min
|
2145
|
+
@dataset.write_idx(new_tree, new_commit)
|
2147
2146
|
end
|
2148
2147
|
return files_uploaded > 0
|
2149
2148
|
rescue Exception => e
|
2150
|
-
|
2149
|
+
puts e
|
2151
2150
|
return false
|
2152
2151
|
end
|
2153
2152
|
|
@@ -2387,8 +2386,8 @@ module Cnvrg
|
|
2387
2386
|
if git_output_dir.ends_with? "/"
|
2388
2387
|
git_output_dir = git_output_dir[0..-2]
|
2389
2388
|
end
|
2390
|
-
|
2391
|
-
spec_files_to_upload
|
2389
|
+
list = @project.generate_output_dir(output_dir)
|
2390
|
+
spec_files_to_upload = list
|
2392
2391
|
if spec_files_to_upload.blank?
|
2393
2392
|
log_message("#{check} Project is up to date", Thor::Shell::Color::GREEN, (((options["sync"] or sync) and !direct) ? false : true))
|
2394
2393
|
return true
|
@@ -2398,6 +2397,7 @@ module Cnvrg
|
|
2398
2397
|
end
|
2399
2398
|
|
2400
2399
|
|
2400
|
+
|
2401
2401
|
if ignore.nil? or ignore.empty?
|
2402
2402
|
ignore = ignore_list
|
2403
2403
|
end
|
@@ -2416,6 +2416,7 @@ module Cnvrg
|
|
2416
2416
|
|
2417
2417
|
result = @project.compare_idx(new_branch, force: force, deploy: options["deploy"],in_exp:in_exp, specific_files: spec_files_to_upload)
|
2418
2418
|
commit = result["result"]["commit"]
|
2419
|
+
|
2419
2420
|
if !link
|
2420
2421
|
if (result["result"]["new_version_exist"] and !force) or ((commit != @project.last_local_commit and !@project.last_local_commit.nil? and !result["result"]["tree"]["updated_on_server"].empty?) and !force)
|
2421
2422
|
log_message("Remote server has an updated version, please run `cnvrg download` first, or alternatively: `cnvrg sync`", Thor::Shell::Color::BLUE)
|
@@ -2445,7 +2446,7 @@ module Cnvrg
|
|
2445
2446
|
log_message("Syncing files", Thor::Shell::Color::BLUE, ((options["sync"] or sync)) ? false : true)
|
2446
2447
|
end
|
2447
2448
|
# Start commit
|
2448
|
-
if in_exp
|
2449
|
+
if in_exp || (job_slug.present? and job_type.present?)
|
2449
2450
|
exp_start_commit = @project.last_local_commit
|
2450
2451
|
else
|
2451
2452
|
exp_start_commit = nil
|
@@ -2799,6 +2800,8 @@ module Cnvrg
|
|
2799
2800
|
log_message("#{check} Downloaded changes successfully", Thor::Shell::Color::GREEN, ((sync or options["sync"]) ? false : true))
|
2800
2801
|
end
|
2801
2802
|
return true
|
2803
|
+
else
|
2804
|
+
@dataset.update_idx_with_commit!(commit_to_download)
|
2802
2805
|
end
|
2803
2806
|
rescue => e
|
2804
2807
|
log_message("Error occurred, \nAborting", Thor::Shell::Color::BLUE)
|
@@ -2811,7 +2814,7 @@ module Cnvrg
|
|
2811
2814
|
end
|
2812
2815
|
|
2813
2816
|
desc 'download in git project', 'Download other files', :hide =>true
|
2814
|
-
def download_in_git(commit_sha1)
|
2817
|
+
def download_in_git(*commit_sha1)
|
2815
2818
|
begin
|
2816
2819
|
verify_logged_in(true)
|
2817
2820
|
log_start(__method__, args, options)
|
@@ -2826,7 +2829,11 @@ module Cnvrg
|
|
2826
2829
|
end
|
2827
2830
|
|
2828
2831
|
begin
|
2829
|
-
|
2832
|
+
if files["keys"].blank?
|
2833
|
+
log_message("No New files to download", Thor::Shell::Color::GREEN)
|
2834
|
+
return
|
2835
|
+
end
|
2836
|
+
download_result = @files.download_multpile_files_s3(files, project_home)
|
2830
2837
|
if download_result
|
2831
2838
|
log_message("Done.\nDownloaded finished successfully", Thor::Shell::Color::GREEN)
|
2832
2839
|
else
|
@@ -2836,7 +2843,6 @@ module Cnvrg
|
|
2836
2843
|
|
2837
2844
|
rescue => e
|
2838
2845
|
log_error(e)
|
2839
|
-
puts e.backtrace
|
2840
2846
|
log_message("Error while trying to download ", Thor::Shell::Color::RED)
|
2841
2847
|
return
|
2842
2848
|
end
|
@@ -2850,6 +2856,8 @@ module Cnvrg
|
|
2850
2856
|
method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
|
2851
2857
|
method_option :sync, :type => :boolean, :aliases => ["-s"], :default => false
|
2852
2858
|
method_option :ignore, :type => :string, :aliases => ["-i"], :desc => "ignore following files", :default => ""
|
2859
|
+
method_option :git, :type => :boolean, :aliases => ["--git"], :desc => "download from git projects' commits", :default => false
|
2860
|
+
method_option :commit, :type => :string, :aliases => ["-c", "--commit"], :desc => "download a specific commit", :default => nil
|
2853
2861
|
|
2854
2862
|
def download(sync = false, ignore_list = "", in_exp=false)
|
2855
2863
|
begin
|
@@ -2858,6 +2866,11 @@ module Cnvrg
|
|
2858
2866
|
project_home = get_project_home
|
2859
2867
|
@project = Project.new(project_home)
|
2860
2868
|
@files = Cnvrg::Files.new(@project.owner, @project.slug)
|
2869
|
+
git = options["git"]
|
2870
|
+
commit = options["commit"]
|
2871
|
+
if git or @project.is_git
|
2872
|
+
return download_in_git(commit)
|
2873
|
+
end
|
2861
2874
|
ignore = options[:ignore] || ""
|
2862
2875
|
if ignore.nil? or ignore.empty?
|
2863
2876
|
ignore = ignore_list
|
@@ -3236,7 +3249,7 @@ module Cnvrg
|
|
3236
3249
|
if run_download
|
3237
3250
|
invoke :download, [true, "", in_exp ], :new_branch => options["new_branch"], :verbose => options["verbose"], :sync => true
|
3238
3251
|
end
|
3239
|
-
invoke :upload, [false, true, direct, "",options[
|
3252
|
+
invoke :upload, [false, true, direct, "",in_exp,options[:force], options["output_dir"],job_type, job_slug ], :new_branch => options["new_branch"], :verbose => options["verbose"], :sync => true,
|
3240
3253
|
:ignore => options[:ignore], :force => options[:force], :message => options[:message], :deploy => options["deploy"], :return_id => options["return_id"],
|
3241
3254
|
:files => options["files"], :output_dir => options["output_dir"], :job_slug => job_slug, :job_type => job_type
|
3242
3255
|
|
data/lib/cnvrg/datafiles.rb
CHANGED
@@ -20,12 +20,13 @@ module Cnvrg
|
|
20
20
|
@base_resource = "users/#{owner}/datasets/#{dataset_slug}/"
|
21
21
|
end
|
22
22
|
|
23
|
-
def upload_multiple_files(commit_sha1, tree, threads: ParallelThreads, force: false, new_branch: false)
|
23
|
+
def upload_multiple_files(commit_sha1, tree, threads: ParallelThreads, force: false, new_branch: false, progressbar: nil)
|
24
24
|
random_file_name = (0...8).map { (65 + rand(26)).chr }.join #needed to create a file for post_file..
|
25
25
|
# each file have: {sha1: sha1, file_name: file_name, file_size: file_size, content_type: content_type, absolute_path, relative_path}
|
26
26
|
|
27
|
-
#this call should also implement compare_idx...
|
28
|
-
|
27
|
+
#this call should also implement compare_idx...
|
28
|
+
begin
|
29
|
+
upload_resp = Cnvrg::API.request(@base_resource + "upload_files", 'POST_JSON', {commit_sha1: commit_sha1, tree: tree, force: force, is_branch: new_branch})
|
29
30
|
return Cnvrg::Result.new(false, "Failed to upload files") unless Cnvrg::CLI.is_response_success(upload_resp, false)
|
30
31
|
results = upload_resp['result'].with_indifferent_access
|
31
32
|
props = Cnvrg::Helpers.get_s3_props(results)
|
@@ -34,11 +35,20 @@ module Cnvrg
|
|
34
35
|
upload_options = props[:upload_options]
|
35
36
|
s3_bucket = Aws::S3::Resource.new(client: client).bucket(bucket)
|
36
37
|
files = results['files']
|
38
|
+
progressbar.progress += tree.keys.length - files.length if progressbar.present?
|
37
39
|
Parallel.map((files.keys), {in_threads: threads}) do |k|
|
38
40
|
o = tree[k].merge(files[k])
|
39
41
|
upload_single_file(o, s3_bucket, upload_options)
|
42
|
+
progressbar.progress += 1 if progressbar.present?
|
40
43
|
end
|
44
|
+
blob_ids = files.values.map{|f| f['bv_id']}
|
45
|
+
dirs = tree.keys.select{|k| tree[k].nil? }
|
46
|
+
upload_resp = Cnvrg::API.request(@base_resource + "upload_files_save", "POST", {commit: commit_sha1, blob_ids: blob_ids, dirs: dirs})
|
41
47
|
return files.keys.length
|
48
|
+
rescue => e
|
49
|
+
return Cnvrg::Result.new(false, "Failed to upload files")
|
50
|
+
end
|
51
|
+
|
42
52
|
end
|
43
53
|
|
44
54
|
def upload_single_file(file, s3_bucket, upload_options={})
|
@@ -734,10 +744,10 @@ module Cnvrg
|
|
734
744
|
Cnvrg::CLI.is_response_success(response, true)
|
735
745
|
return response
|
736
746
|
end
|
737
|
-
def start_commit(new_branch,force=false,delete_commit=nil)
|
747
|
+
def start_commit(new_branch,force=false,delete_commit=nil, chunks: 0, current_commit: nil)
|
738
748
|
begin
|
739
749
|
response = Cnvrg::API.request("#{base_resource}/commit/start", 'POST', {dataset_slug: @dataset_slug, new_branch: new_branch,force:force,
|
740
|
-
username: @owner,
|
750
|
+
username: @owner,current_commit:current_commit, total_chunks: chunks})
|
741
751
|
Cnvrg::CLI.is_response_success(response, true)
|
742
752
|
return response
|
743
753
|
rescue => e
|
@@ -746,9 +756,9 @@ module Cnvrg
|
|
746
756
|
|
747
757
|
end
|
748
758
|
|
749
|
-
def end_commit(commit_sha1,force,
|
759
|
+
def end_commit(commit_sha1,force, success: true)
|
750
760
|
begin
|
751
|
-
response = Cnvrg::API.request("#{base_resource}/commit/end", 'POST', {commit_sha1: commit_sha1,force:force, success:
|
761
|
+
response = Cnvrg::API.request("#{base_resource}/commit/end", 'POST', {commit_sha1: commit_sha1,force:force, success: success})
|
752
762
|
Cnvrg::CLI.is_response_success(response, true)
|
753
763
|
return response
|
754
764
|
rescue => e
|
@@ -828,7 +838,7 @@ module Cnvrg
|
|
828
838
|
|
829
839
|
end
|
830
840
|
|
831
|
-
def download_multiple_files_s3(files, project_home, conflict: false)
|
841
|
+
def download_multiple_files_s3(files, project_home, conflict: false, progressbar: nil)
|
832
842
|
begin
|
833
843
|
props = Cnvrg::Helpers.get_s3_props(files)
|
834
844
|
client = props[:client]
|
@@ -841,11 +851,11 @@ module Cnvrg
|
|
841
851
|
isolation: true
|
842
852
|
}
|
843
853
|
Parallel.map(files["keys"], parallel_options) do |f|
|
844
|
-
|
845
854
|
file_path = f["name"]
|
855
|
+
progressbar.progress += 1 if progressbar.present?
|
846
856
|
if file_path.end_with? "/"
|
847
857
|
# dir
|
848
|
-
if download_dir(
|
858
|
+
if download_dir(project_home, file_path)
|
849
859
|
download_succ_count += 1
|
850
860
|
else
|
851
861
|
return Cnvrg::Result.new(false,"Could not create directory: #{file_path}")
|
@@ -857,6 +867,8 @@ module Cnvrg
|
|
857
867
|
file_key = Cnvrg::Helpers.decrypt(key,iv, f["path"])
|
858
868
|
resp = false
|
859
869
|
file_path = "#{file_path}.conflict" if conflict
|
870
|
+
dirname = File.dirname file_path
|
871
|
+
download_dir(project_home, dirname) unless dirname.eql? "."
|
860
872
|
File.open(project_home+"/"+file_path, 'w+') do |file|
|
861
873
|
resp = client.get_object({bucket:bucket,
|
862
874
|
key:file_key}, target: file)
|
data/lib/cnvrg/dataset.rb
CHANGED
@@ -27,6 +27,9 @@ module Cnvrg
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def last_local_commit
|
30
|
+
if !File.exist? "#{self.local_path}/.cnvrg/idx.yml"
|
31
|
+
return nil
|
32
|
+
end
|
30
33
|
idx = YAML.load_file(@local_path + "/.cnvrg/idx.yml")
|
31
34
|
return idx[:commit]
|
32
35
|
end
|
@@ -488,7 +491,6 @@ module Cnvrg
|
|
488
491
|
end
|
489
492
|
idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
|
490
493
|
return idx_hash[:next_commit]
|
491
|
-
|
492
494
|
end
|
493
495
|
def remove_next_commit()
|
494
496
|
if !File.exist? "#{self.local_path}/.cnvrg/idx.yml"
|
@@ -501,6 +503,13 @@ module Cnvrg
|
|
501
503
|
File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { |f| f.write idx.to_yaml }
|
502
504
|
|
503
505
|
|
506
|
+
end
|
507
|
+
def get_current_commit()
|
508
|
+
if !File.exist? "#{self.local_path}/.cnvrg/idx.yml"
|
509
|
+
return nil
|
510
|
+
end
|
511
|
+
idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
|
512
|
+
return idx_hash[:commit]
|
504
513
|
end
|
505
514
|
def list_files(commit, json)
|
506
515
|
response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/list", 'GET', {commit_sha1:commit, as_json:json})
|
data/lib/cnvrg/experiment.rb
CHANGED
data/lib/cnvrg/helpers.rb
CHANGED
@@ -196,6 +196,7 @@ parameters:
|
|
196
196
|
|
197
197
|
def decrypt(key,iv,str)
|
198
198
|
begin
|
199
|
+
|
199
200
|
cipher = OpenSSL::Cipher.new("aes-256-cbc").decrypt
|
200
201
|
cipher.key = key
|
201
202
|
cipher.iv = Base64.decode64 iv.encode('ascii-8bit')
|
@@ -262,7 +263,7 @@ parameters:
|
|
262
263
|
:http_open_timeout => 60, :retry_limit => 20)
|
263
264
|
use_accelerate_endpoint = true
|
264
265
|
else
|
265
|
-
endpoint = Cnvrg::Helpers.decrypt(key,iv, files["
|
266
|
+
endpoint = Cnvrg::Helpers.decrypt(key,iv, files["endpoint"])
|
266
267
|
client = Aws::S3::Client.new(
|
267
268
|
:access_key_id =>access,
|
268
269
|
:secret_access_key => secret,
|
data/lib/cnvrg/project.rb
CHANGED
@@ -317,6 +317,22 @@ module Cnvrg
|
|
317
317
|
config = YAML.load_file(@working_dir+"/.cnvrg/config.yml")
|
318
318
|
new_config = config.except(:new_branch)
|
319
319
|
File.open(@working_dir+"/.cnvrg/config.yml", "w+") { |f| f.write new_config.to_yaml }
|
320
|
+
end
|
321
|
+
def generate_output_dir(output_dir)
|
322
|
+
upload_list = []
|
323
|
+
list = Dir.glob("#{output_dir}/**/*", File::FNM_DOTMATCH)
|
324
|
+
Parallel.map(list, in_threads: IDXParallelThreads) do |e|
|
325
|
+
next if e.end_with? "/."
|
326
|
+
if File.directory? e
|
327
|
+
|
328
|
+
upload_list << e+"/"
|
329
|
+
else
|
330
|
+
upload_list << e
|
331
|
+
end
|
332
|
+
end
|
333
|
+
upload_list << output_dir + "/"
|
334
|
+
return upload_list
|
335
|
+
|
320
336
|
end
|
321
337
|
|
322
338
|
def generate_idx(deploy:false)
|
data/lib/cnvrg/version.rb
CHANGED
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.6.
|
4
|
+
version: 0.6.2
|
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: 2018-08-
|
12
|
+
date: 2018-08-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|