cnvrg 1.11.1 → 1.11.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cnvrg/cli.rb +13 -4
- data/lib/cnvrg/datafiles.rb +1 -1
- data/lib/cnvrg/dataset.rb +24 -9
- data/lib/cnvrg/downloader/client.rb +24 -16
- data/lib/cnvrg/downloader/clients/gcp_client.rb +1 -1
- data/lib/cnvrg/files.rb +4 -4
- data/lib/cnvrg/storage.rb +1 -1
- data/lib/cnvrg/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1402d0759d20d1c1d9182cebc35fe5539c14a8a1bb2c4eeddf791f43ff768082
|
4
|
+
data.tar.gz: 4146973b1a98ea3d26af0efb96ee481093e29fe9fce6fb88c54a539b34e5c0cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53951eb4b7f82322640e75fdeae5ece07bb7189cc5b81257a9a78fd1398ab04c43ef0ed2784c1963f8d53dd983f874f2ed1ccc0ac4953ffced37deb75953d679
|
7
|
+
data.tar.gz: 8a046e229d0d14a2d36cb896c467aff3599e98b0e1cfb93e96fb72e80342751a47df4e1a90a57ff62e09ed92f1720afb783fe354dd34a5e06767e98c5bd8bdb6
|
data/lib/cnvrg/cli.rb
CHANGED
@@ -896,10 +896,12 @@ module Cnvrg
|
|
896
896
|
return
|
897
897
|
end
|
898
898
|
|
899
|
+
|
899
900
|
if only_tree
|
900
|
-
|
901
|
-
return
|
901
|
+
Dataset.clone_tree(commit: commit, dataset_home: dataset_home)
|
902
|
+
return
|
902
903
|
end
|
904
|
+
|
903
905
|
commit = response["result"]["commit"]
|
904
906
|
files_count = response["result"]["file_count"]
|
905
907
|
files = @files.get_clone_chunk(commit: commit)
|
@@ -911,6 +913,7 @@ module Cnvrg
|
|
911
913
|
:total => files_count,
|
912
914
|
:autofinish => true)
|
913
915
|
|
916
|
+
Dataset.clone_tree(commit: commit, dataset_home: dataset_home, progressbar: progressbar)
|
914
917
|
|
915
918
|
while files['keys'].length > 0
|
916
919
|
Cnvrg::Logger.log_info("download multiple files, #{downloaded_files.size} files downloaded")
|
@@ -969,6 +972,7 @@ module Cnvrg
|
|
969
972
|
|
970
973
|
if Dataset.blank_clone(owner, dataset_name, dataset_slug)
|
971
974
|
dataset = Dataset.new(dataset_home)
|
975
|
+
downloader = dataset.get_storage_client
|
972
976
|
log_message("Cloning #{dataset_name}", Thor::Shell::Color::BLUE)
|
973
977
|
parallel_options = {
|
974
978
|
:progress => {
|
@@ -991,15 +995,20 @@ module Cnvrg
|
|
991
995
|
relative_path_dir = relative_path_dir.join("/")
|
992
996
|
abs_path = dataset_home + "/" + relative_path_dir
|
993
997
|
abs_path = dataset_home if flatten
|
998
|
+
fullpath = abs_path + "/" + file_name
|
994
999
|
|
995
1000
|
begin
|
996
|
-
FileUtils.mkdir_p(abs_path) unless File.exist? (
|
1001
|
+
FileUtils.mkdir_p(abs_path) unless File.exist? (fullpath)
|
997
1002
|
rescue
|
998
1003
|
log_message("Could not create directory: #{abs_path}", Thor::Shell::Color::RED)
|
999
1004
|
exit(1)
|
1000
1005
|
end
|
1001
1006
|
begin
|
1002
|
-
|
1007
|
+
unless File.exist?(fullpath)
|
1008
|
+
downloader.safe_operation("#{abs_path}/#{file_name}") do
|
1009
|
+
File.open(fullpath, "w") { |f| f.write open(f["url"]).read }
|
1010
|
+
end
|
1011
|
+
end
|
1003
1012
|
rescue => e
|
1004
1013
|
log_message("Could not download file: #{f["fullpath"]}", Thor::Shell::Color::RED)
|
1005
1014
|
exit(1)
|
data/lib/cnvrg/datafiles.rb
CHANGED
@@ -1338,7 +1338,7 @@ module Cnvrg
|
|
1338
1338
|
# Cnvrg::Logger.log_info("Trying to download #{local_path} but its already exists, skipping..")
|
1339
1339
|
# next
|
1340
1340
|
# end
|
1341
|
-
resp = @downloader.
|
1341
|
+
resp = @downloader.safe_download(storage_path, local_path)
|
1342
1342
|
Cnvrg::Logger.log_info("Download #{local_path} success resp: #{resp}")
|
1343
1343
|
rescue => e
|
1344
1344
|
Cnvrg::Logger.log_error(e)
|
data/lib/cnvrg/dataset.rb
CHANGED
@@ -471,23 +471,38 @@ module Cnvrg
|
|
471
471
|
response.to_json
|
472
472
|
end
|
473
473
|
|
474
|
-
def self.clone_tree(commit: 'latest', dataset_home: nil)
|
474
|
+
def self.clone_tree(commit: 'latest', dataset_home: nil, progressbar: nil)
|
475
475
|
@dataset = Cnvrg::Dataset.new(dataset_home)
|
476
476
|
@files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug, dataset: @dataset)
|
477
477
|
trees = @files.get_trees(commit: commit)
|
478
478
|
return false if trees.nil?
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
479
|
+
|
480
|
+
if progressbar
|
481
|
+
pb = progressbar
|
482
|
+
pb.total += trees.size
|
483
|
+
else
|
484
|
+
pb = ProgressBar.create(
|
485
|
+
:title => "Download Progress",
|
486
|
+
:progress_mark => '=',
|
487
|
+
:format => "%b>>%i| %p%% %t",
|
488
|
+
:starting_at => 0,
|
489
|
+
:total => trees.size,
|
490
|
+
:autofinish => true
|
491
|
+
)
|
492
|
+
end
|
493
|
+
|
485
494
|
trees.each do |tree|
|
486
495
|
pb.progress += 1
|
487
496
|
@files.download_dir(dataset_home, tree)
|
488
497
|
end
|
489
|
-
|
490
|
-
|
498
|
+
|
499
|
+
unless progressbar
|
500
|
+
# if progessbar sent it means that its not only tree so we dont want to finish the progress bar
|
501
|
+
# and we dont want to write success
|
502
|
+
|
503
|
+
pb.finish
|
504
|
+
@dataset.write_success
|
505
|
+
end
|
491
506
|
true
|
492
507
|
end
|
493
508
|
|
@@ -30,10 +30,14 @@ module Cnvrg
|
|
30
30
|
file.gsub(prefix, '').gsub(/^\/*/, '')
|
31
31
|
end
|
32
32
|
|
33
|
-
def download(storage_path, local_path)
|
33
|
+
def download(storage_path, local_path, decrypt: true)
|
34
34
|
### need to be implemented..
|
35
35
|
end
|
36
36
|
|
37
|
+
def safe_download(storage_path, local_path, decrypt: true)
|
38
|
+
safe_operation(local_path) { self.download(storage_path, local_path, decrypt: decrypt) }
|
39
|
+
end
|
40
|
+
|
37
41
|
def upload(storage_path, local_path)
|
38
42
|
### need to be implemented..
|
39
43
|
end
|
@@ -51,17 +55,34 @@ module Cnvrg
|
|
51
55
|
end
|
52
56
|
|
53
57
|
def safe_upload(storage_path, local_path)
|
58
|
+
safe_operation(local_path) { self.upload(storage_path, local_path) }
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.factory(params)
|
62
|
+
params = params.as_json
|
63
|
+
case params["storage"]
|
64
|
+
when 's3', 'minio'
|
65
|
+
return Cnvrg::Downloader::Clients::S3Client.new(sts_path: params["path_sts"], access_key: params["sts_a"], secret: params["sts_s"], session_token: params["sts_st"], region: params["region"], bucket: params["bucket"], encryption: params["encryption"], endpoint: params["endpoint"], storage: params["storage"])
|
66
|
+
when 'azure'
|
67
|
+
azure_params = params.symbolize_keys.slice(*[:storage_account_name, :storage_access_key, :container, :sts])
|
68
|
+
return Cnvrg::Downloader::Clients::AzureClient.new(**azure_params)
|
69
|
+
when 'gcp'
|
70
|
+
return Cnvrg::Downloader::Clients::GcpClient.new(project_id: params["project_id"], credentials: params["credentials"], bucket_name: params["bucket_name"], sts: params["sts"])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def safe_operation(local_path)
|
54
75
|
n = 1
|
55
76
|
error = nil
|
56
77
|
while n <= RETRIES
|
57
78
|
begin
|
58
|
-
|
79
|
+
yield
|
59
80
|
error = nil
|
60
81
|
break
|
61
82
|
rescue => e
|
62
83
|
backoff_time_seconds = backoff_time(n)
|
63
84
|
|
64
|
-
message = "Got error: #{e.class.name} with message: #{e.message} while uploading a single file: #{local_path}, retry: #{n} of: #{RETRIES}"
|
85
|
+
message = "Got error: #{e.class.name} with message: #{e.message} while uploading / downloading a single file: #{local_path}, retry: #{n} of: #{RETRIES}"
|
65
86
|
if n < RETRIES
|
66
87
|
message += ", next retry in: #{backoff_time_seconds} seconds"
|
67
88
|
else
|
@@ -79,19 +100,6 @@ module Cnvrg
|
|
79
100
|
true
|
80
101
|
end
|
81
102
|
|
82
|
-
def self.factory(params)
|
83
|
-
params = params.as_json
|
84
|
-
case params["storage"]
|
85
|
-
when 's3', 'minio'
|
86
|
-
return Cnvrg::Downloader::Clients::S3Client.new(sts_path: params["path_sts"], access_key: params["sts_a"], secret: params["sts_s"], session_token: params["sts_st"], region: params["region"], bucket: params["bucket"], encryption: params["encryption"], endpoint: params["endpoint"], storage: params["storage"])
|
87
|
-
when 'azure'
|
88
|
-
azure_params = params.symbolize_keys.slice(*[:storage_account_name, :storage_access_key, :container, :sts])
|
89
|
-
return Cnvrg::Downloader::Clients::AzureClient.new(**azure_params)
|
90
|
-
when 'gcp'
|
91
|
-
return Cnvrg::Downloader::Clients::GcpClient.new(project_id: params["project_id"], credentials: params["credentials"], bucket_name: params["bucket_name"], sts: params["sts"])
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
103
|
private
|
96
104
|
|
97
105
|
def random_number_milliseconds
|
data/lib/cnvrg/files.rb
CHANGED
@@ -115,7 +115,7 @@ module Cnvrg
|
|
115
115
|
#upload files
|
116
116
|
blob_id_chunk = Parallel.map(files.keys, in_threads: ParallelThreads) do |file|
|
117
117
|
begin
|
118
|
-
|
118
|
+
upload_single_file(files[file].merge(parsed_chunk_of_files[file]))
|
119
119
|
rescue => e
|
120
120
|
Cnvrg::CLI.log_message("Failed to upload #{file}: #{e.message}", 'red') unless suppress_exceptions
|
121
121
|
Cnvrg::Logger.log_error(e)
|
@@ -188,7 +188,7 @@ module Cnvrg
|
|
188
188
|
def upload_single_file(file)
|
189
189
|
path = file['path']
|
190
190
|
absolute_path = file[:absolute_path]
|
191
|
-
@client.
|
191
|
+
@client.safe_upload(path, absolute_path)
|
192
192
|
end
|
193
193
|
|
194
194
|
def parse_file(file)
|
@@ -789,7 +789,7 @@ module Cnvrg
|
|
789
789
|
end
|
790
790
|
local_path = project_home+"/"+file_path
|
791
791
|
storage_path = f["path"]
|
792
|
-
@client.
|
792
|
+
@client.safe_download(storage_path, local_path)
|
793
793
|
progress.progress += 1 if progress.present?
|
794
794
|
download_succ_count += 1
|
795
795
|
rescue => e
|
@@ -962,7 +962,7 @@ module Cnvrg
|
|
962
962
|
|
963
963
|
def download_file(file_path: '', key: '', iv: '', bucket: '', path: '', client: nil)
|
964
964
|
local_path = @project_home+"/"+file_path
|
965
|
-
@client.
|
965
|
+
@client.safe_download(path, local_path)
|
966
966
|
end
|
967
967
|
|
968
968
|
def delete(file)
|
data/lib/cnvrg/storage.rb
CHANGED
@@ -34,7 +34,7 @@ module Cnvrg
|
|
34
34
|
@element.get_clone_chunk(commit: commit, chunk_size: params[:limit], offset: params[:offset])
|
35
35
|
end
|
36
36
|
action = Proc.new do |storage, local|
|
37
|
-
@client.
|
37
|
+
@client.safe_download(storage, local)
|
38
38
|
end
|
39
39
|
|
40
40
|
@stats = @element.get_stats
|
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: 1.11.
|
4
|
+
version: 1.11.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yochay Ettun
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-
|
13
|
+
date: 2020-11-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -453,7 +453,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
453
453
|
- !ruby/object:Gem::Version
|
454
454
|
version: '0'
|
455
455
|
requirements: []
|
456
|
-
rubygems_version: 3.
|
456
|
+
rubygems_version: 3.0.4
|
457
457
|
signing_key:
|
458
458
|
specification_version: 4
|
459
459
|
summary: A CLI tool for interacting with cnvrg.io.
|