cnvrg 0.7.0 → 0.7.1
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 +3 -2
- data/lib/cnvrg/cli.rb +186 -74
- data/lib/cnvrg/colors.rb +8 -0
- data/lib/cnvrg/data.rb +19 -1
- data/lib/cnvrg/datafiles.rb +30 -1
- data/lib/cnvrg/dataset.rb +21 -4
- data/lib/cnvrg/files.rb +58 -3
- data/lib/cnvrg/project.rb +20 -8
- data/lib/cnvrg/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11c1d6358ef98bf5b6372fc3ddf3348cefd64c5a
|
4
|
+
data.tar.gz: 661547a796ec6a79cd45bb09c9621f4cfb7bace8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc98c43afdcabb9b433c8472504ef62ad3fe5a0bb2097b020c907acdba984a73debc56848a98e8d34866c3efca8f2b255370d084cc54a50b4c922ecf4e8943f5
|
7
|
+
data.tar.gz: 45aef2a6405f28cba33c69feb7202e82b3845d353fcf54283fd0b769306f861e3cb5120faa5a6e19f0db0ba8b38648d5b2ec14273e0e8cc2d839b79ab03fa1a1
|
data/lib/cnvrg/api.rb
CHANGED
@@ -79,14 +79,15 @@ module Cnvrg
|
|
79
79
|
else
|
80
80
|
response
|
81
81
|
end
|
82
|
-
when 'POST'
|
82
|
+
when 'POST', 'PUT'
|
83
83
|
conn.options.timeout = 4200
|
84
84
|
conn.options.open_timeout =4200
|
85
85
|
retries = 0
|
86
86
|
success = false
|
87
87
|
while !success and retries < 20
|
88
88
|
begin
|
89
|
-
response = conn.post "#{resource}", data
|
89
|
+
response = conn.post "#{resource}", data if method.eql? 'POST'
|
90
|
+
response = conn.put "#{resource}", data if method.eql? 'PUT'
|
90
91
|
success = true
|
91
92
|
|
92
93
|
rescue => e
|
data/lib/cnvrg/cli.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require "pty" unless !!(RUBY_PLATFORM =~ /mswin32|mingw32/)
|
3
|
-
|
4
3
|
require 'etc'
|
5
4
|
require 'parallel'
|
6
5
|
require 'netrc'
|
@@ -163,6 +162,27 @@ module Cnvrg
|
|
163
162
|
|
164
163
|
desc "", "", :hide => true
|
165
164
|
|
165
|
+
def test
|
166
|
+
# image_settings = {
|
167
|
+
# 'Image' => "cnvrg:latest",
|
168
|
+
# 'User' => 'ds',
|
169
|
+
# 'Cmd' => '/home/ds/run_ipython.sh',
|
170
|
+
# 'ExposedPorts' => {``
|
171
|
+
# '80/tcp' => {},
|
172
|
+
# },
|
173
|
+
# 'HostConfig' => {
|
174
|
+
# 'PortBindings' => {
|
175
|
+
# '80/tcp' => [
|
176
|
+
# {'HostPort' => "7654", 'HostIp' => 'localhost'}
|
177
|
+
# ],
|
178
|
+
# },
|
179
|
+
# },
|
180
|
+
# }
|
181
|
+
# container = Docker::Container.get('b4d64bf83f41')
|
182
|
+
# s = "/leah/1/2/3/4/5"
|
183
|
+
# command = ["/bin/bash","-lc","sed -i 's#c.NotebookApp.base_url = .*#c.NotebookApp.base_url = \"#{s}\"#' /home/ds/.jupyter/jupyter_notebook_config.py"]
|
184
|
+
# puts container.exec(command, tty: true)
|
185
|
+
end
|
166
186
|
|
167
187
|
|
168
188
|
desc 'version', 'Prints cnvrg current version'
|
@@ -172,6 +192,32 @@ module Cnvrg
|
|
172
192
|
|
173
193
|
end
|
174
194
|
|
195
|
+
|
196
|
+
desc 'dataurl', 'dataur', :hide => true
|
197
|
+
def set_data_url(dataset_url)
|
198
|
+
begin
|
199
|
+
verify_logged_in(true)
|
200
|
+
log_start(__method__, args, options)
|
201
|
+
unless is_cnvrg_dir
|
202
|
+
log_message("Not in cnvrg dir.", Thor::Shell::Color::RED)
|
203
|
+
end
|
204
|
+
url_parts = dataset_url.split("/")
|
205
|
+
project_index = Cnvrg::Helpers.look_for_in_path(dataset_url, "datasets")
|
206
|
+
slug = url_parts[project_index + 1]
|
207
|
+
owner = url_parts[project_index - 1]
|
208
|
+
res = Cnvrg::API.request("users/#{owner}/datasets/#{slug}", 'GET')
|
209
|
+
unless Cnvrg::CLI.is_response_success(res, false)
|
210
|
+
raise SignalException.new()
|
211
|
+
end
|
212
|
+
@dataset = Dataset.new(Dir.pwd)
|
213
|
+
result = res['result']
|
214
|
+
@dataset.change_url(result.symbolize_keys)
|
215
|
+
log_message("Changed URL Succesfuly to #{dataset_url}", Thor::Shell::Color::GREEN)
|
216
|
+
rescue => e
|
217
|
+
log_message("Cant change the url to the given dataset url", Thor::Shell::Color::RED)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
175
221
|
map %w(-v --version) => :version
|
176
222
|
|
177
223
|
desc 'api', 'set api url, e.g cnvrg --api "https://cnvrg.io/api"'
|
@@ -1099,6 +1145,59 @@ module Cnvrg
|
|
1099
1145
|
exit(1)
|
1100
1146
|
end
|
1101
1147
|
|
1148
|
+
desc '', '', :hide => true
|
1149
|
+
def data_put(dataset_url, files: [], dir: '', chunk_size: 1000)
|
1150
|
+
begin
|
1151
|
+
verify_logged_in(true)
|
1152
|
+
log_start(__method__, args, options)
|
1153
|
+
|
1154
|
+
#find owner and slug in url
|
1155
|
+
url_parts = dataset_url.split("/")
|
1156
|
+
project_index = Cnvrg::Helpers.look_for_in_path(dataset_url, "datasets")
|
1157
|
+
slug = url_parts[project_index + 1]
|
1158
|
+
owner = url_parts[project_index - 1]
|
1159
|
+
|
1160
|
+
@datafiles = Cnvrg::Datafiles.new(owner, slug)
|
1161
|
+
@dataset = Dataset.new(Dir.pwd)
|
1162
|
+
@files = @datafiles.verify_files_exists(files)
|
1163
|
+
|
1164
|
+
if @files.blank?
|
1165
|
+
raise SignalException.new(1, "Cant find files to upload, exiting.")
|
1166
|
+
end
|
1167
|
+
log_message("Uploading #{@files.size} files", Thor::Shell::Color::GREEN)
|
1168
|
+
number_of_chunks = (@files.size.to_f / chunk_size).ceil
|
1169
|
+
response = @datafiles.start_commit(false, true, chunks: number_of_chunks)
|
1170
|
+
unless response #means we failed in the start commit.
|
1171
|
+
raise SignalException.new(1, "Cant put files into server, check the dataset slug")
|
1172
|
+
end
|
1173
|
+
@commit = response['result']['commit_sha1']
|
1174
|
+
#dir shouldnt have starting or ending slash.
|
1175
|
+
dir = dir[0..-2] if dir.end_with? '/'
|
1176
|
+
dir = dir[1..-1] if dir.start_with? '/'
|
1177
|
+
|
1178
|
+
progressbar = ProgressBar.create(:title => "Upload Progress",
|
1179
|
+
:progress_mark => '=',
|
1180
|
+
:format => "%b>>%i| %p%% %t",
|
1181
|
+
:starting_at => 0,
|
1182
|
+
:total => @files.size,
|
1183
|
+
:autofinish => true)
|
1184
|
+
|
1185
|
+
@files.each_slice(chunk_size).each do |list_files|
|
1186
|
+
temp_tree = @dataset.generate_chunked_idx(list_files, prefix: dir)
|
1187
|
+
#will throw a signal exception if something goes wrong.
|
1188
|
+
@datafiles.upload_multiple_files(@commit, temp_tree, force: false, progressbar: progressbar, prefix: dir)
|
1189
|
+
end
|
1190
|
+
res = @datafiles.put_commit(@commit)
|
1191
|
+
unless res.is_success?
|
1192
|
+
raise SignalException.new(1, res.msg)
|
1193
|
+
end
|
1194
|
+
log_message("Upload finished", Thor::Shell::Color::GREEN)
|
1195
|
+
rescue SignalException => e
|
1196
|
+
log_message(e.message, Thor::Shell::Color::RED)
|
1197
|
+
return false
|
1198
|
+
end
|
1199
|
+
end
|
1200
|
+
|
1102
1201
|
|
1103
1202
|
|
1104
1203
|
|
@@ -2082,7 +2181,6 @@ module Cnvrg
|
|
2082
2181
|
method_option :parallel, :type => :numeric, :aliases => ["-p", "--parallel"], :desc => "uparallel upload at the same time", :default => 15
|
2083
2182
|
|
2084
2183
|
def upload_data_files(new_commit, *files)
|
2085
|
-
|
2086
2184
|
begin
|
2087
2185
|
verify_logged_in(true)
|
2088
2186
|
log_start(__method__, args, options)
|
@@ -2378,8 +2476,6 @@ module Cnvrg
|
|
2378
2476
|
end
|
2379
2477
|
end
|
2380
2478
|
|
2381
|
-
|
2382
|
-
|
2383
2479
|
if ignore.nil? or ignore.empty?
|
2384
2480
|
ignore = ignore_list
|
2385
2481
|
end
|
@@ -2394,7 +2490,7 @@ module Cnvrg
|
|
2394
2490
|
if !@project.update_ignore_list(ignore)
|
2395
2491
|
log_message("Couldn't append new ignore files to .cnvrgignore", Thor::Shell::Color::YELLOW)
|
2396
2492
|
end
|
2397
|
-
new_branch = options["new_branch"] ||
|
2493
|
+
new_branch = options["new_branch"] || @project.is_branch
|
2398
2494
|
|
2399
2495
|
result = @project.compare_idx(new_branch, force: force, deploy: options["deploy"],in_exp:in_exp, specific_files: spec_files_to_upload)
|
2400
2496
|
commit = result["result"]["commit"]
|
@@ -2408,8 +2504,6 @@ module Cnvrg
|
|
2408
2504
|
log_message("Comparing local changes with remote version:", Thor::Shell::Color::BLUE, (options["verbose"]))
|
2409
2505
|
end
|
2410
2506
|
result = result["result"]["tree"]
|
2411
|
-
|
2412
|
-
|
2413
2507
|
if result["added"].empty? and result["updated_on_local"].empty? and result["deleted"].empty?
|
2414
2508
|
log_message("#{check} Project is up to date", Thor::Shell::Color::GREEN, (((options["sync"] or sync) and !direct) ? false : true))
|
2415
2509
|
return true
|
@@ -2428,18 +2522,19 @@ module Cnvrg
|
|
2428
2522
|
log_message("Syncing files", Thor::Shell::Color::BLUE, ((options["sync"] or sync)) ? false : true)
|
2429
2523
|
end
|
2430
2524
|
# Start commit
|
2525
|
+
current_commit = nil
|
2526
|
+
exp_start_commit = nil
|
2431
2527
|
if in_exp || (job_slug.present? and job_type.present?)
|
2432
2528
|
exp_start_commit = @project.last_local_commit
|
2433
2529
|
else
|
2434
|
-
|
2530
|
+
current_commit = @project.last_local_commit
|
2435
2531
|
end
|
2436
2532
|
job_type = options['job_type'] || job_type
|
2437
2533
|
job_slug = options['job_slug'] || job_slug
|
2438
2534
|
commit_sha1 = @files.start_commit(new_branch, force: force, exp_start_commit:exp_start_commit,
|
2439
|
-
job_type: job_type, job_slug: job_slug)["result"]["commit_sha1"]
|
2535
|
+
job_type: job_type, job_slug: job_slug, start_commit: current_commit)["result"]["commit_sha1"]
|
2440
2536
|
# upload / update
|
2441
2537
|
begin
|
2442
|
-
|
2443
2538
|
parallel_options = {
|
2444
2539
|
:progress => {
|
2445
2540
|
:title => "Upload Progress",
|
@@ -2869,7 +2964,7 @@ module Cnvrg
|
|
2869
2964
|
if !@project.update_ignore_list(ignore)
|
2870
2965
|
log_message("Couldn't append new ignore files to .cnvrgignore", Thor::Shell::Color::YELLOW)
|
2871
2966
|
end
|
2872
|
-
new_branch = options["new_branch"] || false
|
2967
|
+
new_branch = options["new_branch"] || @project.is_branch || false
|
2873
2968
|
res = @project.compare_idx(new_branch, commit: nil, in_exp: in_exp)["result"]
|
2874
2969
|
result = res["tree"]
|
2875
2970
|
|
@@ -3046,82 +3141,82 @@ module Cnvrg
|
|
3046
3141
|
|
3047
3142
|
|
3048
3143
|
desc 'jump', 'jump to specific commit'
|
3049
|
-
method_option :remote, :type => :boolean, :aliases => ["-r", "--r"], :default => false
|
3050
3144
|
def jump(commit_sha1)
|
3051
3145
|
begin
|
3052
3146
|
verify_logged_in()
|
3053
3147
|
log_start(__method__, args, options)
|
3054
|
-
is_remote = options["remote"]
|
3055
3148
|
project_home = get_project_home
|
3056
3149
|
@project = Project.new(project_home)
|
3057
|
-
# say "Syncing existing project tree before jumping", Thor::Shell::Color::BLUE
|
3058
3150
|
current_commit = @project.last_local_commit
|
3059
3151
|
if current_commit.eql? commit_sha1
|
3060
3152
|
log_message("Project is already updated", Thor::Shell::Color::GREEN)
|
3061
3153
|
exit(0)
|
3062
3154
|
end
|
3063
|
-
@files = Cnvrg::Files.new(@project.owner, @project.slug)
|
3064
|
-
|
3065
|
-
|
3066
|
-
|
3067
|
-
|
3068
|
-
|
3069
|
-
if !response["result"]["tree"].nil?
|
3070
|
-
parallel_options = {
|
3071
|
-
:progress => {
|
3072
|
-
:title => "Jump Progress",
|
3073
|
-
:progress_mark => '=',
|
3074
|
-
:format => "%b>>%i| %p%% %t",
|
3075
|
-
:starting_at => 0,
|
3076
|
-
:total => response["result"]["tree"].size,
|
3077
|
-
:autofinish => true
|
3078
|
-
},
|
3079
|
-
in_processes: ParallelProcesses,
|
3080
|
-
in_thread: ParallelThreads
|
3081
|
-
}
|
3082
|
-
commit_sha1 = response["result"]["commit"]
|
3083
|
-
idx = {commit: response["result"]["commit"], tree: response["result"]["tree"]}
|
3084
|
-
File.open(project_home + "/.cnvrg/idx.yml", "w+") {|f| f.write idx.to_yaml}
|
3085
|
-
if is_remote
|
3086
|
-
current_tree = Dir.glob("**/*", File::FNM_DOTMATCH).flatten.reject {|file| file.start_with? '.' or file.eql? "__init__.py" or file.eql? "uwsgi.ini" or file.ends_with? "/." or file.eql? "."}
|
3087
|
-
else
|
3088
|
-
current_tree = Dir.glob("**/*", File::FNM_DOTMATCH).flatten.reject {|file| file.start_with? '.cnvrg' or file.ends_with? "/." or file.eql? "."}
|
3089
|
-
end
|
3090
|
-
|
3091
|
-
jump_result = Parallel.map(response["result"]["tree"], parallel_options) do |f|
|
3092
|
-
|
3093
|
-
relative_path = f[0].gsub(/^#{@project.local_path}/, "")
|
3094
|
-
log_message("Downloading #{f[0]}", Thor::Shell::Color::BLUE, false)
|
3095
|
-
if f[0].end_with? "/"
|
3096
|
-
# dir
|
3097
|
-
@files.download_dir(f[0], relative_path, project_home)
|
3098
|
-
|
3099
|
-
else
|
3100
|
-
# blob
|
3101
|
-
@files.download_file_s3(f[0], relative_path, project_home, commit_sha1 = commit_sha1)
|
3102
|
-
end
|
3103
|
-
end
|
3104
|
-
|
3105
|
-
|
3106
|
-
successful_changes = jump_result.select {|x| not x.nil?}
|
3107
|
-
end
|
3108
|
-
response["result"]["tree"].each do |f|
|
3109
|
-
if f[0].end_with? "/"
|
3110
|
-
current_tree.delete(f[0][0, f[0].size - 1])
|
3111
|
-
else
|
3112
|
-
current_tree.delete(f[0])
|
3113
|
-
end
|
3155
|
+
@files = Cnvrg::Files.new(@project.owner, @project.slug, project_home: project_home)
|
3156
|
+
resp = @project.jump_idx(destination: commit_sha1)
|
3157
|
+
if resp.blank?
|
3158
|
+
log_message("Cant find the given commit", Thor::Shell::Color::RED)
|
3159
|
+
exit(0)
|
3114
3160
|
end
|
3115
|
-
|
3116
|
-
|
3117
|
-
|
3161
|
+
compare = resp['result']['compare']
|
3162
|
+
resolver = resp['result']['resolver']
|
3163
|
+
latest = resp['result']['latest']
|
3164
|
+
commit = resp['result']['commit']
|
3165
|
+
@files.handle_compare_idx(compare, resolver: resolver)
|
3166
|
+
@project.set_on_branch(latest)
|
3167
|
+
@project.update_idx_with_commit!(commit)
|
3168
|
+
@project.generate_idx
|
3169
|
+
log_message("Jumped successfuly!", Thor::Shell::Color::GREEN)
|
3118
3170
|
rescue => e
|
3119
|
-
log_message("
|
3120
|
-
|
3121
|
-
|
3122
|
-
|
3123
|
-
|
3124
|
-
|
3171
|
+
log_message("Cant jump to the specified commit", Thor::Shell::Color::RED)
|
3172
|
+
end
|
3173
|
+
# successful_changes = []
|
3174
|
+
#
|
3175
|
+
# if !response["result"]["tree"].nil?
|
3176
|
+
|
3177
|
+
# commit_sha1 = response["result"]["commit"]
|
3178
|
+
# idx = {commit: response["result"]["commit"], tree: response["result"]["tree"]}
|
3179
|
+
# File.open(project_home + "/.cnvrg/idx.yml", "w+") {|f| f.write idx.to_yaml}
|
3180
|
+
# if is_remote
|
3181
|
+
# current_tree = Dir.glob("**/*", File::FNM_DOTMATCH).flatten.reject {|file| file.start_with? '.' or file.eql? "__init__.py" or file.eql? "uwsgi.ini" or file.ends_with? "/." or file.eql? "."}
|
3182
|
+
# else
|
3183
|
+
# current_tree = Dir.glob("**/*", File::FNM_DOTMATCH).flatten.reject {|file| file.start_with? '.cnvrg' or file.ends_with? "/." or file.eql? "."}
|
3184
|
+
# end
|
3185
|
+
#
|
3186
|
+
# jump_result = Parallel.map(response["result"]["tree"], parallel_options) do |f|
|
3187
|
+
#
|
3188
|
+
# relative_path = f[0].gsub(/^#{@project.local_path}/, "")
|
3189
|
+
# log_message("Downloading #{f[0]}", Thor::Shell::Color::BLUE, false)
|
3190
|
+
# if f[0].end_with? "/"
|
3191
|
+
# # dir
|
3192
|
+
# @files.download_dir(f[0], relative_path, project_home)
|
3193
|
+
#
|
3194
|
+
# else
|
3195
|
+
# # blob
|
3196
|
+
# @files.download_file_s3(f[0], relative_path, project_home, commit_sha1 = commit_sha1)
|
3197
|
+
# end
|
3198
|
+
# end
|
3199
|
+
#
|
3200
|
+
#
|
3201
|
+
# successful_changes = jump_result.select {|x| not x.nil?}
|
3202
|
+
# end
|
3203
|
+
# response["result"]["tree"].each do |f|
|
3204
|
+
# if f[0].end_with? "/"
|
3205
|
+
# current_tree.delete(f[0][0, f[0].size - 1])
|
3206
|
+
# else
|
3207
|
+
# current_tree.delete(f[0])
|
3208
|
+
# end
|
3209
|
+
# end
|
3210
|
+
#
|
3211
|
+
# FileUtils.rm_rf(current_tree)
|
3212
|
+
# log_message("Done. Jumped to #{commit_sha1} completed successfully", Thor::Shell::Color::GREEN)
|
3213
|
+
# rescue => e
|
3214
|
+
# log_message("Error occurred, Aborting", Thor::Shell::Color::RED)
|
3215
|
+
# log_error(e)
|
3216
|
+
# rescue SignalException
|
3217
|
+
#
|
3218
|
+
# exit(1)
|
3219
|
+
# end
|
3125
3220
|
end
|
3126
3221
|
|
3127
3222
|
desc 'show', 'Show specific file from a specific commit'
|
@@ -3820,6 +3915,7 @@ module Cnvrg
|
|
3820
3915
|
if forced_commit and (commit_to_run.nil? or commit_to_run.empty?)
|
3821
3916
|
commit_to_run = forced_commit
|
3822
3917
|
end
|
3918
|
+
commit_to_run = commit_to_run.presence || project.last_local_commit
|
3823
3919
|
res = exp.exec_remote(command, commit_to_run, instance_type, image_slug, schedule, local_timestamp, grid, path_to_cmd, data, data_commit,
|
3824
3920
|
periodic_sync, sync_before_terminate, max_time, ds_sync_options,output_dir,
|
3825
3921
|
data_query, git_commit, git_branch, restart_if_stuck,local_folders_options )
|
@@ -5780,6 +5876,22 @@ module Cnvrg
|
|
5780
5876
|
end
|
5781
5877
|
end
|
5782
5878
|
|
5879
|
+
def self.log_message(message, type = Thor::Shell::Color::BLUE, to_print: true)
|
5880
|
+
say "#{type}#{message}" if to_print
|
5881
|
+
case type
|
5882
|
+
when Thor::Shell::Color::BLUE
|
5883
|
+
$LOG.info message: message, type: "info"
|
5884
|
+
when Thor::Shell::Color::RED
|
5885
|
+
$LOG.error message: message, type: "error"
|
5886
|
+
when Thor::Shell::Color::YELLOW
|
5887
|
+
$LOG.warn message: message, type: "warning"
|
5888
|
+
when Thor::Shell::Color::GREEN
|
5889
|
+
$LOG.info message: message, type: "success"
|
5890
|
+
else
|
5891
|
+
$LOG.info message: message, type: "unknown"
|
5892
|
+
end
|
5893
|
+
end
|
5894
|
+
|
5783
5895
|
def log_message(message, type, to_print = true)
|
5784
5896
|
if to_print
|
5785
5897
|
say message, type
|
data/lib/cnvrg/colors.rb
ADDED
data/lib/cnvrg/data.rb
CHANGED
@@ -77,7 +77,6 @@ module Cnvrg
|
|
77
77
|
commit = options["commit"]
|
78
78
|
all_files = options["all_files"]
|
79
79
|
cli.download_data_new(verbose,sync,new_branch, commit,all_files)
|
80
|
-
|
81
80
|
end
|
82
81
|
desc 'data clone', 'clone datset'
|
83
82
|
method_option :only_tree, :type => :boolean, :aliases => ["-t", "--tree"], :default => false
|
@@ -92,6 +91,25 @@ module Cnvrg
|
|
92
91
|
cli.clone_data(dataset_url, only_tree=only_tree,commit=commit, query=query)
|
93
92
|
end
|
94
93
|
|
94
|
+
desc 'data set --url=dataset_url', 'Set dataset url to other url'
|
95
|
+
method_option :url, :type => :string, :aliases => ["--url"], :default => ''
|
96
|
+
def set
|
97
|
+
cli = Cnvrg::CLI.new
|
98
|
+
cli.log_start(__method__)
|
99
|
+
cli.log_handler
|
100
|
+
if options['url'].present?
|
101
|
+
cli.set_data_url(options['url'])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
desc 'date put dataset_url', 'clone datset'
|
106
|
+
method_option :dir, :type => :string, :aliases => ["-d", "--dir"], :default => ''
|
107
|
+
def put(dataset_url, *files)
|
108
|
+
cli = Cnvrg::CLI.new()
|
109
|
+
dir = options[:dir]
|
110
|
+
cli.data_put(dataset_url, files: files, dir: dir)
|
111
|
+
end
|
112
|
+
|
95
113
|
desc 'data clone_query', 'clone query datset'
|
96
114
|
method_option :query, :type => :string, :aliases => ["-q", "--query"], :default => nil
|
97
115
|
def clone_query(dataset_url)
|
data/lib/cnvrg/datafiles.rb
CHANGED
@@ -28,6 +28,22 @@ module Cnvrg
|
|
28
28
|
return 1
|
29
29
|
end
|
30
30
|
|
31
|
+
def verify_files_exists(files)
|
32
|
+
paths = []
|
33
|
+
files.each do |file|
|
34
|
+
if File.exists? file
|
35
|
+
if File.directory? file
|
36
|
+
paths += Dir.glob("#{file}/**/*")
|
37
|
+
else
|
38
|
+
paths << file
|
39
|
+
end
|
40
|
+
next
|
41
|
+
end
|
42
|
+
raise SignalException.new(1, "Cant find file #{file}") unless File.exists? "#{Dir.pwd}/#{file}"
|
43
|
+
end
|
44
|
+
paths
|
45
|
+
end
|
46
|
+
|
31
47
|
def check_files_sha1(files, resolver, tag)
|
32
48
|
conflicts = 0
|
33
49
|
files.each do |file|
|
@@ -53,7 +69,19 @@ module Cnvrg
|
|
53
69
|
end
|
54
70
|
|
55
71
|
|
56
|
-
def
|
72
|
+
def put_commit(commit_sha1)
|
73
|
+
response = Cnvrg::API.request("#{@base_resource}/commit/latest", 'PUT', {commit_sha1: commit_sha1})
|
74
|
+
if response.present?
|
75
|
+
msg = response['result']
|
76
|
+
else
|
77
|
+
msg = "Cant save changes in the dataset"
|
78
|
+
end
|
79
|
+
|
80
|
+
Cnvrg::Result.new(Cnvrg::CLI.is_response_success(response, false), msg)
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
def upload_multiple_files(commit_sha1, tree, threads: ParallelThreads, force: false, new_branch: false, progressbar: nil, prefix: '')
|
57
85
|
random_file_name = (0...8).map { (65 + rand(26)).chr }.join #needed to create a file for post_file..
|
58
86
|
# each file have: {sha1: sha1, file_name: file_name, file_size: file_size, content_type: content_type, absolute_path, relative_path}
|
59
87
|
|
@@ -63,6 +91,7 @@ module Cnvrg
|
|
63
91
|
return Cnvrg::Result.new(false, "Failed to upload files") unless Cnvrg::CLI.is_response_success(upload_resp, false)
|
64
92
|
results = upload_resp['result'].with_indifferent_access
|
65
93
|
if results['files'].blank?
|
94
|
+
progressbar.progress += tree.keys.length if progressbar.present?
|
66
95
|
return 0
|
67
96
|
end
|
68
97
|
props = Cnvrg::Helpers.get_s3_props(results)
|
data/lib/cnvrg/dataset.rb
CHANGED
@@ -9,17 +9,22 @@ module Cnvrg
|
|
9
9
|
|
10
10
|
def initialize(project_home)
|
11
11
|
begin
|
12
|
-
config = YAML.load_file(project_home+"/.cnvrg/config.yml")
|
13
12
|
@local_path = project_home
|
13
|
+
@working_dir = project_home
|
14
|
+
config = YAML.load_file(project_home+"/.cnvrg/config.yml")
|
14
15
|
@title = config[:dataset_name]
|
15
16
|
@slug = config[:dataset_slug]
|
16
17
|
@owner = config[:owner]
|
17
|
-
@working_dir = project_home
|
18
18
|
rescue => e
|
19
19
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
def change_url(owner: '', slug: '', title: '')
|
24
|
+
config = {dataset_home: title, dataset_slug: slug, owner: owner}
|
25
|
+
File.open(".cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
|
26
|
+
end
|
27
|
+
|
23
28
|
|
24
29
|
def self.delete(dataset_slug,owner)
|
25
30
|
response = Cnvrg::API.request("users/#{owner}/datasets/#{dataset_slug}/delete", 'DELETE')
|
@@ -295,10 +300,12 @@ module Cnvrg
|
|
295
300
|
url = Cnvrg::Helpers.remote_url
|
296
301
|
"#{url}/#{self.owner}/datasets/#{self.slug}"
|
297
302
|
end
|
298
|
-
def generate_chunked_idx(list_files=[], threads: IDXParallelThreads)
|
303
|
+
def generate_chunked_idx(list_files=[], threads: IDXParallelThreads, prefix: '')
|
299
304
|
tree = {}
|
300
|
-
Parallel.map(list_files, in_threads:
|
305
|
+
Parallel.map(list_files, in_threads: threads) do |file|
|
306
|
+
#check if prefix exists do prefix/path otherwise path
|
301
307
|
label = file.gsub(self.local_path + "/", "")
|
308
|
+
label = "#{prefix}/#{label}" if prefix.present?
|
302
309
|
if File.directory? file
|
303
310
|
tree[label+"/"] = nil
|
304
311
|
else
|
@@ -308,9 +315,19 @@ module Cnvrg
|
|
308
315
|
mime_type = MimeMagic.by_path(file)
|
309
316
|
content_type = !(mime_type.nil? or mime_type.text?) ? mime_type.type : "text/plain"
|
310
317
|
relative_path = file.gsub(/^#{@local_path + "/"}/, "")
|
318
|
+
relative_path = "#{prefix}/#{relative_path}" if prefix.present?
|
311
319
|
tree[label] = {sha1: sha1, file_name: file_name, file_size: file_size, content_type: content_type, absolute_path: file, relative_path: relative_path}
|
312
320
|
end
|
313
321
|
end
|
322
|
+
if prefix.present? #add the prefix as dirs to the files
|
323
|
+
#lets say the prefix is a/b/c so we want that a/, a/b/, a/b/c/ will be in our files_list
|
324
|
+
dirs = prefix.split('/')
|
325
|
+
curr_path = []
|
326
|
+
dirs.each do |dir|
|
327
|
+
curr_path << dir
|
328
|
+
list_files << curr_path.join('/')
|
329
|
+
end
|
330
|
+
end
|
314
331
|
return tree
|
315
332
|
end
|
316
333
|
|
data/lib/cnvrg/files.rb
CHANGED
@@ -12,10 +12,11 @@ module Cnvrg
|
|
12
12
|
|
13
13
|
attr_reader :base_resource
|
14
14
|
|
15
|
-
def initialize(owner, project_slug)
|
15
|
+
def initialize(owner, project_slug, project_home: '')
|
16
16
|
@project_slug = project_slug
|
17
17
|
@owner = owner
|
18
18
|
@base_resource = "users/#{owner}/projects/#{project_slug}/"
|
19
|
+
@project_home = project_home
|
19
20
|
end
|
20
21
|
|
21
22
|
def upload_file(absolute_path, relative_path, commit_sha1)
|
@@ -657,9 +658,9 @@ module Cnvrg
|
|
657
658
|
return true
|
658
659
|
|
659
660
|
end
|
660
|
-
def start_commit(new_branch,force:false, exp_start_commit:nil, job_slug: nil, job_type: nil)
|
661
|
+
def start_commit(new_branch,force:false, exp_start_commit:nil, job_slug: nil, job_type: nil, start_commit: nil)
|
661
662
|
response = Cnvrg::API.request("#{base_resource}/commit/start", 'POST', {project_slug: @project_slug, new_branch: new_branch,force:force,
|
662
|
-
username: @owner, exp_start_commit:exp_start_commit, job_slug: job_slug, job_type: job_type})
|
663
|
+
username: @owner, exp_start_commit:exp_start_commit, job_slug: job_slug, job_type: job_type, start_commit: start_commit})
|
663
664
|
Cnvrg::CLI.is_response_success(response,false)
|
664
665
|
return response
|
665
666
|
end
|
@@ -669,6 +670,60 @@ module Cnvrg
|
|
669
670
|
return response
|
670
671
|
end
|
671
672
|
|
673
|
+
def download_file(file_path: '', key: '', iv: '', bucket: '', path: '', client: nil)
|
674
|
+
file_key = Cnvrg::Helpers.decrypt(key,iv, path)
|
675
|
+
resp = false
|
676
|
+
File.open(@project_home+"/"+file_path, 'w+') do |file|
|
677
|
+
resp = client.get_object({bucket:bucket,
|
678
|
+
key:file_key}, target: file)
|
679
|
+
end
|
680
|
+
end
|
681
|
+
|
682
|
+
def delete(file)
|
683
|
+
FileUtils.rm_rf(file)
|
684
|
+
end
|
685
|
+
|
686
|
+
def handle_compare_idx(compared, resolver: {})
|
687
|
+
begin
|
688
|
+
all_files = compared.values.flatten.uniq
|
689
|
+
props = Cnvrg::Helpers.get_s3_props(resolver)
|
690
|
+
files = resolver['keys'].map{|f| [f['name'], f]}.to_h
|
691
|
+
client = props[:client]
|
692
|
+
iv = props[:iv]
|
693
|
+
key = props[:key]
|
694
|
+
bucket = props[:bucket]
|
695
|
+
parallel_options = {
|
696
|
+
:progress => {
|
697
|
+
:title => "Jump Progress",
|
698
|
+
:progress_mark => '=',
|
699
|
+
:format => "%b>>%i| %p%% %t",
|
700
|
+
:starting_at => 0,
|
701
|
+
:total => all_files.size,
|
702
|
+
:autofinish => true
|
703
|
+
},
|
704
|
+
in_processes: Cnvrg::CLI::ParallelProcesses,
|
705
|
+
in_thread: Cnvrg::CLI::ParallelThreads
|
706
|
+
}
|
707
|
+
Parallel.map(all_files, parallel_options) do |file|
|
708
|
+
Cnvrg::CLI.log_message("Trying #{file}")
|
709
|
+
if compared['conflicts'].include? file
|
710
|
+
self.download_file(file_path: "#{file}.conflict", key: key, iv: iv, bucket: bucket, path: files[file]['path'], client: client)
|
711
|
+
next
|
712
|
+
end
|
713
|
+
if compared['updated_on_server'].include? file or compared['added'].include? file
|
714
|
+
self.download_file(file_path: file, key: key, iv: iv, bucket: bucket, path: files[file]['path'], client: client)
|
715
|
+
next
|
716
|
+
end
|
717
|
+
if compared['deleted'].include? file
|
718
|
+
self.delete(file)
|
719
|
+
next
|
720
|
+
end
|
721
|
+
Cnvrg::CLI.log_message("Failed #{file}")
|
722
|
+
end
|
723
|
+
rescue => e
|
724
|
+
raise Exception.new("Cant upload files")
|
725
|
+
end
|
726
|
+
end
|
672
727
|
def rollback_commit(commit_sha1)
|
673
728
|
response = Cnvrg::API.request("#{base_resource}/commit/rollback", 'POST', {commit_sha1: commit_sha1})
|
674
729
|
Cnvrg::CLI.is_response_success(response, false)
|
data/lib/cnvrg/project.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
module Cnvrg
|
3
3
|
class Project
|
4
|
-
attr_reader :slug, :owner, :title, :local_path, :working_dir, :is_git
|
4
|
+
attr_reader :slug, :owner, :title, :local_path, :working_dir, :is_git, :is_branch
|
5
5
|
|
6
6
|
RemoteURL ||= "https://cnvrg.io"
|
7
7
|
IDXParallelThreads ||= 15
|
@@ -15,10 +15,10 @@ module Cnvrg
|
|
15
15
|
@title = config[:project_name]
|
16
16
|
@slug = config[:project_slug]
|
17
17
|
@owner = config[:owner]
|
18
|
+
@is_branch = config[:is_branch]
|
18
19
|
@is_git = config[:git] || false
|
19
20
|
rescue => e
|
20
21
|
end
|
21
|
-
|
22
22
|
end
|
23
23
|
|
24
24
|
|
@@ -423,14 +423,26 @@ module Cnvrg
|
|
423
423
|
CLI.is_response_success(response,true)
|
424
424
|
return response
|
425
425
|
end
|
426
|
-
def jump_idx(
|
427
|
-
|
426
|
+
def jump_idx(destination: self.last_local_commit)
|
428
427
|
local_idx = self.generate_idx
|
429
|
-
ignore_list = self.send_ignore_list
|
430
|
-
|
431
|
-
|
428
|
+
ignore_list = self.send_ignore_list
|
429
|
+
current_commit = local_idx[:commit]
|
430
|
+
tree = local_idx[:tree]
|
431
|
+
response = Cnvrg::API.request("users/#{self.owner}/projects/#{self.slug}/jump_to",
|
432
|
+
'POST',
|
433
|
+
{tree: tree, ignore: ignore_list,
|
434
|
+
dest_commit: destination, current_commit: current_commit})
|
432
435
|
CLI.is_response_success(response,false)
|
433
|
-
|
436
|
+
response
|
437
|
+
end
|
438
|
+
|
439
|
+
def set_on_branch(is_latest)
|
440
|
+
config = YAML.load_file(@working_dir+"/.cnvrg/config.yml")
|
441
|
+
@is_branch = !is_latest
|
442
|
+
config[:is_branch] = @is_branch
|
443
|
+
|
444
|
+
File.open(@working_dir+"/.cnvrg/config.yml", 'w') { |f| f.write config.to_yaml }
|
445
|
+
|
434
446
|
end
|
435
447
|
|
436
448
|
def compare_commit(commit)
|
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.7.
|
4
|
+
version: 0.7.1
|
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-09-
|
12
|
+
date: 2018-09-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -400,6 +400,7 @@ files:
|
|
400
400
|
- lib/cnvrg/api.rb
|
401
401
|
- lib/cnvrg/auth.rb
|
402
402
|
- lib/cnvrg/cli.rb
|
403
|
+
- lib/cnvrg/colors.rb
|
403
404
|
- lib/cnvrg/data.rb
|
404
405
|
- lib/cnvrg/datafiles.rb
|
405
406
|
- lib/cnvrg/dataset.rb
|