cnvrg 0.3.6 → 0.3.8
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/cnvrg.gemspec +1 -0
- data/lib/cnvrg/api.rb +26 -8
- data/lib/cnvrg/auth.rb +5 -0
- data/lib/cnvrg/cli.rb +964 -477
- data/lib/cnvrg/data.rb +42 -8
- data/lib/cnvrg/datafiles.rb +168 -145
- data/lib/cnvrg/dataset.rb +124 -17
- data/lib/cnvrg/experiment.rb +7 -4
- data/lib/cnvrg/files.rb +52 -67
- data/lib/cnvrg/helpers.rb +20 -0
- data/lib/cnvrg/project.rb +0 -6
- data/lib/cnvrg/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14812c074d9b241c639f215c82da967e632a5b4c
|
4
|
+
data.tar.gz: 68845b081b102ec1d06499a09e3e576a00a89e65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce3a5373033f6a01bab5e0eb9d839e3a6a3b7d1b15576a996e1c00e5d6ef091e9ac6ac50a320379aa9f7ac691b16f8caacc3116b5bd79c4f3c464fbf17878c23
|
7
|
+
data.tar.gz: 2d1ece161322402bd3922b52f0e0371577eeade4c650d037c7956d13c04a3ce701647ff45f45c4c5415006b6e0a6c33f12bda2ddbbb9103c0a0802a49b3438d6
|
data/cnvrg.gemspec
CHANGED
data/lib/cnvrg/api.rb
CHANGED
@@ -44,24 +44,33 @@ module Cnvrg
|
|
44
44
|
|
45
45
|
@user, @pass = n[Cnvrg::Helpers.netrc_domain]
|
46
46
|
begin
|
47
|
-
|
47
|
+
if !Helpers.is_verify_ssl
|
48
|
+
|
49
|
+
conn = Faraday.new "#{endpoint_uri}", :ssl => {:verify => false}
|
50
|
+
else
|
51
|
+
conn = Faraday.new "#{endpoint_uri}"
|
52
|
+
end
|
48
53
|
conn.headers['Auth-Token'] = @pass
|
49
54
|
conn.headers['User-Agent'] = "#{Cnvrg::API::USER_AGENT}"
|
50
|
-
|
51
55
|
case method
|
52
|
-
|
53
|
-
response = conn.get "#{
|
54
|
-
|
56
|
+
when 'GET'
|
57
|
+
response = conn.get "#{resource}", data
|
58
|
+
if response.to_hash[:status] == 404
|
59
|
+
return false
|
60
|
+
end
|
55
61
|
if parse_request == true
|
56
62
|
JSON.parse(response.body)
|
57
63
|
else
|
58
64
|
response
|
59
65
|
end
|
60
|
-
|
66
|
+
when 'POST'
|
61
67
|
conn.options.timeout = 420
|
62
68
|
conn.options.open_timeout =420
|
63
|
-
response = conn.post "#{
|
69
|
+
response = conn.post "#{resource}", data
|
64
70
|
|
71
|
+
if response.to_hash[:status] == 404
|
72
|
+
return false
|
73
|
+
end
|
65
74
|
if parse_request == true
|
66
75
|
JSON.parse(response.body)
|
67
76
|
else
|
@@ -72,10 +81,14 @@ module Cnvrg
|
|
72
81
|
fr.headers['Auth-Token'] = @pass
|
73
82
|
fr.headers['User-Agent'] = "#{Cnvrg::API::USER_AGENT}"
|
74
83
|
fr.headers["Content-Type"] = "multipart/form-data"
|
84
|
+
if !Helpers.is_verify_ssl
|
85
|
+
fr.ssl.verify = false
|
86
|
+
end
|
75
87
|
|
76
88
|
|
77
89
|
fr.request :multipart
|
78
90
|
fr.request :url_encoded
|
91
|
+
fr.request :retry, max: 2, interval: 0.05,interval_randomness: 0.5, backoff_factor: 2
|
79
92
|
fr.adapter :net_http
|
80
93
|
end
|
81
94
|
conn.options.timeout = 420
|
@@ -100,6 +113,9 @@ module Cnvrg
|
|
100
113
|
response = conn.post "#{endpoint_uri}/#{resource}", data
|
101
114
|
|
102
115
|
FileUtils.rm_rf(temp_path)
|
116
|
+
if response.to_hash[:status] == 404
|
117
|
+
return false
|
118
|
+
end
|
103
119
|
|
104
120
|
|
105
121
|
if parse_request == true
|
@@ -109,7 +125,9 @@ module Cnvrg
|
|
109
125
|
end
|
110
126
|
when 'DELETE'
|
111
127
|
response = conn.delete "#{endpoint_uri}/#{resource}", data
|
112
|
-
|
128
|
+
if response.to_hash[:status] == 404
|
129
|
+
return false
|
130
|
+
end
|
113
131
|
if parse_request == true
|
114
132
|
JSON.parse(response.body)
|
115
133
|
else
|
data/lib/cnvrg/auth.rb
CHANGED
data/lib/cnvrg/cli.rb
CHANGED
@@ -60,6 +60,7 @@ class Thor
|
|
60
60
|
|
61
61
|
end
|
62
62
|
|
63
|
+
|
63
64
|
# Let Thor::Options parse the options first, so it can remove
|
64
65
|
# declared options from the array. This will leave us with
|
65
66
|
# a list of arguments that weren't declared.
|
@@ -193,12 +194,16 @@ module Cnvrg
|
|
193
194
|
map %w(-v --version) => :version
|
194
195
|
|
195
196
|
desc 'api', 'set api url, e.g cnvrg --api "https://cnvrg.io/api"'
|
197
|
+
method_option :verify_ssl, :type => :boolean, :aliases => ["-s", "--verify_ssl"], :default => true
|
196
198
|
|
197
199
|
def set_api_url(url)
|
200
|
+
log_handler()
|
201
|
+
log_start(__method__, args, options)
|
198
202
|
home_dir = File.expand_path('~')
|
199
203
|
if !url.end_with? "/api"
|
200
204
|
url = url + "/api"
|
201
205
|
end
|
206
|
+
verify_ssl = options["verify_ssl"]
|
202
207
|
begin
|
203
208
|
if !File.directory? home_dir + "/.cnvrg"
|
204
209
|
FileUtils.mkdir_p([home_dir + "/.cnvrg", home_dir + "/.cnvrg/tmp"])
|
@@ -207,42 +212,34 @@ module Cnvrg
|
|
207
212
|
FileUtils.touch [home_dir + "/.cnvrg/config.yml"]
|
208
213
|
end
|
209
214
|
compression_path = "#{File.expand_path('~')}/.cnvrg/tmp"
|
210
|
-
|
211
215
|
begin
|
212
|
-
config = YAML.load_file(home_dir
|
216
|
+
config = YAML.load_file(home_dir+"/.cnvrg/config.yml")
|
213
217
|
if !config
|
214
|
-
config = {owner: "", username: "", version_last_check: get_start_day(), api: url, compression_path: compression_path, }
|
215
|
-
|
218
|
+
config = {owner: "", username: "", version_last_check: get_start_day(), api: url, compression_path: compression_path ,verify_ssl: verify_ssl }
|
216
219
|
end
|
220
|
+
|
221
|
+
|
217
222
|
rescue
|
218
|
-
config = {owner: "", username: "", version_last_check: get_start_day(), api: url, compression_path: compression_path}
|
223
|
+
config = {owner: "", username: "", version_last_check: get_start_day(), api: url, compression_path: compression_path ,verify_ssl: verify_ssl }
|
219
224
|
end
|
220
|
-
owner = config.to_h[:owner]
|
221
225
|
|
222
226
|
say "Setting default api to be: #{url}", Thor::Shell::Color::BLUE
|
223
227
|
if config.empty?
|
224
|
-
config = {owner: "", username: "", version_last_check: get_start_day(), api: url, compression_path: compression_path}
|
228
|
+
config = {owner: "", username: "", version_last_check: get_start_day(), api: url, compression_path: compression_path, verify_ssl: verify_ssl }
|
225
229
|
else
|
226
230
|
if !config.to_h[:compression_path].nil?
|
227
231
|
compression_path = config.to_h[:compression_path]
|
228
232
|
end
|
229
|
-
config = {owner: config.to_h[:owner], username: config.to_h[:username], version_last_check: config.to_h[:version_last_check], api: url, compression_path: compression_path}
|
233
|
+
config = {owner: config.to_h[:owner], username: config.to_h[:username], version_last_check: config.to_h[:version_last_check], api: url, compression_path: compression_path, verify_ssl: verify_ssl}
|
230
234
|
end
|
231
|
-
# res = Cnvrg::API.request("/users/#{owner}/custom_api", 'POST', {custom_api: url})
|
232
|
-
# if Cnvrg::CLI.is_response_success(res, false)
|
233
235
|
|
234
236
|
checks = Helpers.checkmark
|
237
|
+
File.open(home_dir+"/.cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
|
235
238
|
|
236
|
-
|
237
|
-
File.open(home_dir + "/.cnvrg/config.yml", "w+") {|f| f.write config.to_yaml}
|
238
239
|
say "#{checks} Done", Thor::Shell::Color::GREEN
|
239
|
-
# else
|
240
|
-
# say "Couldn't set default api, contact help@cnvrg.io", Thor::Shell::Color::RED
|
241
|
-
# exit(1)
|
242
|
-
#
|
243
|
-
# end
|
244
240
|
|
245
241
|
rescue => e
|
242
|
+
log_error(e)
|
246
243
|
say "Couldn't set default api, contact help@cnvrg.io", Thor::Shell::Color::RED
|
247
244
|
end
|
248
245
|
end
|
@@ -272,6 +269,16 @@ module Cnvrg
|
|
272
269
|
say "Done"
|
273
270
|
rescue
|
274
271
|
say "ERROR", Thor::Shell::Color::RED
|
272
|
+
File.open(home_dir+"/.cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
|
273
|
+
say "#{checks} Done", Thor::Shell::Color::GREEN
|
274
|
+
# else
|
275
|
+
# say "Couldn't set default api, contact help@cnvrg.io", Thor::Shell::Color::RED
|
276
|
+
# exit(1)
|
277
|
+
#
|
278
|
+
# end
|
279
|
+
|
280
|
+
rescue => e
|
281
|
+
say "Couldn't set default api, contact help@cnvrg.io", Thor::Shell::Color::RED
|
275
282
|
end
|
276
283
|
end
|
277
284
|
|
@@ -553,7 +560,7 @@ module Cnvrg
|
|
553
560
|
|
554
561
|
def new(project_name)
|
555
562
|
begin
|
556
|
-
|
563
|
+
verify_logged_in(false)
|
557
564
|
log_start(__method__, args, options)
|
558
565
|
clean = options["clean"]
|
559
566
|
docker_image = options["docker_image"]
|
@@ -568,8 +575,8 @@ module Cnvrg
|
|
568
575
|
exit(1)
|
569
576
|
|
570
577
|
end
|
571
|
-
if Project.create(project_name, clean, with_docker
|
572
|
-
|
578
|
+
if Project.create(project_name, clean, with_docker=docker)
|
579
|
+
path = Dir.pwd + "/" + project_name
|
573
580
|
@project = Project.new(path)
|
574
581
|
@project.generate_idx
|
575
582
|
if docker
|
@@ -635,42 +642,6 @@ module Cnvrg
|
|
635
642
|
end
|
636
643
|
end
|
637
644
|
|
638
|
-
desc 'set_image', 'set_image for a project'
|
639
|
-
|
640
|
-
def set_image(docker_image)
|
641
|
-
verify_logged_in(false)
|
642
|
-
log_start(__method__, args, options)
|
643
|
-
working_dir = is_cnvrg_dir
|
644
|
-
local_images = Docker::Image.all
|
645
|
-
docker_image_local = local_images.map {|x| x.info["RepoTags"]}.flatten.select {|y| y.include? docker_image}.flatten
|
646
|
-
if docker_image_local.size == 0
|
647
|
-
|
648
|
-
if yes? "Image wasn't found locally, pull image from cnvrg repository?", Thor::Shell::Color::YELLOW
|
649
|
-
image = pull(docker_image)
|
650
|
-
if image
|
651
|
-
say "downloaded image: #{docker_image}"
|
652
|
-
@image = Images.new(working_dir, docker_image)
|
653
|
-
else
|
654
|
-
say "Could not set image, image was not found", Thor::Shell::Color::RED
|
655
|
-
exit(1)
|
656
|
-
end
|
657
|
-
else
|
658
|
-
say "Could nset image, image was not found", Thor::Shell::Color::RED
|
659
|
-
exit(1)
|
660
|
-
|
661
|
-
end
|
662
|
-
elsif docker_image_local.size == 1
|
663
|
-
say "found image: #{docker_image_local[0]}, setting it up..", Thor::Shell::Color::BLUE
|
664
|
-
@image = Images.new(working_dir, docker_image_local[0])
|
665
|
-
elsif docker_image_local.size > 1
|
666
|
-
say "found #{docker_image_local.size} images, choose the image name you want to use", Thor::Shell::Color::BLUE
|
667
|
-
image_name = ask "#{docker_image_local.join("\n")}\n", Thor::Shell::Color::BLUE
|
668
|
-
image_name = image_name.strip
|
669
|
-
@image = Images.new(working_dir, image_name)
|
670
|
-
end
|
671
|
-
@image.update_image_activity(nil, nil)
|
672
|
-
|
673
|
-
end
|
674
645
|
|
675
646
|
desc 'link', 'Link current directory to a new cnvrg project'
|
676
647
|
method_option :sync, :type => :boolean, :aliases => ["-s"], :default => false
|
@@ -793,24 +764,51 @@ module Cnvrg
|
|
793
764
|
exit(1)
|
794
765
|
end
|
795
766
|
end
|
767
|
+
desc 'data delete', 'delete dataset'
|
768
|
+
def delete_data(dataset_slug)
|
769
|
+
begin
|
770
|
+
verify_logged_in(false)
|
771
|
+
log_start(__method__, args, options)
|
772
|
+
owner = CLI.get_owner
|
773
|
+
response = Dataset.delete(dataset_slug, owner)
|
796
774
|
|
797
|
-
|
798
|
-
|
799
|
-
|
775
|
+
if Cnvrg::CLI.is_response_success(response)
|
776
|
+
log_message("Successfully deleted dataset: #{dataset_slug}", Thor::Shell::Color::GREEN)
|
777
|
+
else
|
778
|
+
log_message("Error while tying to delete dataset: #{response["messages"]}", Thor::Shell::Color::RED)
|
800
779
|
|
801
780
|
|
802
|
-
|
781
|
+
end
|
782
|
+
|
783
|
+
rescue => e
|
784
|
+
log_error(e)
|
785
|
+
rescue SignalException
|
786
|
+
|
787
|
+
say "\nAborting"
|
788
|
+
exit(1)
|
789
|
+
end
|
790
|
+
end
|
791
|
+
|
792
|
+
desc 'data clone', 'Clone dataset'
|
793
|
+
method_option :commit, :type => :string, :aliases => ["-c", "--commit"], :default => ""
|
794
|
+
method_option :only_tree, :type => :boolean, :aliases => ["-t", "--tree"], :default => false
|
795
|
+
def clone_data(dataset_url,only_tree=false,commit=nil)
|
803
796
|
begin
|
804
797
|
verify_logged_in(false)
|
805
798
|
log_start(__method__, args, options)
|
799
|
+
commit = options["commit"] || commit
|
800
|
+
only_tree = options["only_tree"] || only_tree
|
801
|
+
|
802
|
+
|
806
803
|
url_parts = dataset_url.split("/")
|
807
804
|
project_index = Cnvrg::Helpers.look_for_in_path(dataset_url, "datasets")
|
808
805
|
slug = url_parts[project_index + 1]
|
809
806
|
owner = url_parts[project_index - 1]
|
810
|
-
response = Cnvrg::API.request("users/#{owner}/datasets/#{slug}/clone", '
|
811
|
-
|
812
|
-
Cnvrg::CLI.is_response_success(response)
|
807
|
+
response = Cnvrg::API.request("users/#{owner}/datasets/#{slug}/clone", 'POST',{ commit: commit})
|
808
|
+
Cnvrg::CLI.is_response_success(response,true)
|
813
809
|
dataset_name = response["result"]["name"]
|
810
|
+
dataset_home = Dir.pwd+"/"+dataset_name
|
811
|
+
|
814
812
|
|
815
813
|
if (Dir.exists? dataset_name)
|
816
814
|
log_message("Error: Conflict with dir #{dataset_name}", Thor::Shell::Color::RED)
|
@@ -822,35 +820,88 @@ module Cnvrg
|
|
822
820
|
end
|
823
821
|
if Dataset.clone(owner, dataset_name, slug)
|
824
822
|
log_message("Cloning #{dataset_name}", Thor::Shell::Color::BLUE)
|
823
|
+
@files = Cnvrg::Datafiles.new(owner, slug)
|
825
824
|
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
825
|
+
successful_changes = []
|
826
|
+
log_message("Downloading files", Thor::Shell::Color::BLUE)
|
827
|
+
commit = response["result"]["commit"]
|
828
|
+
idx = {commit: response["result"]["commit"], tree: response["result"]["tree"]}
|
829
|
+
File.open(dataset_home + "/.cnvrg/idx.yml", "w+") {|f| f.write idx.to_yaml}
|
830
|
+
if !response["result"]["tree"].nil?
|
831
|
+
parallel_options = {
|
832
|
+
:progress => {
|
833
|
+
:title => "Download Progress",
|
834
|
+
:progress_mark => '=',
|
835
|
+
:format => "%b>>%i| %p%% %t",
|
836
|
+
:starting_at => 0,
|
837
|
+
:total => response["result"]["tree"].size,
|
838
|
+
:autofinish => true
|
839
|
+
},
|
840
|
+
in_threads: ParallelThreads
|
841
|
+
}
|
842
|
+
begin
|
843
|
+
is_success = true
|
830
844
|
|
845
|
+
Parallel.map((response["result"]["tree"]), parallel_options) do |f|
|
831
846
|
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
847
|
+
relative_path = f[0].gsub(/^#{dataset_home}/, "")
|
848
|
+
if f[0].end_with? "/"
|
849
|
+
# dir
|
850
|
+
if @files.download_dir(dataset_home, relative_path)
|
851
|
+
successful_changes << relative_path
|
852
|
+
else
|
853
|
+
is_success =false
|
854
|
+
log_message("Could not create directory: #{f[0]}", Thor::Shell::Color::RED)
|
855
|
+
raise Parallel::Kill
|
856
|
+
end
|
857
|
+
else
|
858
|
+
# blob
|
859
|
+
if !only_tree
|
860
|
+
|
861
|
+
if @files.download_file_s3(f[0], relative_path, dataset_home, false, commit_sha1=commit)
|
862
|
+
successful_changes << relative_path
|
863
|
+
else
|
864
|
+
is_success =false
|
865
|
+
log_message("Could not download file: #{f[0]}", Thor::Shell::Color::RED)
|
866
|
+
raise Parallel::Kill
|
867
|
+
end
|
868
|
+
end
|
869
|
+
end
|
870
|
+
end
|
871
|
+
rescue Interrupt
|
872
|
+
is_success =false
|
873
|
+
log_message("Couldn't download", Thor::Shell::Color::RED)
|
874
|
+
|
875
|
+
exit(1)
|
876
|
+
end
|
837
877
|
|
838
878
|
|
879
|
+
end
|
839
880
|
check = Helpers.checkmark
|
840
|
-
|
881
|
+
|
882
|
+
successful_changes = response["result"]["tree"]
|
883
|
+
if !successful_changes.nil? and is_success
|
884
|
+
Dataset.verify_cnvrgignore_exist(dataset_name, false)
|
885
|
+
|
886
|
+
log_message("#{check} Clone finished successfully", Thor::Shell::Color::GREEN)
|
887
|
+
else
|
888
|
+
log_message("Couldn't download some files", Thor::Shell::Color::RED)
|
889
|
+
|
890
|
+
end
|
841
891
|
|
842
892
|
else
|
843
|
-
|
844
|
-
log_message("Error
|
845
|
-
exit(
|
893
|
+
|
894
|
+
log_message("Error: Couldn't create directory: #{dataset_name}", Thor::Shell::Color::RED)
|
895
|
+
exit(1)
|
846
896
|
end
|
847
|
-
rescue => e
|
848
|
-
log_error(e)
|
849
897
|
rescue SignalException
|
850
|
-
|
851
898
|
say "\nAborting"
|
852
899
|
exit(1)
|
853
900
|
end
|
901
|
+
|
902
|
+
|
903
|
+
|
904
|
+
|
854
905
|
end
|
855
906
|
|
856
907
|
desc 'init_data_container', 'Init dataset directory', :hide => true
|
@@ -1029,6 +1080,8 @@ module Cnvrg
|
|
1029
1080
|
end
|
1030
1081
|
|
1031
1082
|
|
1083
|
+
|
1084
|
+
|
1032
1085
|
desc 'upload_data', 'Upload data files', :hide => true
|
1033
1086
|
method_option :ignore, :type => :array, :aliases => ["-i", "--i"], :desc => "ignore following files"
|
1034
1087
|
method_option :new_branch, :type => :boolean, :aliases => ["-nb", "--nb"], :desc => "create new branch of commits"
|
@@ -1152,7 +1205,7 @@ module Cnvrg
|
|
1152
1205
|
update_count += result["deleted"].size
|
1153
1206
|
end
|
1154
1207
|
if update_count == update_total
|
1155
|
-
res = @files.end_commit(commit_sha1)
|
1208
|
+
res = @files.end_commit(commit_sha1,false)
|
1156
1209
|
if (Cnvrg::CLI.is_response_success(res, false))
|
1157
1210
|
# save idx
|
1158
1211
|
begin
|
@@ -1280,9 +1333,8 @@ module Cnvrg
|
|
1280
1333
|
relative_path = f.gsub(/^#{@dataset.local_path + "/"}/, "")
|
1281
1334
|
successful_updates << relative_path
|
1282
1335
|
end
|
1283
|
-
@dataset.update_idx_with_files_commits!((successful_deletions
|
1336
|
+
@dataset.update_idx_with_files_commits!((successful_deletions+successful_updates), commit_time)
|
1284
1337
|
|
1285
|
-
@dataset.update_idx_with_commit!(commit_sha1)
|
1286
1338
|
log_message("Compressing data", Thor::Shell::Color::BLUE)
|
1287
1339
|
|
1288
1340
|
home_dir = File.expand_path('~')
|
@@ -1366,10 +1418,10 @@ module Cnvrg
|
|
1366
1418
|
exit(0)
|
1367
1419
|
rescue => e
|
1368
1420
|
log_error(e)
|
1369
|
-
if !Cnvrg::Helpers.internet_connection?
|
1370
|
-
|
1371
|
-
|
1372
|
-
end
|
1421
|
+
# if !Cnvrg::Helpers.internet_connection?
|
1422
|
+
# say "Seems there is no internet connection", Thor::Shell::Color::RED
|
1423
|
+
#
|
1424
|
+
# end
|
1373
1425
|
if File.exist? log_file
|
1374
1426
|
@files.upload_data_log_file(log_file, log_file, commit_sha1)
|
1375
1427
|
end
|
@@ -1428,12 +1480,16 @@ module Cnvrg
|
|
1428
1480
|
if owner.nil? or owner.empty?
|
1429
1481
|
owner = CLI.get_owner()
|
1430
1482
|
end
|
1483
|
+
|
1431
1484
|
result = @dataset.list(owner)
|
1432
|
-
|
1485
|
+
Cnvrg::CLI.is_response_success(result)
|
1433
1486
|
|
1434
|
-
|
1487
|
+
list = result["result"]["list"]
|
1435
1488
|
|
1436
|
-
|
1489
|
+
print_table(list)
|
1490
|
+
|
1491
|
+
|
1492
|
+
end
|
1437
1493
|
|
1438
1494
|
desc 'data commits', 'List all commits for a specific dataset'
|
1439
1495
|
|
@@ -1640,7 +1696,7 @@ module Cnvrg
|
|
1640
1696
|
new_branch = options["new_branch"] || false
|
1641
1697
|
force = options["force"] || false
|
1642
1698
|
|
1643
|
-
result = @project.compare_idx(new_branch,
|
1699
|
+
result = @project.compare_idx(new_branch,force:force)["result"]
|
1644
1700
|
commit = result["commit"]
|
1645
1701
|
result = result["tree"]
|
1646
1702
|
log_message("Comparing local changes with remote version:", Thor::Shell::Color::BLUE)
|
@@ -1710,112 +1766,487 @@ module Cnvrg
|
|
1710
1766
|
exit(1)
|
1711
1767
|
end
|
1712
1768
|
end
|
1769
|
+
desc 'sync_data_new', 'sync_data_new'
|
1770
|
+
method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
|
1771
|
+
method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
|
1772
|
+
method_option :force, :type => :boolean, :aliases => ["-f","--force"], :default => false
|
1773
|
+
method_option :commit, :type => :string, :aliases => ["-c"], :desc => "download specified commit", :default => nil
|
1774
|
+
method_option :all_files, :type => :boolean, :aliases => ["--all"], :desc => "download specified commit", :default => true
|
1713
1775
|
|
1776
|
+
def sync_data_new(new_branch, force, verbose, commit, all_files)
|
1777
|
+
verify_logged_in(true)
|
1778
|
+
log_start(__method__, args, options)
|
1779
|
+
log_message('Syncing dataset', Thor::Shell::Color::BLUE, !options["verbose"])
|
1780
|
+
if !options[:force]
|
1781
|
+
invoke :download_data_new,[verbose,true, commit, all_files], :new_branch=>new_branch, :direct=>false, :force =>force
|
1782
|
+
end
|
1783
|
+
invoke :upload_data_new,[new_branch, verbose,true,force], :new_branch=>new_branch, :direct=>false, :force =>force, :sync =>true
|
1714
1784
|
|
1715
|
-
|
1716
|
-
|
1717
|
-
method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
|
1785
|
+
end
|
1786
|
+
desc 'upload_data_new', 'upload_data_new'
|
1718
1787
|
method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
|
1719
|
-
method_option :
|
1720
|
-
method_option :force, :type => :boolean, :aliases => ["-f",
|
1721
|
-
method_option :
|
1722
|
-
|
1788
|
+
method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
|
1789
|
+
method_option :force, :type => :boolean, :aliases => ["-f","--force"], :default => false
|
1790
|
+
method_option :sync, :type => :boolean, :aliases => ["-s","--sync"], :default => false
|
1791
|
+
def upload_data_new(new_branch, verbose,sync,force)
|
1792
|
+
commit = invoke :start_commit_data,[], :new_branch=>new_branch, :direct=>false, :force =>force
|
1793
|
+
|
1794
|
+
upload_res = invoke :upload_data_files,[commit],:new_branch=>new_branch, :verbose =>verbose, :force =>force, :sync =>sync
|
1795
|
+
if upload_res
|
1796
|
+
invoke :end_commit_data,[commit] , :new_branch=>new_branch, :force =>force
|
1797
|
+
end
|
1723
1798
|
|
1724
|
-
|
1799
|
+
end
|
1800
|
+
|
1801
|
+
desc 'start_commit', 'start data commit'
|
1802
|
+
method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
|
1803
|
+
method_option :direct, :type => :boolean, :aliases => ["-d","--direct"], :desc => "was called directed", :default => true
|
1804
|
+
method_option :force, :type => :boolean, :aliases => ["-f","--force"], :default => false
|
1725
1805
|
|
1806
|
+
def start_commit_data()
|
1726
1807
|
begin
|
1727
1808
|
verify_logged_in(true)
|
1728
1809
|
log_start(__method__, args, options)
|
1810
|
+
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
1811
|
+
direct = options[:direct]
|
1812
|
+
new_branch = options["new_branch"] || false
|
1813
|
+
force = options["force"] || false
|
1814
|
+
commit_sha1 = nil
|
1815
|
+
@dataset = Dataset.new(dataset_dir)
|
1816
|
+
@files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug)
|
1817
|
+
next_commit = @dataset.get_next_commit()
|
1818
|
+
if !next_commit.nil? and !next_commit.empty?
|
1819
|
+
resp = @files.get_commit(next_commit)
|
1820
|
+
if resp["result"]["status"].eql? "new"
|
1821
|
+
resp = @files.start_commit(new_branch,force)
|
1822
|
+
commit_sha1 = resp["result"]["commit_sha1"]
|
1729
1823
|
|
1730
|
-
|
1731
|
-
commit_msg = options["message"]
|
1732
|
-
if commit_msg.nil? or commit_msg.empty?
|
1733
|
-
commit_msg = ""
|
1734
|
-
end
|
1735
|
-
|
1736
|
-
@files = Cnvrg::Files.new(@project.owner, @project.slug)
|
1737
|
-
ignore = options[:ignore] || ""
|
1738
|
-
force = options[:force] || false
|
1824
|
+
@dataset.set_next_commit(commit_sha1)
|
1739
1825
|
|
1740
|
-
if ignore.nil? or ignore.empty?
|
1741
|
-
ignore = ignore_list
|
1742
|
-
end
|
1743
|
-
data_ignore = data_dir_include()
|
1744
|
-
if !data_ignore.nil?
|
1745
|
-
if ignore.nil? or ignore.empty?
|
1746
|
-
ignore = data_ignore
|
1747
1826
|
else
|
1748
|
-
ignore = "#{ignore},#{data_ignore}"
|
1749
|
-
end
|
1750
|
-
end
|
1751
|
-
if !@project.update_ignore_list(ignore)
|
1752
|
-
log_message("Couldn't append new ignore files to .cnvrgignore", Thor::Shell::Color::YELLOW)
|
1753
|
-
end
|
1754
|
-
new_branch = options["new_branch"] || false
|
1755
|
-
|
1756
|
-
if options["sync"] or sync
|
1757
|
-
new_branch_exp = @project.get_new_branch
|
1758
|
-
if new_branch_exp
|
1759
|
-
new_branch = new_branch_exp
|
1760
|
-
end
|
1761
|
-
end
|
1762
1827
|
|
1763
|
-
|
1764
|
-
commit = result["result"]["commit"]
|
1765
|
-
if !link
|
1766
|
-
if ((commit != @project.last_local_commit and !@project.last_local_commit.nil? and !result["result"]["tree"]["updated_on_server"].empty?) and !force)
|
1828
|
+
commit_sha1 = resp["result"]["commit_sha1"]
|
1767
1829
|
|
1768
|
-
log_message("Remote server has an updated version, please run `cnvrg download` first, or alternatively: `cnvrg sync`", Thor::Shell::Color::BLUE)
|
1769
|
-
exit(1)
|
1770
1830
|
end
|
1831
|
+
else
|
1771
1832
|
|
1772
|
-
|
1833
|
+
resp = @files.start_commit(new_branch,force)
|
1834
|
+
commit_sha1 = resp["result"]["commit_sha1"]
|
1835
|
+
|
1836
|
+
@dataset.set_next_commit(commit_sha1)
|
1773
1837
|
end
|
1774
|
-
|
1775
|
-
|
1776
|
-
# all = result["added"].select {|x| x.include? ".conflict"} +result["conflicts"].flatten
|
1777
|
-
# if all.size == 1
|
1778
|
-
# num = "conflict"
|
1779
|
-
# else
|
1780
|
-
# num = "conflicts"
|
1781
|
-
# end
|
1782
|
-
# say "Project contains #{all.size} #{num}:", Thor::Shell::Color::RED
|
1783
|
-
# say "#{all.join("\n")}"
|
1784
|
-
# say "Please fix #{num}, and retry", Thor::Shell::Color::RED
|
1785
|
-
# exit(1)
|
1786
|
-
#
|
1787
|
-
# end
|
1788
|
-
check = Helpers.checkmark()
|
1789
|
-
if result["added"].empty? and result["updated_on_local"].empty? and result["deleted"].empty?
|
1790
|
-
log_message("#{check} Project is up to date", Thor::Shell::Color::GREEN, (((options["sync"] or sync) and !direct) ? false : true))
|
1791
|
-
return true
|
1838
|
+
if direct
|
1839
|
+
puts commit_sha1
|
1792
1840
|
end
|
1793
|
-
|
1794
|
-
|
1795
|
-
|
1796
|
-
|
1797
|
-
|
1798
|
-
if update_total == 1
|
1799
|
-
log_message("Updating #{update_total} file", Thor::Shell::Color::BLUE)
|
1800
|
-
else
|
1801
|
-
log_message("Updating #{update_total} files", Thor::Shell::Color::BLUE)
|
1841
|
+
return commit_sha1
|
1842
|
+
rescue => e
|
1843
|
+
puts e
|
1844
|
+
if !commit_sha1.nil?
|
1845
|
+
@dataset.set_next_commit(commit_sha1)
|
1802
1846
|
end
|
1803
|
-
|
1804
|
-
|
1847
|
+
rescue SignalException
|
1848
|
+
log_message("Aborting..", Thor::Shell::Color::YELLOW)
|
1849
|
+
if !commit_sha1.nil?
|
1805
1850
|
|
1851
|
+
@dataset.set_next_commit(commit_sha1)
|
1806
1852
|
end
|
1807
|
-
# Start commit
|
1808
|
-
commit_sha1 = @files.start_commit(new_branch, force: force)["result"]["commit_sha1"]
|
1809
1853
|
|
1810
|
-
|
1811
|
-
|
1854
|
+
exit(1)
|
1855
|
+
end
|
1812
1856
|
|
1813
|
-
|
1814
|
-
|
1815
|
-
|
1816
|
-
|
1817
|
-
|
1818
|
-
|
1857
|
+
end
|
1858
|
+
desc 'end_commit', 'start data commit'
|
1859
|
+
method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
|
1860
|
+
method_option :force, :type => :boolean, :aliases => ["-f","--force"], :default => false
|
1861
|
+
|
1862
|
+
def end_commit_data(commit)
|
1863
|
+
begin
|
1864
|
+
verify_logged_in(true)
|
1865
|
+
log_start(__method__, args, options)
|
1866
|
+
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
1867
|
+
@dataset = Dataset.new(dataset_dir)
|
1868
|
+
@files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug)
|
1869
|
+
force = options["force"] || false
|
1870
|
+
|
1871
|
+
resp = @files.end_commit(commit, force)
|
1872
|
+
if (resp and resp["result"])
|
1873
|
+
check = Helpers.checkmark()
|
1874
|
+
@dataset.remove_next_commit()
|
1875
|
+
log_message("#{check} Data files were updated successfully", Thor::Shell::Color::GREEN)
|
1876
|
+
end
|
1877
|
+
|
1878
|
+
|
1879
|
+
rescue => e
|
1880
|
+
puts e
|
1881
|
+
rescue SignalException
|
1882
|
+
@dataset.set_next_commit(commit)
|
1883
|
+
log_message("Aborting", Thor::Shell::Color::YELLOW)
|
1884
|
+
exit(1)
|
1885
|
+
end
|
1886
|
+
|
1887
|
+
end
|
1888
|
+
desc 'list_files', 'list files in dataset'
|
1889
|
+
method_option :json, :type => :boolean, :aliases => ["-j","--json"],:default => true, :desc => "response as json"
|
1890
|
+
method_option :commit, :type => :string, :aliases => ["-c","--commit"], :default => nil
|
1891
|
+
|
1892
|
+
def list_files_dataset()
|
1893
|
+
begin
|
1894
|
+
verify_logged_in(true)
|
1895
|
+
log_start(__method__, args, options)
|
1896
|
+
commit = options[:commit]
|
1897
|
+
as_json = options[:json]
|
1898
|
+
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
1899
|
+
@dataset = Dataset.new(dataset_dir)
|
1900
|
+
|
1901
|
+
resp = @dataset.list_files(commit, as_json)
|
1902
|
+
if (resp and resp["result"])
|
1903
|
+
if as_json
|
1904
|
+
puts resp["result"]
|
1905
|
+
else
|
1906
|
+
print_table(resp["result"])
|
1907
|
+
|
1908
|
+
end
|
1909
|
+
|
1910
|
+
end
|
1911
|
+
|
1912
|
+
|
1913
|
+
rescue => e
|
1914
|
+
puts e
|
1915
|
+
rescue SignalException
|
1916
|
+
@dataset.set_next_commit(commit)
|
1917
|
+
log_message("Aborting", Thor::Shell::Color::YELLOW)
|
1918
|
+
exit(1)
|
1919
|
+
end
|
1920
|
+
|
1921
|
+
end
|
1922
|
+
desc 'upload_data', 'Upload updated files'
|
1923
|
+
method_option :ignore, :type => :string, :aliases => ["-i"], :desc => "ignore following files", :default => ""
|
1924
|
+
method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
|
1925
|
+
method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
|
1926
|
+
method_option :sync, :type => :boolean, :aliases => ["-s"], :default => false
|
1927
|
+
method_option :force, :type => :boolean, :aliases => ["-f","--force"], :default => false
|
1928
|
+
|
1929
|
+
def upload_data_files(new_commit, *files)
|
1930
|
+
|
1931
|
+
begin
|
1932
|
+
verify_logged_in(true)
|
1933
|
+
log_start(__method__, args, options)
|
1934
|
+
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
1935
|
+
|
1936
|
+
@dataset = Dataset.new(dataset_dir)
|
1937
|
+
@files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug)
|
1938
|
+
next_commit = @dataset.get_next_commit()
|
1939
|
+
|
1940
|
+
|
1941
|
+
if (new_commit.nil? or new_commit.empty?) and next_commit.nil?
|
1942
|
+
log_message("You must specify commit, run start_commit to create new commit", Thor::Shell::Color::RED)
|
1943
|
+
exit(1)
|
1944
|
+
end
|
1945
|
+
|
1946
|
+
force = options[:force] || false
|
1947
|
+
|
1948
|
+
new_branch = options["new_branch"] || false
|
1949
|
+
log_message("Checking dataset", Thor::Shell::Color::BLUE) unless options[:sync]
|
1950
|
+
local_idx = @dataset.generate_idx
|
1951
|
+
result = @dataset.compare_idx(new_branch, commit=@dataset.last_local_commit, local_idx= local_idx, force=force, next_commit= next_commit)
|
1952
|
+
|
1953
|
+
commit_sha1 = result["result"]["commit"]
|
1954
|
+
if commit_sha1 != @dataset.last_local_commit and !@dataset.last_local_commit.nil? and !result["result"]["tree"]["updated_on_server"].empty?
|
1955
|
+
@dataset.remove_next_commit()
|
1956
|
+
@files.delete_commit(next_commit)
|
1957
|
+
log_message("Remote server has an updated version, please run `cnvrg data download` first or cnvrg data upload --new_branch", Thor::Shell::Color::BLUE)
|
1958
|
+
exit(1)
|
1959
|
+
end
|
1960
|
+
check = Helpers.checkmark()
|
1961
|
+
|
1962
|
+
|
1963
|
+
commit_time = result["result"]["commit_time"]
|
1964
|
+
already_uploaded = result["result"]["uploaded"]
|
1965
|
+
dirs_uploaded = []
|
1966
|
+
files_uploaded = []
|
1967
|
+
files_uploaded_names = []
|
1968
|
+
if !already_uploaded.nil? and !already_uploaded.empty?
|
1969
|
+
|
1970
|
+
dirs_uploaded = already_uploaded["dirs"]
|
1971
|
+
files_uploaded = already_uploaded["blobs"]
|
1972
|
+
if !files_uploaded.nil? and !files_uploaded.empty?
|
1973
|
+
files_uploaded_names = already_uploaded["blobs"].keys
|
1974
|
+
end
|
1975
|
+
|
1976
|
+
end
|
1977
|
+
|
1978
|
+
result = result["result"]["tree"]
|
1979
|
+
if result["added"].empty? and result["updated_on_local"].empty? and result["deleted"].empty?
|
1980
|
+
@files.delete_commit(next_commit)
|
1981
|
+
|
1982
|
+
log_message("#{check} Dataset is up to date", Thor::Shell::Color::GREEN, true)
|
1983
|
+
return false
|
1984
|
+
end
|
1985
|
+
log_message("Creating new commit for dataset: #{@dataset.slug}", Thor::Shell::Color::BLUE) unless options[:sync]
|
1986
|
+
|
1987
|
+
|
1988
|
+
# upload / update
|
1989
|
+
begin
|
1990
|
+
|
1991
|
+
parallel_options = {
|
1992
|
+
:progress => {
|
1993
|
+
:title => "Upload Progress",
|
1994
|
+
:progress_mark => '=',
|
1995
|
+
:format => "%b>>%i| %p%% %t",
|
1996
|
+
:starting_at => 0,
|
1997
|
+
:total => (result["added"] + result["updated_on_local"]).size,
|
1998
|
+
:autofinish => true
|
1999
|
+
},
|
2000
|
+
in_threads: ParallelThreads,
|
2001
|
+
isolation: true
|
2002
|
+
}
|
2003
|
+
successful_updates = []
|
2004
|
+
update_count =0
|
2005
|
+
update_total = (result["added"] + result["updated_on_local"] + result["deleted"]).size
|
2006
|
+
|
2007
|
+
if (result["added"] + result["updated_on_local"]).size > 0
|
2008
|
+
begin
|
2009
|
+
upload_result = Parallel.map((result["added"] + result["updated_on_local"]), parallel_options) do |f|
|
2010
|
+
absolute_path = "#{@dataset.local_path}/#{f}"
|
2011
|
+
relative_path = f.gsub(/^#{@dataset.local_path + "/"}/, "")
|
2012
|
+
if File.directory?(absolute_path)
|
2013
|
+
if dirs_uploaded.include? f
|
2014
|
+
#Already uploaded and didn't finish commit
|
2015
|
+
log_message("Already uploaded dir: #{f}", Thor::Shell::Color::BLUE, options["verbose"])
|
2016
|
+
|
2017
|
+
next
|
2018
|
+
end
|
2019
|
+
log_message("uploading dir: #{f}", Thor::Shell::Color::BLUE, options["verbose"])
|
2020
|
+
|
2021
|
+
resDir = @files.create_dir(absolute_path, relative_path, commit_sha1)
|
2022
|
+
if resDir
|
2023
|
+
update_count += 1
|
2024
|
+
successful_updates<< relative_path
|
2025
|
+
else
|
2026
|
+
log_message("Failed to upload directory: #{ relative_path }", Thor::Shell::Color::RED)
|
2027
|
+
|
2028
|
+
raise Parallel::Kill
|
2029
|
+
end
|
2030
|
+
|
2031
|
+
else
|
2032
|
+
if files_uploaded_names.include? f
|
2033
|
+
log_message("Already uploaded file: #{f}", Thor::Shell::Color::BLUE, options["verbose"])
|
2034
|
+
|
2035
|
+
next
|
2036
|
+
end
|
2037
|
+
log_message("uploading: #{f}", Thor::Shell::Color::BLUE, options["verbose"])
|
2038
|
+
|
2039
|
+
res = @files.upload_file(absolute_path, relative_path, commit_sha1)
|
2040
|
+
if res
|
2041
|
+
update_count += 1
|
2042
|
+
|
2043
|
+
successful_updates<< relative_path
|
2044
|
+
else
|
2045
|
+
log_message("Failed to upload: #{ File.basename(absolute_path) }", Thor::Shell::Color::RED)
|
2046
|
+
|
2047
|
+
raise Parallel::Kill
|
2048
|
+
|
2049
|
+
end
|
2050
|
+
end
|
2051
|
+
end
|
2052
|
+
rescue SignalException
|
2053
|
+
log_message("Exception while trying to upload, look at the log for more details", Thor::Shell::Color::RED)
|
2054
|
+
|
2055
|
+
|
2056
|
+
exit(1)
|
2057
|
+
end
|
2058
|
+
end
|
2059
|
+
|
2060
|
+
end
|
2061
|
+
successful_updates = upload_result.to_a + dirs_uploaded + files_uploaded_names
|
2062
|
+
successful_deletions =[]
|
2063
|
+
|
2064
|
+
|
2065
|
+
# delete
|
2066
|
+
|
2067
|
+
deleted = update_deleted(result["deleted"])
|
2068
|
+
begin
|
2069
|
+
|
2070
|
+
deleted_result = Parallel.map(deleted, in_threads: ParallelThreads) do |f|
|
2071
|
+
|
2072
|
+
relative_path = f.gsub(/^#{@dataset.local_path + "/"}/, "")
|
2073
|
+
if relative_path.end_with?("/")
|
2074
|
+
log_message("deleting dir: #{f}", Thor::Shell::Color::RED, options["verbose"])
|
2075
|
+
|
2076
|
+
if @files.delete_dir(f, relative_path, commit_sha1)
|
2077
|
+
successful_deletions << f
|
2078
|
+
else
|
2079
|
+
log_message("Failed to delete directory: #{ f }", Thor::Shell::Color::RED)
|
2080
|
+
raise Parallel::Kill
|
2081
|
+
|
2082
|
+
end
|
2083
|
+
else
|
2084
|
+
log_message("deleteing file: #{f}", Thor::Shell::Color::RED, options["verbose"])
|
2085
|
+
|
2086
|
+
if @files.delete_file(f, relative_path, commit_sha1)
|
2087
|
+
successful_deletions << f
|
2088
|
+
|
2089
|
+
else
|
2090
|
+
log_message("Failed to delete file: #{ f }", Thor::Shell::Color::RED)
|
2091
|
+
raise Parallel::Kill
|
2092
|
+
|
2093
|
+
|
2094
|
+
end
|
2095
|
+
end
|
2096
|
+
end
|
2097
|
+
|
2098
|
+
|
2099
|
+
successful_deletions += successful_deletions.select { |x| not x.nil? }
|
2100
|
+
|
2101
|
+
|
2102
|
+
successful_updates = successful_updates.select { |x| not x.nil? }
|
2103
|
+
|
2104
|
+
update_count = successful_updates.size
|
2105
|
+
|
2106
|
+
rescue SignalException
|
2107
|
+
say "User aborted", Thor::Shell::Color::RED
|
2108
|
+
exit(0)
|
2109
|
+
rescue => e
|
2110
|
+
log_message("Exception while trying to upload, look at the log for more details", Thor::Shell::Color::RED)
|
2111
|
+
log_error(e)
|
2112
|
+
exit(0)
|
2113
|
+
end
|
2114
|
+
if !result["deleted"].nil? and !result["deleted"].empty?
|
2115
|
+
update_count += result["deleted"].size
|
2116
|
+
end
|
2117
|
+
|
2118
|
+
if update_count == update_total
|
2119
|
+
begin
|
2120
|
+
@dataset.update_idx_with_files_commits!((successful_deletions+successful_updates), commit_time)
|
2121
|
+
|
2122
|
+
return true
|
2123
|
+
rescue => e
|
2124
|
+
log_message("Exception while trying to upload, look at the log for more details", Thor::Shell::Color::RED)
|
2125
|
+
|
2126
|
+
exit(1)
|
2127
|
+
|
2128
|
+
end
|
2129
|
+
|
2130
|
+
end
|
2131
|
+
rescue => e
|
2132
|
+
|
2133
|
+
log_message("Exception while trying to upload, look at the log for more details", Thor::Shell::Color::RED)
|
2134
|
+
log_error(e)
|
2135
|
+
|
2136
|
+
exit(1)
|
2137
|
+
rescue SignalException
|
2138
|
+
|
2139
|
+
say "\nAborting", Thor::Shell::Color::BLUE
|
2140
|
+
exit(1)
|
2141
|
+
end
|
2142
|
+
|
2143
|
+
end
|
2144
|
+
|
2145
|
+
|
2146
|
+
desc 'upload', 'Upload updated files'
|
2147
|
+
method_option :ignore, :type => :string, :aliases => ["-i"], :desc => "ignore following files", :default => ""
|
2148
|
+
method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
|
2149
|
+
method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
|
2150
|
+
method_option :sync, :type => :boolean, :aliases => ["-s"], :default => false
|
2151
|
+
method_option :force, :type => :boolean, :aliases => ["-f", "--force"], :default => false
|
2152
|
+
method_option :message, :type => :string, :aliases => ["-m", "--message"], :default => ""
|
2153
|
+
method_option :deploy, :type => :boolean, :aliases => ["-d", "--deploy"], :default => false
|
2154
|
+
|
2155
|
+
def upload(link = false, sync = false, direct = false, ignore_list = "")
|
2156
|
+
|
2157
|
+
begin
|
2158
|
+
verify_logged_in(true)
|
2159
|
+
log_start(__method__, args, options)
|
2160
|
+
|
2161
|
+
@project = Project.new(get_project_home)
|
2162
|
+
commit_msg = options["message"]
|
2163
|
+
if commit_msg.nil? or commit_msg.empty?
|
2164
|
+
commit_msg = ""
|
2165
|
+
end
|
2166
|
+
|
2167
|
+
@files = Cnvrg::Files.new(@project.owner, @project.slug)
|
2168
|
+
ignore = options[:ignore] || ""
|
2169
|
+
force = options[:force] || false
|
2170
|
+
|
2171
|
+
if ignore.nil? or ignore.empty?
|
2172
|
+
ignore = ignore_list
|
2173
|
+
end
|
2174
|
+
data_ignore = data_dir_include()
|
2175
|
+
if !data_ignore.nil?
|
2176
|
+
if ignore.nil? or ignore.empty?
|
2177
|
+
ignore = data_ignore
|
2178
|
+
else
|
2179
|
+
ignore = "#{ignore},#{data_ignore}"
|
2180
|
+
end
|
2181
|
+
end
|
2182
|
+
if !@project.update_ignore_list(ignore)
|
2183
|
+
log_message("Couldn't append new ignore files to .cnvrgignore", Thor::Shell::Color::YELLOW)
|
2184
|
+
end
|
2185
|
+
new_branch = options["new_branch"] || false
|
2186
|
+
|
2187
|
+
if options["sync"] or sync
|
2188
|
+
new_branch_exp = @project.get_new_branch
|
2189
|
+
if new_branch_exp
|
2190
|
+
new_branch = new_branch_exp
|
2191
|
+
end
|
2192
|
+
end
|
2193
|
+
|
2194
|
+
result = @project.compare_idx(new_branch, force: force, deploy: options["deploy"])
|
2195
|
+
commit = result["result"]["commit"]
|
2196
|
+
if !link
|
2197
|
+
if ((commit != @project.last_local_commit and !@project.last_local_commit.nil? and !result["result"]["tree"]["updated_on_server"].empty?) and !force)
|
2198
|
+
|
2199
|
+
log_message("Remote server has an updated version, please run `cnvrg download` first, or alternatively: `cnvrg sync`", Thor::Shell::Color::BLUE)
|
2200
|
+
exit(1)
|
2201
|
+
end
|
2202
|
+
|
2203
|
+
log_message("Comparing local changes with remote version:", Thor::Shell::Color::BLUE, (options["verbose"]))
|
2204
|
+
end
|
2205
|
+
result = result["result"]["tree"]
|
2206
|
+
# if result["added"].any? {|x| x.include? ".conflict"} or !result["conflicts"].empty?
|
2207
|
+
# all = result["added"].select {|x| x.include? ".conflict"} +result["conflicts"].flatten
|
2208
|
+
# if all.size == 1
|
2209
|
+
# num = "conflict"
|
2210
|
+
# else
|
2211
|
+
# num = "conflicts"
|
2212
|
+
# end
|
2213
|
+
# say "Project contains #{all.size} #{num}:", Thor::Shell::Color::RED
|
2214
|
+
# say "#{all.join("\n")}"
|
2215
|
+
# say "Please fix #{num}, and retry", Thor::Shell::Color::RED
|
2216
|
+
# exit(1)
|
2217
|
+
#
|
2218
|
+
# end
|
2219
|
+
check = Helpers.checkmark()
|
2220
|
+
if result["added"].empty? and result["updated_on_local"].empty? and result["deleted"].empty?
|
2221
|
+
log_message("#{check} Project is up to date", Thor::Shell::Color::GREEN, (((options["sync"] or sync) and !direct) ? false : true))
|
2222
|
+
return true
|
2223
|
+
end
|
2224
|
+
update_count = 0
|
2225
|
+
update_total = result["added"].size + result["updated_on_local"].size + result["deleted"].size
|
2226
|
+
successful_updates = []
|
2227
|
+
successful_deletions = []
|
2228
|
+
if options["verbose"]
|
2229
|
+
if update_total == 1
|
2230
|
+
log_message("Updating #{update_total} file", Thor::Shell::Color::BLUE)
|
2231
|
+
else
|
2232
|
+
log_message("Updating #{update_total} files", Thor::Shell::Color::BLUE)
|
2233
|
+
end
|
2234
|
+
else
|
2235
|
+
log_message("Syncing files", Thor::Shell::Color::BLUE, ((options["sync"] or sync)) ? false : true)
|
2236
|
+
|
2237
|
+
end
|
2238
|
+
# Start commit
|
2239
|
+
commit_sha1 = @files.start_commit(new_branch, force: force)["result"]["commit_sha1"]
|
2240
|
+
|
2241
|
+
# upload / update
|
2242
|
+
begin
|
2243
|
+
|
2244
|
+
parallel_options = {
|
2245
|
+
:progress => {
|
2246
|
+
:title => "Upload Progress",
|
2247
|
+
:progress_mark => '=',
|
2248
|
+
:format => "%b>>%i| %p%% %t",
|
2249
|
+
:starting_at => 0,
|
1819
2250
|
:total => (result["added"] + result["updated_on_local"]).size,
|
1820
2251
|
:autofinish => true
|
1821
2252
|
},
|
@@ -1931,78 +2362,309 @@ module Cnvrg
|
|
1931
2362
|
update_count += result["deleted"].size
|
1932
2363
|
end
|
1933
2364
|
|
1934
|
-
if update_count == update_total
|
1935
|
-
res = @files.end_commit(commit_sha1, force: force, message: commit_msg)
|
1936
|
-
if (Cnvrg::CLI.is_response_success(res, false))
|
1937
|
-
# save idx
|
1938
|
-
begin
|
1939
|
-
@project.update_idx_with_files_commits!((successful_deletions + successful_updates), res["result"]["commit_time"])
|
2365
|
+
if update_count == update_total
|
2366
|
+
res = @files.end_commit(commit_sha1, force: force, message: commit_msg)
|
2367
|
+
if (Cnvrg::CLI.is_response_success(res, false))
|
2368
|
+
# save idx
|
2369
|
+
begin
|
2370
|
+
@project.update_idx_with_files_commits!((successful_deletions + successful_updates), res["result"]["commit_time"])
|
2371
|
+
|
2372
|
+
@project.update_idx_with_commit!(commit_sha1)
|
2373
|
+
rescue => e
|
2374
|
+
@files.rollback_commit(commit_sha1)
|
2375
|
+
log_message("Couldn't commit updates, Rolling Back all changes.", Thor::Shell::Color::RED)
|
2376
|
+
log_error(e)
|
2377
|
+
exit(1)
|
2378
|
+
|
2379
|
+
end
|
2380
|
+
image = is_project_with_docker(Dir.pwd)
|
2381
|
+
if image and image.is_docker
|
2382
|
+
image.update_image_activity(commit_sha1, nil)
|
2383
|
+
end
|
2384
|
+
|
2385
|
+
if options["verbose"]
|
2386
|
+
log_message("#{check} Done", Thor::Shell::Color::BLUE)
|
2387
|
+
if successful_updates.size > 0
|
2388
|
+
successful_updates.flatten!
|
2389
|
+
log_message("Updated:", Thor::Shell::Color::GREEN)
|
2390
|
+
suc = successful_updates.map {|x| x = Helpers.checkmark() + " " + x}
|
2391
|
+
log_message(suc.join("\n"), Thor::Shell::Color::GREEN)
|
2392
|
+
end
|
2393
|
+
if successful_deletions.size > 0
|
2394
|
+
successful_deletions.flatten!
|
2395
|
+
|
2396
|
+
log_message("Deleted:", Thor::Shell::Color::GREEN)
|
2397
|
+
del = successful_updates.map {|x| x = Helpers.checkmark() + " " + x}
|
2398
|
+
log_message(del.join("\n"), Thor::Shell::Color::GREEN)
|
2399
|
+
end
|
2400
|
+
log_message("Total of #{update_count} / #{update_total} files.", Thor::Shell::Color::GREEN)
|
2401
|
+
else
|
2402
|
+
if (options["sync"] or sync) and direct
|
2403
|
+
log_message("#{check} Syncing project completed successfully", Thor::Shell::Color::GREEN)
|
2404
|
+
|
2405
|
+
else
|
2406
|
+
log_message("#{check} Changes were updated successfully", Thor::Shell::Color::GREEN)
|
2407
|
+
|
2408
|
+
end
|
2409
|
+
|
2410
|
+
end
|
2411
|
+
|
2412
|
+
else
|
2413
|
+
@files.rollback_commit(commit_sha1)
|
2414
|
+
log_message("Error: couldn't commit changes, Rolling Back all changes.", Thor::Shell::Color::RED)
|
2415
|
+
end
|
2416
|
+
else
|
2417
|
+
@files.rollback_commit(commit_sha1)
|
2418
|
+
log_message("Error: uploaded only: #{update_count} / #{update_total}, \n Rolling back", Thor::Shell::Color::RED)
|
2419
|
+
|
2420
|
+
end
|
2421
|
+
rescue => e
|
2422
|
+
|
2423
|
+
log_message("Error occurred, \nAborting", Thor::Shell::Color::RED)
|
2424
|
+
log_error(e)
|
2425
|
+
@files.rollback_commit(commit_sha1) unless commit_sha1.nil?
|
2426
|
+
puts e.message
|
2427
|
+
|
2428
|
+
exit(1)
|
2429
|
+
rescue SignalException
|
2430
|
+
|
2431
|
+
say "\nAborting", Thor::Shell::Color::BLUE
|
2432
|
+
say "\nRolling back all changes", Thor::Shell::Color::BLUE
|
2433
|
+
@files.rollback_commit(commit_sha1) unless commit_sha1.nil?
|
2434
|
+
exit(1)
|
2435
|
+
end
|
2436
|
+
|
2437
|
+
end
|
2438
|
+
desc 'download_file_data', 'Download one data files'
|
2439
|
+
method_option :verbose, :type => :boolean, :aliases => ["-v", "--verbose"], :default => false
|
2440
|
+
method_option :commit, :type => :string, :aliases => ["-c", "--commit"], :desc => "download specified commit", :default => nil
|
2441
|
+
method_option :link, :type => :boolean, :aliases => ["-l","--link"], :desc => "download specified commit", :default => false
|
2442
|
+
method_option :download_path, :type => :string, :aliases => ["-p", "--path"], :desc => "download specified commit", :default => ""
|
2443
|
+
method_option :remote, :type => :boolean, :aliases => ["-r","--remote"], :desc => "remote download", :default => false
|
2444
|
+
method_option :json, :type => :boolean, :aliases => ["-j","--json"],:default => false, :desc => "response as json"
|
2445
|
+
|
2446
|
+
def download_file_data(file_path, *dataset_path)
|
2447
|
+
|
2448
|
+
verify_logged_in(true)
|
2449
|
+
log_start(__method__, args, options)
|
2450
|
+
begin
|
2451
|
+
if dataset_path.nil? or dataset_path.empty?
|
2452
|
+
dataset_path = Dir.pwd
|
2453
|
+
elsif dataset_path.is_a? Array
|
2454
|
+
dataset_path = dataset_path[0]
|
2455
|
+
end
|
2456
|
+
dataset_dir = is_cnvrg_dir(dataset_path)
|
2457
|
+
@dataset = Dataset.new(dataset_dir)
|
2458
|
+
@files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug)
|
2459
|
+
commit_to_download = options["commit"] || nil
|
2460
|
+
as_link = options["link"] || false
|
2461
|
+
download_path = options["path"]
|
2462
|
+
remote = options["remote"]
|
2463
|
+
as_json = options["json"]
|
2464
|
+
if remote
|
2465
|
+
download_path = "/data/#{@dataset.title}/"
|
2466
|
+
|
2467
|
+
else
|
2468
|
+
download_path = dataset_dir
|
2469
|
+
end
|
2470
|
+
if !as_json
|
2471
|
+
|
2472
|
+
log_message("Downloading file", Thor::Shell::Color::BLUE)
|
2473
|
+
|
2474
|
+
end
|
2475
|
+
res = @files.download_file_s3(file_path, file_path, download_path, conflict=false, commit_sha1=commit_to_download, as_link=as_link)
|
2476
|
+
if as_link
|
2477
|
+
puts res
|
2478
|
+
else
|
2479
|
+
if res
|
2480
|
+
if as_json
|
2481
|
+
response = {"status":"success"}
|
2482
|
+
puts response.to_json
|
2483
|
+
else
|
2484
|
+
log_message("#{Helpers.checkmark()} File #{file_path} was successfully downloaded", Thor::Shell::Color::GREEN)
|
2485
|
+
|
2486
|
+
end
|
2487
|
+
end
|
2488
|
+
|
2489
|
+
|
2490
|
+
end
|
2491
|
+
|
2492
|
+
rescue =>e
|
2493
|
+
log_message("Error occurred, \nAborting", Thor::Shell::Color::BLUE)
|
2494
|
+
log_error(e)
|
2495
|
+
exit(1)
|
2496
|
+
end
|
2497
|
+
end
|
2498
|
+
|
2499
|
+
desc 'download_data_new', 'Download updated files'
|
2500
|
+
method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
|
2501
|
+
method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
|
2502
|
+
method_option :sync, :type => :boolean, :aliases => ["-s"], :default => false
|
2503
|
+
method_option :commit, :type => :string, :aliases => ["-c"], :desc => "download specified commit", :default => ""
|
2504
|
+
method_option :all_files, :type => :boolean, :aliases => ["--all"], :desc => "download specified commit", :default => false
|
2505
|
+
|
2506
|
+
begin
|
2507
|
+
def download_data_new(verbose=false,sync=false, commit=nil,all_files=true)
|
2508
|
+
verify_logged_in(true)
|
2509
|
+
log_start(__method__, args, options)
|
2510
|
+
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
2511
|
+
@dataset = Dataset.new(dataset_dir)
|
2512
|
+
@files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug)
|
2513
|
+
commit_to_download = commit
|
2514
|
+
local_idx = @dataset.generate_idx
|
2515
|
+
all_files = all_files
|
2516
|
+
if !commit_to_download.nil? and !commit_to_download.empty?
|
2517
|
+
res = @dataset.compare_idx_download( commit=commit_to_download, local_idx= local_idx,all_files=all_files)
|
2518
|
+
else
|
2519
|
+
res = @dataset.compare_idx_download( commit=nil, local_idx= local_idx,all_files=all_files)
|
2520
|
+
|
2521
|
+
end
|
2522
|
+
|
2523
|
+
result = res["result"]["tree"]
|
2524
|
+
|
2525
|
+
commit = res["result"]["commit"]
|
2526
|
+
if result["updated_on_server"].empty? and result["conflicts"].empty? and result["deleted"].empty?
|
2527
|
+
log_message("Dataset is up to date", Thor::Shell::Color::GREEN, ((options["sync"] or sync) ? false : true))
|
2528
|
+
return true
|
2529
|
+
end
|
2530
|
+
update_total = result["updated_on_server"].size + result["conflicts"].size + result["deleted"].size
|
2531
|
+
|
2532
|
+
|
2533
|
+
successful_changes = 0
|
2534
|
+
if update_total ==1
|
2535
|
+
log_message("Downloading #{update_total} file", Thor::Shell::Color::BLUE, !sync)
|
2536
|
+
elsif update_total == 0
|
2537
|
+
log_message("Dataset is up to date", Thor::Shell::Color::GREEN, !sync)
|
2538
|
+
return true
|
2539
|
+
elsif options["verbose"]
|
2540
|
+
log_message("Downloading #{update_total} files", Thor::Shell::Color::BLUE)
|
2541
|
+
else
|
2542
|
+
log_message("Syncing Dataset", Thor::Shell::Color::BLUE, !sync)
|
2543
|
+
|
2544
|
+
end
|
2545
|
+
parallel_options = {
|
2546
|
+
:progress => {
|
2547
|
+
:title => "Download Progress",
|
2548
|
+
:progress_mark => '=',
|
2549
|
+
:format => "%b>>%i| %p%% %t",
|
2550
|
+
:starting_at => 0,
|
2551
|
+
:total => result["updated_on_server"].size,
|
2552
|
+
:autofinish => true
|
2553
|
+
},
|
2554
|
+
in_threads: ParallelThreads
|
2555
|
+
}
|
2556
|
+
conflicts = 0
|
2557
|
+
if !result["conflicts"].empty?
|
2558
|
+
begin
|
2559
|
+
|
2560
|
+
|
2561
|
+
conflicts_result = Parallel.map(result["conflicts"], in_threads: ParallelThreads) do |f|
|
2562
|
+
|
2563
|
+
relative_path = f.gsub(/^#{@dataset.local_path}/, "")
|
2564
|
+
log_message("downloading: #{f}.conflict", Thor::Shell::Color::BLUE, verbose)
|
2565
|
+
|
2566
|
+
if @files.download_file_s3(f, relative_path, dataset_dir, conflict=true, commit_sha1=commit)
|
2567
|
+
conflicts +=1
|
2568
|
+
else
|
2569
|
+
log_message("Couldn't download: #{f}", Thor::Shell::Color::RED)
|
2570
|
+
raise Parallel::Kill
|
2571
|
+
|
2572
|
+
end
|
2573
|
+
end
|
2574
|
+
rescue Interrupt
|
2575
|
+
|
2576
|
+
log_message("Failed to download files", Thor::Shell::Color::RED)
|
2577
|
+
|
2578
|
+
exit(1)
|
2579
|
+
end
|
2580
|
+
end
|
2581
|
+
|
2582
|
+
|
2583
|
+
successful_changes += conflicts
|
2584
|
+
downloads = 0
|
2585
|
+
if !result["updated_on_server"].empty?
|
2586
|
+
|
2587
|
+
updated_on_server_result = Parallel.map(result["updated_on_server"], parallel_options) do |f|
|
2588
|
+
begin
|
2589
|
+
relative_path = f.gsub(/^#{@dataset.local_path}/, "")
|
2590
|
+
if f.end_with? "/"
|
2591
|
+
# dir
|
2592
|
+
if !all_files
|
2593
|
+
log_message("downloading dir: #{f}", Thor::Shell::Color::BLUE, verbose)
|
2594
|
+
if @files.download_dir(dataset_dir, relative_path)
|
2595
|
+
downloads +=1
|
2596
|
+
else
|
2597
|
+
log_message("Couldn't create directory: #{f}", Thor::Shell::Color::RED)
|
2598
|
+
raise Parallel::Kill
|
2599
|
+
|
1940
2600
|
|
1941
|
-
|
1942
|
-
|
1943
|
-
@files.rollback_commit(commit_sha1)
|
1944
|
-
log_message("Couldn't commit updates, Rolling Back all changes.", Thor::Shell::Color::RED)
|
1945
|
-
log_error(e)
|
1946
|
-
exit(1)
|
2601
|
+
end
|
2602
|
+
end
|
1947
2603
|
|
1948
|
-
|
1949
|
-
|
1950
|
-
|
1951
|
-
image.update_image_activity(commit_sha1, nil)
|
1952
|
-
end
|
2604
|
+
else
|
2605
|
+
# blob
|
2606
|
+
log_message("downloading file: #{f}", Thor::Shell::Color::BLUE, verbose)
|
1953
2607
|
|
1954
|
-
|
1955
|
-
|
1956
|
-
if successful_updates.size > 0
|
1957
|
-
successful_updates.flatten!
|
1958
|
-
log_message("Updated:", Thor::Shell::Color::GREEN)
|
1959
|
-
suc = successful_updates.map {|x| x = Helpers.checkmark() + " " + x}
|
1960
|
-
log_message(suc.join("\n"), Thor::Shell::Color::GREEN)
|
1961
|
-
end
|
1962
|
-
if successful_deletions.size > 0
|
1963
|
-
successful_deletions.flatten!
|
2608
|
+
if @files.download_file_s3(f, relative_path, dataset_dir,conflict=false, commit_sha1=commit)
|
2609
|
+
downloads +=1
|
1964
2610
|
|
1965
|
-
|
1966
|
-
|
1967
|
-
|
2611
|
+
else
|
2612
|
+
|
2613
|
+
log_message("Couldn't download: #{f}", Thor::Shell::Color::RED)
|
2614
|
+
raise Parallel::Kill
|
2615
|
+
|
2616
|
+
|
2617
|
+
end
|
1968
2618
|
end
|
1969
|
-
|
1970
|
-
|
1971
|
-
if (options["sync"] or sync) and direct
|
1972
|
-
log_message("#{check} Syncing project completed successfully", Thor::Shell::Color::GREEN)
|
2619
|
+
rescue Interrupt
|
2620
|
+
log_message("Couldn't download", Thor::Shell::Color::RED)
|
1973
2621
|
|
1974
|
-
|
1975
|
-
log_message("#{check} Changes were updated successfully", Thor::Shell::Color::GREEN)
|
2622
|
+
exit(1)
|
1976
2623
|
|
1977
2624
|
end
|
1978
2625
|
|
1979
2626
|
end
|
2627
|
+
successful_changes += downloads
|
2628
|
+
|
2629
|
+
end
|
2630
|
+
|
2631
|
+
deleted = result["deleted"].to_a
|
2632
|
+
delete_res = @files.delete_commit_files_local(deleted)
|
2633
|
+
if !delete_res
|
2634
|
+
log_message("Couldn't delete #{deleted.join(" ")}", Thor::Shell::Color::RED)
|
2635
|
+
log_message("Couldn't download, Rolling Back all changes.", Thor::Shell::Color::RED)
|
2636
|
+
|
2637
|
+
exit(1)
|
2638
|
+
|
2639
|
+
end
|
2640
|
+
successful_changes += deleted.size
|
2641
|
+
|
1980
2642
|
|
2643
|
+
|
2644
|
+
if update_total == successful_changes
|
2645
|
+
# update idx with latest commit
|
2646
|
+
@dataset.update_idx_with_commit!(commit)
|
2647
|
+
check = Helpers.checkmark()
|
2648
|
+
|
2649
|
+
if options["verbose"]
|
2650
|
+
log_message("#{check} Done, Downloaded:", Thor::Shell::Color::GREEN)
|
2651
|
+
log_message(successful_changes.join("\n"), Thor::Shell::Color::GREEN)
|
2652
|
+
log_message("Total of #{successful_changes.size} / #{update_total} files.", Thor::Shell::Color::GREEN)
|
1981
2653
|
else
|
1982
|
-
|
1983
|
-
log_message("Error: couldn't commit changes, Rolling Back all changes.", Thor::Shell::Color::RED)
|
2654
|
+
log_message("#{check} Downloaded changes successfully", Thor::Shell::Color::GREEN, ((sync or options["sync"]) ? false : true))
|
1984
2655
|
end
|
1985
|
-
|
1986
|
-
@files.rollback_commit(commit_sha1)
|
1987
|
-
log_message("Error: uploaded only: #{update_count} / #{update_total}, \n Rolling back", Thor::Shell::Color::RED)
|
2656
|
+
return true
|
1988
2657
|
|
1989
2658
|
end
|
1990
2659
|
rescue => e
|
1991
2660
|
|
1992
|
-
log_message("Error occurred, \nAborting", Thor::Shell::Color::
|
2661
|
+
log_message("Error occurred, \nAborting", Thor::Shell::Color::BLUE)
|
1993
2662
|
log_error(e)
|
1994
|
-
@files.rollback_commit(commit_sha1) unless commit_sha1.nil?
|
1995
|
-
puts e.message
|
1996
|
-
|
1997
2663
|
exit(1)
|
1998
2664
|
rescue SignalException
|
1999
|
-
|
2000
2665
|
say "\nAborting", Thor::Shell::Color::BLUE
|
2001
|
-
say "\nRolling back all changes", Thor::Shell::Color::BLUE
|
2002
|
-
@files.rollback_commit(commit_sha1) unless commit_sha1.nil?
|
2003
2666
|
exit(1)
|
2004
2667
|
end
|
2005
|
-
|
2006
2668
|
end
|
2007
2669
|
|
2008
2670
|
desc 'download', 'Download updated files'
|
@@ -2219,6 +2881,8 @@ module Cnvrg
|
|
2219
2881
|
end
|
2220
2882
|
|
2221
2883
|
|
2884
|
+
|
2885
|
+
|
2222
2886
|
desc 'jump', 'jump to specific commit'
|
2223
2887
|
method_option :remote, :type => :boolean, :aliases => ["-r", "--r"], :default => false
|
2224
2888
|
|
@@ -2428,7 +3092,9 @@ module Cnvrg
|
|
2428
3092
|
method_option :ignore, :type => :string, :aliases => ["-i", "--ignore"], :desc => "ignore following files", :default => ""
|
2429
3093
|
method_option :force, :type => :boolean, :aliases => ["-f", "--force"], :default => false
|
2430
3094
|
method_option :sync_before_terminate, :type => :boolean, :aliases => ["-sbt", "--sync_before_terminate"], :default => false
|
2431
|
-
method_option :periodic_sync, :type => :string, :aliases => ["-ps", "--
|
3095
|
+
method_option :periodic_sync, :type => :string, :aliases => ["-ps", "--periodic_sync"], :default => nil #//15,30,45,60
|
3096
|
+
method_option :max_time, :type => :string, :aliases => [ "--max_time"], :default => nil
|
3097
|
+
method_option :dataset_only_tree, :type => :boolean, :aliases => [ "--dataset_only_tree"], :default => false
|
2432
3098
|
|
2433
3099
|
|
2434
3100
|
def run(*cmd)
|
@@ -2451,6 +3117,8 @@ module Cnvrg
|
|
2451
3117
|
sync_before_terminate = options["sync_before_terminate"]
|
2452
3118
|
periodic_sync = options["periodic_sync"]
|
2453
3119
|
force = options["force"]
|
3120
|
+
max_time = options["max_time"]
|
3121
|
+
dataset_only_tree = options["dataset_only_tree"]
|
2454
3122
|
|
2455
3123
|
options_hash = Hash[options]
|
2456
3124
|
real_options = []
|
@@ -2464,8 +3132,7 @@ module Cnvrg
|
|
2464
3132
|
return
|
2465
3133
|
else
|
2466
3134
|
if !periodic_sync.nil? and !periodic_sync.empty?
|
2467
|
-
if /^\d{2}
|
2468
|
-
periodic_sync = periodic_sync.gsub("m","")
|
3135
|
+
if /^\d{2}$/ === periodic_sync
|
2469
3136
|
if !["15","30","45","60"].include? periodic_sync
|
2470
3137
|
log_message("periodic sync can only be every 15m, 30m, 45m or 60m", Thor::Shell::Color::RED)
|
2471
3138
|
exit(1)
|
@@ -2488,7 +3155,8 @@ module Cnvrg
|
|
2488
3155
|
invoke :exec_remote, [cmd], :sync_before => sync_before, :sync_after => sync_after, :title => title, :machine_type => instance_type,
|
2489
3156
|
:schedule => schedule, :log => log, :email_notification => email_notification, :upload_output => upload_output, :commit => commit,
|
2490
3157
|
:image => image, :grid => grid, :data => data, :data_commit => data_commit, :ignore => ignore, :force => force, :sync_before_terminate => sync_before_terminate,
|
2491
|
-
|
3158
|
+
:max_time => max_time,
|
3159
|
+
:periodic_sync => periodic_sync, :dataset_only_tree=> dataset_only_tree
|
2492
3160
|
return
|
2493
3161
|
end
|
2494
3162
|
|
@@ -2523,7 +3191,6 @@ module Cnvrg
|
|
2523
3191
|
method_option :sync_before_terminate, :type => :boolean, :aliases => ["-sbt", "--sync_before_terminate"], :default => false
|
2524
3192
|
method_option :periodic_sync, :type => :string, :aliases => ["-ps", "--periodic_sync"], :default => ""
|
2525
3193
|
def exec(*cmd)
|
2526
|
-
|
2527
3194
|
log = []
|
2528
3195
|
cpu_average = 0
|
2529
3196
|
memory_average = 0
|
@@ -2834,190 +3501,6 @@ module Cnvrg
|
|
2834
3501
|
exit(1)
|
2835
3502
|
end
|
2836
3503
|
end
|
2837
|
-
|
2838
|
-
desc '', '', :hide => true
|
2839
|
-
method_option :sync_before, :type => :boolean, :aliases => ["-sb", "--sb"], :default => true
|
2840
|
-
method_option :sync_after, :type => :boolean, :aliases => ["-sa", "--sa"], :default => true
|
2841
|
-
method_option :title, :type => :string, :aliases => ["-t", "--t"], :default => ""
|
2842
|
-
method_option :log, :type => :boolean, :aliases => ["-l", "--l"], :default => false
|
2843
|
-
method_option :email_notification, :type => :boolean, :aliases => ["-en", "--en"], :default => false
|
2844
|
-
method_option :upload_output, :type => :string, :aliases => ["--uo", "-uo"], :default => ""
|
2845
|
-
|
2846
|
-
def exec_docker(*cmd)
|
2847
|
-
log = []
|
2848
|
-
cpu_average = 0
|
2849
|
-
memory_average = 0
|
2850
|
-
verify_logged_in()
|
2851
|
-
log_start(__method__, args, options)
|
2852
|
-
project_home = "/home/ds/notebooks"
|
2853
|
-
@project = Project.new(project_home)
|
2854
|
-
sync_before = options["sync_before"]
|
2855
|
-
sync_after = options["sync_after"]
|
2856
|
-
print_log = options["log"]
|
2857
|
-
title = options["title"]
|
2858
|
-
email_notification = options["email_notification"]
|
2859
|
-
upload_output = options["upload_output"]
|
2860
|
-
time_to_upload = calc_output_time(upload_output)
|
2861
|
-
@image = is_project_with_docker(project_home)
|
2862
|
-
|
2863
|
-
|
2864
|
-
begin
|
2865
|
-
start_commit = @project.last_local_commit
|
2866
|
-
cmd = cmd.join("\s")
|
2867
|
-
|
2868
|
-
log_message("Running: #{cmd}\n", Thor::Shell::Color::BLUE)
|
2869
|
-
|
2870
|
-
@exp = Experiment.new(@project.owner, @project.slug)
|
2871
|
-
machine_activity = @exp.get_machine_activity(project_home)
|
2872
|
-
|
2873
|
-
platform = RUBY_PLATFORM
|
2874
|
-
machine_name = Socket.gethostname
|
2875
|
-
begin
|
2876
|
-
|
2877
|
-
@exp.start(cmd, platform, machine_name, start_commit, title, email_notification, machine_activity, Dir.pwd)
|
2878
|
-
unless @exp.slug.nil?
|
2879
|
-
real = Time.now
|
2880
|
-
exp_success = true
|
2881
|
-
memory_total = []
|
2882
|
-
cpu_total = []
|
2883
|
-
start_loop = Time.now
|
2884
|
-
begin
|
2885
|
-
PTY.spawn(cmd) do |stdout, stdin, pid, stderr|
|
2886
|
-
begin
|
2887
|
-
stdout.each do |line|
|
2888
|
-
cur_time = Time.now
|
2889
|
-
monitor = %x{ps aux|awk '{print $2,$3,$4}'|grep #{pid} }
|
2890
|
-
monitor_by = monitor.split(" ")
|
2891
|
-
memory = monitor_by[2]
|
2892
|
-
cpu = monitor_by[1]
|
2893
|
-
memory_total << memory.to_f
|
2894
|
-
cpu_total << cpu.to_f
|
2895
|
-
real_time = Time.now - real
|
2896
|
-
|
2897
|
-
cur_log = {time: cur_time,
|
2898
|
-
message: line,
|
2899
|
-
type: "stdout",
|
2900
|
-
real: real_time}
|
2901
|
-
if print_log
|
2902
|
-
puts cur_log
|
2903
|
-
end
|
2904
|
-
log << cur_log
|
2905
|
-
|
2906
|
-
begin
|
2907
|
-
if time_to_upload != 0
|
2908
|
-
if time_to_upload <= Time.now - start_loop
|
2909
|
-
#upload current log
|
2910
|
-
cpu_average = cpu_total.inject(0) {|sum, el| sum + el}.to_f / cpu_total.size
|
2911
|
-
memory_average = memory_total.inject(0) {|sum, el| sum + el}.to_f / memory_total.size
|
2912
|
-
|
2913
|
-
@exp.upload_temp_log(log, cpu_average, memory_average)
|
2914
|
-
log = []
|
2915
|
-
start_loop = Time.now
|
2916
|
-
end
|
2917
|
-
|
2918
|
-
end
|
2919
|
-
rescue
|
2920
|
-
log_message("Failed to upload ongoing results, continuing with experiment", Thor::Shell::Color::YELLOW)
|
2921
|
-
end
|
2922
|
-
|
2923
|
-
end
|
2924
|
-
|
2925
|
-
|
2926
|
-
if stderr
|
2927
|
-
|
2928
|
-
stderr.each do |err|
|
2929
|
-
|
2930
|
-
log << {time: Time.now, message: err, type: "stderr"}
|
2931
|
-
end
|
2932
|
-
end
|
2933
|
-
|
2934
|
-
rescue Errno::EIO => e
|
2935
|
-
break
|
2936
|
-
rescue Errno::ENOENT
|
2937
|
-
|
2938
|
-
exp_success = false
|
2939
|
-
|
2940
|
-
log_message("command \"#{cmd}\" couldn't be executed, verify command is valid", Thor::Shell::Color::RED)
|
2941
|
-
rescue PTY::ChildExited
|
2942
|
-
exp_success = false
|
2943
|
-
log_message("The process exited!", Thor::Shell::Color::RED)
|
2944
|
-
rescue => e
|
2945
|
-
log_message("Error occurred, aborting", Thor::Shell::Color::RED)
|
2946
|
-
log_error(e)
|
2947
|
-
exit(0)
|
2948
|
-
end
|
2949
|
-
::Process.wait pid
|
2950
|
-
cpu_average = cpu_total.inject(0) {|sum, el| sum + el}.to_f / cpu_total.size
|
2951
|
-
memory_average = memory_total.inject(0) {|sum, el| sum + el}.to_f / memory_total.size
|
2952
|
-
exit_status = $?.exitstatus
|
2953
|
-
if $?.exitstatus != 0
|
2954
|
-
exp_success = false
|
2955
|
-
end
|
2956
|
-
if !exp_success
|
2957
|
-
if !Cnvrg::Helpers.internet_connection?
|
2958
|
-
wait_offline = agree "Seems like you're offline, wait until your'e back online?", Thor::Shell::Color::YELLOW
|
2959
|
-
if wait_offline
|
2960
|
-
log_message("Waiting until your'e online..", Thor::Shell::Color::BLUE)
|
2961
|
-
while !Cnvrg::Helpers.internet_connection?
|
2962
|
-
end
|
2963
|
-
exit_status = 0
|
2964
|
-
else
|
2965
|
-
log_message("Experiment has failed, your'e computer is offline", Thor::Shell::Color::RED)
|
2966
|
-
exit(0)
|
2967
|
-
end
|
2968
|
-
else
|
2969
|
-
|
2970
|
-
end_commit = @project.last_local_commit
|
2971
|
-
res = @exp.end(log, exit_status, end_commit, cpu_average, memory_average)
|
2972
|
-
@image.update_image_activity(@project.last_local_commit, @exp.slug)
|
2973
|
-
log_message("Experiment has failed, look at the log for more details or run cnvrg exec --log", Thor::Shell::Color::RED)
|
2974
|
-
exit(0)
|
2975
|
-
end
|
2976
|
-
|
2977
|
-
end
|
2978
|
-
if sync_after
|
2979
|
-
log_message("Syncing project after running", Thor::Shell::Color::BLUE)
|
2980
|
-
# Sync after run
|
2981
|
-
download()
|
2982
|
-
upload()
|
2983
|
-
log_message("Done Syncing", Thor::Shell::Color::BLUE)
|
2984
|
-
end
|
2985
|
-
end_commit = @project.last_local_commit
|
2986
|
-
|
2987
|
-
res = @exp.end(log, exit_status, end_commit, cpu_average, memory_average)
|
2988
|
-
@image.update_image_activity(@project.last_local_commit, @exp.slug)
|
2989
|
-
|
2990
|
-
check = Helpers.checkmark()
|
2991
|
-
log_message("#{check} Done. Experiment's result: #{Cnvrg::Helpers.remote_url}/#{@project.owner}/projects/#{@project.slug}/experiments/#{@exp.slug}", Thor::Shell::Color::GREEN)
|
2992
|
-
end
|
2993
|
-
rescue => e
|
2994
|
-
log_message("Couldn't run #{cmd}, check your input parameters", Thor::Shell::Color::RED)
|
2995
|
-
log_error(e)
|
2996
|
-
exit(1)
|
2997
|
-
end
|
2998
|
-
|
2999
|
-
|
3000
|
-
end
|
3001
|
-
|
3002
|
-
end
|
3003
|
-
rescue => e
|
3004
|
-
log_message("Error occurred, Aborting", Thor::Shell::Color::RED)
|
3005
|
-
log_error(e)
|
3006
|
-
|
3007
|
-
rescue SignalException
|
3008
|
-
exit_status = -1
|
3009
|
-
end_commit = @project.last_local_commit
|
3010
|
-
if !@exp.nil?
|
3011
|
-
|
3012
|
-
res = @exp.end(log, exit_status, end_commit, cpu_average, memory_average)
|
3013
|
-
end
|
3014
|
-
|
3015
|
-
say "\nAborting"
|
3016
|
-
|
3017
|
-
exit(1)
|
3018
|
-
end
|
3019
|
-
end
|
3020
|
-
|
3021
3504
|
desc '', '', :hide => true
|
3022
3505
|
method_option :sync_before, :type => :boolean, :aliases => ["-sb", "--sync_before"], :default => true
|
3023
3506
|
method_option :sync_after, :type => :boolean, :aliases => ["-sa", "--sync_after"], :default => true
|
@@ -3034,6 +3517,10 @@ module Cnvrg
|
|
3034
3517
|
method_option :data_commit, :type => :string, :aliases => ["--data_commit"], :default => ""
|
3035
3518
|
method_option :ignore, :type => :string, :aliases => ["-i", "--ignore"], :desc => "ignore following files", :default => ""
|
3036
3519
|
method_option :force, :type => :boolean, :aliases => ["-f", "--force"], :default => false
|
3520
|
+
method_option :max_time, :type => :string, :aliases => [ "--max_time"], :default => nil
|
3521
|
+
method_option :dataset_only_tree, :type => :boolean, :aliases => [ "--dataset_only_tree"], :default => false
|
3522
|
+
method_option :periodic_sync, :type => :string, :aliases => ["-ps", "--periodic_sync"], :default => nil
|
3523
|
+
method_option :sync_before_terminate, :type => :boolean, :aliases => ["-sbt", "--sync_before_terminate"], :default => false
|
3037
3524
|
|
3038
3525
|
def exec_remote(*cmd)
|
3039
3526
|
verify_logged_in(true)
|
@@ -3047,6 +3534,21 @@ module Cnvrg
|
|
3047
3534
|
data_commit = options["data_commit"] || nil
|
3048
3535
|
sync_before = options["sync_before"]
|
3049
3536
|
force = options["force"]
|
3537
|
+
max_time = options["max_time"]
|
3538
|
+
if !max_time.nil? and !max_time.empty?
|
3539
|
+
max_time = max_time.to_i
|
3540
|
+
if max_time <=0
|
3541
|
+
log_message("Max time for experiment should be more than 0 minutess", Thor::Shell::Color::RED)
|
3542
|
+
exit(1)
|
3543
|
+
end
|
3544
|
+
end
|
3545
|
+
periodic_sync = options["periodic_sync"]
|
3546
|
+
sync_before_terminate = options["sync_before_terminate"]
|
3547
|
+
dataset_only_tree = options["dataset_only_tree"]
|
3548
|
+
ds_sync_options = 0
|
3549
|
+
if dataset_only_tree
|
3550
|
+
ds_sync_options = 1
|
3551
|
+
end
|
3050
3552
|
|
3051
3553
|
instance_type = options["machine_type"] || nil
|
3052
3554
|
schedule = options["schedule"] || ""
|
@@ -3081,7 +3583,7 @@ module Cnvrg
|
|
3081
3583
|
end
|
3082
3584
|
|
3083
3585
|
options_hash = Hash[options]
|
3084
|
-
options_hash.except!("schedule", "machine_type", "image", "upload_output", "grid", "data", "data_commit", "local", "small", "medium", "large", "gpu", "gpuxl", "gpuxxl")
|
3586
|
+
options_hash.except!("schedule", "machine_type", "image", "upload_output", "grid", "data", "data_commit", "local", "small", "medium", "large", "gpu", "gpuxl", "gpuxxl","max_time","dataset_only_tree")
|
3085
3587
|
exec_options = options_hash.map {|x| "--#{x[0]}=#{x[1]}"}.flatten.join(" ")
|
3086
3588
|
command = "#{exec_options} #{remote} #{upload_output_option} #{cmd.flatten.join(" ")}"
|
3087
3589
|
commit_to_run = options["commit"] || nil
|
@@ -3105,13 +3607,6 @@ module Cnvrg
|
|
3105
3607
|
if instance_type.eql? "gpu" or instance_type.eql? "gpuxl"
|
3106
3608
|
image_slug = "cnvrg_gpu"
|
3107
3609
|
end
|
3108
|
-
# default = yes? "use #{default_image_name} default image?", Thor::Shell::Color::YELLOW
|
3109
|
-
# if default
|
3110
|
-
# image = Images.new(working_dir, default_image_name)
|
3111
|
-
# image_slug = image.image_slug
|
3112
|
-
# else
|
3113
|
-
# exit(0)
|
3114
|
-
# end
|
3115
3610
|
else
|
3116
3611
|
image_slug = image.image_slug
|
3117
3612
|
end
|
@@ -3135,7 +3630,8 @@ module Cnvrg
|
|
3135
3630
|
end
|
3136
3631
|
log_message("Running remote experiment", Thor::Shell::Color::BLUE)
|
3137
3632
|
exp = Experiment.new(project.owner, project.slug)
|
3138
|
-
res = exp.exec_remote(command, commit_to_run, instance_type, image_slug, schedule, local_timestamp, grid, path_to_cmd, data, data_commit
|
3633
|
+
res = exp.exec_remote(command, commit_to_run, instance_type, image_slug, schedule, local_timestamp, grid, path_to_cmd, data, data_commit,
|
3634
|
+
periodic_sync, sync_before_terminate, max_time, ds_sync_options)
|
3139
3635
|
if Cnvrg::CLI.is_response_success(res)
|
3140
3636
|
# if res["result"]["machine"] == -1
|
3141
3637
|
# say "There are no available machines", Thor::Shell::Color::BLUE
|
@@ -3194,7 +3690,6 @@ module Cnvrg
|
|
3194
3690
|
exit(1)
|
3195
3691
|
end
|
3196
3692
|
end
|
3197
|
-
|
3198
3693
|
desc 'deploy', 'Deploys model to production'
|
3199
3694
|
method_option :small, :type => :boolean, :aliases => ["-sm", "--small"], :default => false
|
3200
3695
|
method_option :medium, :type => :boolean, :aliases => ["-md", "--medium"], :default => false
|
@@ -3323,6 +3818,7 @@ module Cnvrg
|
|
3323
3818
|
method_option :image, :type => :string, :aliases => ["-i", "--image"], :default => ""
|
3324
3819
|
method_option :data, :type => :string, :aliases => ["-d", "--data"], :default => ""
|
3325
3820
|
method_option :data_commit, :type => :string, :aliases => ["--data_commit"], :default => ""
|
3821
|
+
method_option :dataset_only_tree, :type => :boolean, :aliases => [ "--dataset_only_tree"], :default => false
|
3326
3822
|
|
3327
3823
|
|
3328
3824
|
desc 'notebook', 'starts a notebook session remotely or locally'
|
@@ -3334,6 +3830,7 @@ module Cnvrg
|
|
3334
3830
|
image = options["image"]
|
3335
3831
|
data = options["data"]
|
3336
3832
|
data_commit = options["data_commit"]
|
3833
|
+
dataset_only_tree = options["dataset_only_tree"]
|
3337
3834
|
if local
|
3338
3835
|
invoke :run_notebook, [], :notebook_dir => notebook_dir, :remote => false, :kernel => kernel, :image => image
|
3339
3836
|
return
|
@@ -3343,7 +3840,7 @@ module Cnvrg
|
|
3343
3840
|
instance_type = get_instance_type(instances)
|
3344
3841
|
|
3345
3842
|
invoke :remote_notebook, [], :notebook_dir => notebook_dir, :kernel => kernel, :machine_type => instance_type, :image => image,
|
3346
|
-
:data => data, :data_commit => data_commit
|
3843
|
+
:data => data, :data_commit => data_commit , :dataset_only_tree => dataset_only_tree
|
3347
3844
|
return
|
3348
3845
|
|
3349
3846
|
end
|
@@ -3462,6 +3959,7 @@ module Cnvrg
|
|
3462
3959
|
method_option :data, :type => :string, :aliases => ["-d", "--data"], :default => ""
|
3463
3960
|
method_option :data_commit, :type => :string, :aliases => ["--data_commit"], :default => ""
|
3464
3961
|
method_option :commit, :type => :string, :aliases => ["--commit"], :default => ""
|
3962
|
+
method_option :dataset_only_tree, :type => :boolean, :aliases => [ "--dataset_only_tree"], :default => false
|
3465
3963
|
|
3466
3964
|
|
3467
3965
|
def remote_notebook()
|
@@ -3474,7 +3972,11 @@ module Cnvrg
|
|
3474
3972
|
data_commit = options["data_commit"]
|
3475
3973
|
commit = options["commit"]
|
3476
3974
|
notebook_type = options["notebook_type"]
|
3477
|
-
|
3975
|
+
dataset_only_tree = options["dataset_only_tree"]
|
3976
|
+
ds_sync_options = 0
|
3977
|
+
if dataset_only_tree
|
3978
|
+
ds_sync_options = 1
|
3979
|
+
end
|
3478
3980
|
|
3479
3981
|
begin
|
3480
3982
|
project = Project.new(working_dir)
|
@@ -3485,7 +3987,7 @@ module Cnvrg
|
|
3485
3987
|
end
|
3486
3988
|
invoke :sync, [false], []
|
3487
3989
|
slug = ""
|
3488
|
-
res = exp.remote_notebook(instance_type, commit, data, data_commit, notebook_type)
|
3990
|
+
res = exp.remote_notebook(instance_type, commit, data, data_commit, notebook_type,ds_sync_options)
|
3489
3991
|
if Cnvrg::CLI.is_response_success(res)
|
3490
3992
|
slug = res["result"]["notebook_url"]
|
3491
3993
|
log_message("#{Helpers.checkmark} Notebook is ready: #{Cnvrg::Helpers.remote_url}/#{project.owner}/projects/#{project.slug}/notebook_sessions/show/#{slug}", Thor::Shell::Color::GREEN)
|
@@ -5059,7 +5561,6 @@ module Cnvrg
|
|
5059
5561
|
|
5060
5562
|
def set_owner(owner, username, url)
|
5061
5563
|
home_dir = File.expand_path('~')
|
5062
|
-
|
5063
5564
|
begin
|
5064
5565
|
if !File.directory? home_dir + "/.cnvrg"
|
5065
5566
|
FileUtils.mkdir_p([home_dir + "/.cnvrg", home_dir + "/.cnvrg/tmp"])
|
@@ -5186,12 +5687,12 @@ module Cnvrg
|
|
5186
5687
|
|
5187
5688
|
def self.is_response_success(response, should_exit = true)
|
5188
5689
|
begin
|
5189
|
-
if response.nil?
|
5190
|
-
if !Cnvrg::Helpers.internet_connection?
|
5191
|
-
|
5192
|
-
|
5193
|
-
|
5194
|
-
end
|
5690
|
+
if response.nil? or !response
|
5691
|
+
# if !Cnvrg::Helpers.internet_connection?
|
5692
|
+
# say("<%= color('Error:You seems to be offline', RED) %>")
|
5693
|
+
# $LOG.error message: "offline connection", type: "error"
|
5694
|
+
#
|
5695
|
+
# end
|
5195
5696
|
if should_exit
|
5196
5697
|
exit(1)
|
5197
5698
|
else
|
@@ -5214,12 +5715,15 @@ module Cnvrg
|
|
5214
5715
|
end
|
5215
5716
|
end
|
5216
5717
|
return true
|
5217
|
-
|
5218
|
-
|
5219
|
-
|
5718
|
+
rescue => e
|
5719
|
+
puts e.message
|
5720
|
+
puts e.backtrace
|
5721
|
+
rescue SignalException
|
5722
|
+
say "Aborting"
|
5723
|
+
end
|
5724
|
+
|
5220
5725
|
end
|
5221
5726
|
|
5222
|
-
end
|
5223
5727
|
|
5224
5728
|
def self.get_owner
|
5225
5729
|
home_dir = File.expand_path('~')
|
@@ -5341,27 +5845,27 @@ module Cnvrg
|
|
5341
5845
|
|
5342
5846
|
end
|
5343
5847
|
|
5848
|
+
def verify_logged_in(in_dir=true)
|
5849
|
+
begin
|
5850
|
+
log_handler()
|
5851
|
+
auth = Cnvrg::Auth.new
|
5852
|
+
unless auth.is_logged_in?
|
5853
|
+
say 'You\'re not logged in', Thor::Shell::Color::RED
|
5854
|
+
say 'Please log in via `cnvrg login`', Thor::Shell::Color::BLUE
|
5855
|
+
exit(1)
|
5856
|
+
end
|
5344
5857
|
|
5345
|
-
|
5346
|
-
|
5347
|
-
|
5348
|
-
|
5349
|
-
|
5350
|
-
|
5351
|
-
|
5352
|
-
|
5353
|
-
|
5354
|
-
|
5355
|
-
|
5356
|
-
# if wait_offline
|
5357
|
-
# say "Waiting until your'e online..", Thor::Shell::Color::BLUE
|
5358
|
-
# while !Cnvrg::Helpers.internet_connection?
|
5359
|
-
# end
|
5360
|
-
# else
|
5361
|
-
# say "you seem to be offline, please check your internet connection", Thor::Shell::Color::RED
|
5362
|
-
# exit(0)
|
5363
|
-
# end
|
5364
|
-
# end
|
5858
|
+
# if !Helpers.internet_connection?
|
5859
|
+
# wait_offline = agree "Seems like you're offline, wait until your'e back online?", Thor::Shell::Color::YELLOW
|
5860
|
+
# if wait_offline
|
5861
|
+
# say "Waiting until your'e online..", Thor::Shell::Color::BLUE
|
5862
|
+
# while !Cnvrg::Helpers.internet_connection?
|
5863
|
+
# end
|
5864
|
+
# else
|
5865
|
+
# say "you seem to be offline, please check your internet connection", Thor::Shell::Color::RED
|
5866
|
+
# exit(0)
|
5867
|
+
# end
|
5868
|
+
# end
|
5365
5869
|
|
5366
5870
|
config = YAML.load_file(File.expand_path('~') + "/.cnvrg/config.yml")
|
5367
5871
|
version_date = config.to_h[:version_last_check]
|
@@ -5385,8 +5889,10 @@ module Cnvrg
|
|
5385
5889
|
#verify tmp dirs exist
|
5386
5890
|
home_dir = File.expand_path('~')
|
5387
5891
|
|
5388
|
-
|
5892
|
+
FileUtils.mkdir_p([home_dir+"/.cnvrg", home_dir+"/.cnvrg/tmp", home_dir+"/.cnvrg/tmp_files"])
|
5893
|
+
rescue SignalException
|
5389
5894
|
|
5895
|
+
end
|
5390
5896
|
|
5391
5897
|
end
|
5392
5898
|
|
@@ -5746,29 +6252,10 @@ module Cnvrg
|
|
5746
6252
|
|
5747
6253
|
end
|
5748
6254
|
|
5749
|
-
def with_progress_bar
|
5750
|
-
not_done = true
|
5751
|
-
upload_progress_bar = ProgressBar.create(:title => "Upload progress",
|
5752
|
-
:format => '%a <%B> %p%% %t',
|
5753
|
-
:starting_at => 0,
|
5754
|
-
:total => 600)
|
5755
|
-
pb = Thread.new do
|
5756
|
-
while not_done do
|
5757
|
-
upload_progress_bar.increment
|
5758
|
-
sleep(1)
|
5759
|
-
|
5760
|
-
end
|
5761
|
-
end
|
5762
|
-
|
5763
|
-
yield.tap do # After yielding to the block, save the return value
|
5764
|
-
not_done = false # Tell the thread to exit, cleaning up after itself…
|
5765
|
-
pb.join # …and wait for it to do so.
|
5766
|
-
end
|
5767
|
-
end
|
5768
6255
|
end
|
6256
|
+
end
|
5769
6257
|
|
5770
6258
|
|
5771
|
-
end
|
5772
6259
|
end
|
5773
6260
|
|
5774
6261
|
|