cnvrg 0.0.147 → 0.0.148
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/cli.rb +27 -9
- data/lib/cnvrg/dataset.rb +6 -0
- data/lib/cnvrg/files.rb +65 -12
- data/lib/cnvrg/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9889a94a7cbc7cf8e729daf363e61bd38072960a
|
4
|
+
data.tar.gz: e46f0fed0b9b6a3007daa399dc4e75b81d402aa6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bc2c1dca91ad6f2ff9e4248b95b34231bef97be4eb9d7ba52b5cd73c9def6ee36ad672beaf45c8581e868d0b89fc7d8cf6e6f6babfd35ed6f5feb5bf610c222
|
7
|
+
data.tar.gz: 02d1c07bec47cada6285f3df813b6fc67b0c3f2700df70bc89be691e72f20593da9672ce2fa03430dc2d548e5ba9ac930a7f3d2711b2a36e6fe32f022367e589
|
data/lib/cnvrg/cli.rb
CHANGED
@@ -70,11 +70,11 @@ module Cnvrg
|
|
70
70
|
# },
|
71
71
|
# },
|
72
72
|
# }
|
73
|
-
container = Docker::Container.get('b4d64bf83f41')
|
74
|
-
s = "/leah/1/2/3/4/5"
|
75
|
-
command = ["/bin/bash","-lc","sed -i 's#c.NotebookApp.base_url = .*#c.NotebookApp.base_url = \"#{s}\"#' /home/ds/.jupyter/jupyter_notebook_config.py"]
|
76
|
-
puts container.exec(command, tty: true)
|
77
|
-
|
73
|
+
# container = Docker::Container.get('b4d64bf83f41')
|
74
|
+
# s = "/leah/1/2/3/4/5"
|
75
|
+
# command = ["/bin/bash","-lc","sed -i 's#c.NotebookApp.base_url = .*#c.NotebookApp.base_url = \"#{s}\"#' /home/ds/.jupyter/jupyter_notebook_config.py"]
|
76
|
+
# puts container.exec(command, tty: true)
|
77
|
+
puts File.read("s4cmd.py")
|
78
78
|
end
|
79
79
|
|
80
80
|
|
@@ -815,9 +815,11 @@ module Cnvrg
|
|
815
815
|
end
|
816
816
|
|
817
817
|
end
|
818
|
-
|
818
|
+
|
819
|
+
|
820
|
+
desc 'unlink','Unlink a project from current directory', :hide=>true
|
819
821
|
def create_volume
|
820
|
-
verify_logged_in(
|
822
|
+
verify_logged_in(false)
|
821
823
|
log_start(__method__, args, options)
|
822
824
|
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
823
825
|
@dataset = Dataset.new(dataset_dir)
|
@@ -825,6 +827,20 @@ module Cnvrg
|
|
825
827
|
|
826
828
|
end
|
827
829
|
|
830
|
+
desc 'list data','Unlink a project from current directory', :hide=>true
|
831
|
+
def list_data
|
832
|
+
verify_logged_in(true)
|
833
|
+
log_start(__method__, args, options)
|
834
|
+
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
835
|
+
@dataset = Dataset.new(dataset_dir)
|
836
|
+
result = @dataset.list()
|
837
|
+
list = result["result"]["list"]
|
838
|
+
|
839
|
+
print_table(list)
|
840
|
+
|
841
|
+
end
|
842
|
+
|
843
|
+
|
828
844
|
desc 'unlink','Unlink a project from current directory'
|
829
845
|
def unlink
|
830
846
|
verify_logged_in(false)
|
@@ -1083,7 +1099,6 @@ module Cnvrg
|
|
1083
1099
|
#
|
1084
1100
|
# end
|
1085
1101
|
check = Helpers.checkmark()
|
1086
|
-
|
1087
1102
|
if result["added"].empty? and result["updated_on_local"].empty? and result["deleted"].empty?
|
1088
1103
|
log_end(0)
|
1089
1104
|
say "#{check} Project is up to date", Thor::Shell::Color::GREEN unless ((options["sync"] or sync) and !direct)
|
@@ -3056,6 +3071,7 @@ module Cnvrg
|
|
3056
3071
|
method_option :login, :type => :string, :aliases => ["-l", "--l"], :default => ""
|
3057
3072
|
method_option :app_dir, :type => :string, :aliases => ["-d", "--d"], :default => "/home/ds/notebooks"
|
3058
3073
|
method_option :cmd, :type => :string, :aliases => ["-c", "--c"], :default => "/usr/local/cnvrg/run_ipython.sh"
|
3074
|
+
method_option :volume, :type => :string, :aliases => ["-v", "--v"], :default => "/home/ds/notebooks/data"
|
3059
3075
|
|
3060
3076
|
|
3061
3077
|
def config_remote(image_name, port=7654,tensport=6006)
|
@@ -3071,15 +3087,17 @@ module Cnvrg
|
|
3071
3087
|
login_content = options["login"]
|
3072
3088
|
app_dir = options["app_dir"]
|
3073
3089
|
cmd= options["cmd"]
|
3090
|
+
volume_from = options["volume"]
|
3074
3091
|
|
3075
3092
|
image_settings = {
|
3076
3093
|
'Image' => "#{image_name}:latest",
|
3077
|
-
|
3094
|
+
|
3078
3095
|
'Cmd' => cmd,
|
3079
3096
|
'WorkingDir' => app_dir,
|
3080
3097
|
'ExposedPorts' => {
|
3081
3098
|
'8888/tcp' => {},
|
3082
3099
|
},
|
3100
|
+
'VolumesFrom' =>volume_from,
|
3083
3101
|
'HostConfig' => {
|
3084
3102
|
'PortBindings' => {
|
3085
3103
|
'8888/tcp' => [
|
data/lib/cnvrg/dataset.rb
CHANGED
@@ -30,6 +30,12 @@ module Cnvrg
|
|
30
30
|
CLI.is_response_success(response)
|
31
31
|
return response
|
32
32
|
|
33
|
+
end
|
34
|
+
def list
|
35
|
+
response = Cnvrg::API.request("users/#{self.owner}/datasets/list", 'GET')
|
36
|
+
CLI.is_response_success(response)
|
37
|
+
return response
|
38
|
+
|
33
39
|
end
|
34
40
|
def url
|
35
41
|
url = Cnvrg::Helpers.remote_url
|
data/lib/cnvrg/files.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
require 'mimemagic'
|
2
2
|
require 'aws-sdk'
|
3
3
|
require 'URLcrypt'
|
4
|
+
require 'tempfile'
|
4
5
|
|
5
6
|
module Cnvrg
|
6
7
|
class Files
|
7
8
|
|
8
9
|
LARGE_FILE=1024*1024*5
|
10
|
+
MULTIPART_SPLIT=10000000
|
11
|
+
|
9
12
|
attr_reader :base_resource
|
10
13
|
|
11
14
|
def initialize(owner, project_slug)
|
@@ -19,9 +22,11 @@ module Cnvrg
|
|
19
22
|
file_size = File.size(absolute_path).to_f
|
20
23
|
mime_type = MimeMagic.by_path(absolute_path)
|
21
24
|
content_type = !(mime_type.nil? or mime_type.text?) ? mime_type.type : "text/plain"
|
25
|
+
sha1 = Digest::SHA1.file(absolute_path).hexdigest
|
26
|
+
|
22
27
|
upload_resp = Cnvrg::API.request(@base_resource + "upload_file", 'POST_FILE', {absolute_path: absolute_path, relative_path: relative_path,
|
23
28
|
commit_sha1: commit_sha1, file_name: file_name,
|
24
|
-
file_size: file_size, file_content_type: content_type})
|
29
|
+
file_size: file_size, file_content_type: content_type, sha1:sha1})
|
25
30
|
if Cnvrg::CLI.is_response_success(upload_resp, false)
|
26
31
|
path = upload_resp["result"]["path"]
|
27
32
|
if file_size.to_f>= Cnvrg::Files::LARGE_FILE.to_f
|
@@ -29,11 +34,13 @@ module Cnvrg
|
|
29
34
|
else
|
30
35
|
s3_res = upload_small_files_s3(path, absolute_path, content_type)
|
31
36
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
+
return s3_res
|
38
|
+
# if s3_res
|
39
|
+
# update_s3_resp = Cnvrg::API.request(@base_resource + "update_s3", 'POST', {path: path, commit_id: upload_resp["result"]["commit_id"],
|
40
|
+
# blob_id: upload_resp["result"]["id"]})
|
41
|
+
# is_suc = Cnvrg::CLI.is_response_success(update_s3_resp, false)
|
42
|
+
#
|
43
|
+
# return is_suc
|
37
44
|
end
|
38
45
|
return false
|
39
46
|
end
|
@@ -199,9 +206,11 @@ module Cnvrg
|
|
199
206
|
|
200
207
|
end
|
201
208
|
|
202
|
-
def
|
209
|
+
def upload_large_files_s3(upload_resp, file_path)
|
203
210
|
begin
|
204
211
|
sts_path = upload_resp["result"]["path_sts"]
|
212
|
+
s4cmd_path = upload_resp["result"]["path_s4cmd"]
|
213
|
+
|
205
214
|
uri = URI.parse(sts_path)
|
206
215
|
http_object = Net::HTTP.new(uri.host, uri.port)
|
207
216
|
http_object.use_ssl = true if uri.scheme == 'https'
|
@@ -212,18 +221,62 @@ module Cnvrg
|
|
212
221
|
response = http.request request
|
213
222
|
body = response.read_body
|
214
223
|
end
|
224
|
+
|
215
225
|
URLcrypt::key = [body].pack('H*')
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
226
|
+
|
227
|
+
python_version=`python --version > /dev/null 2>&1` ; is_python=$?.success?
|
228
|
+
if !is_python
|
229
|
+
s3 = Aws::S3::Resource.new(
|
230
|
+
:access_key_id => URLcrypt.decrypt(upload_resp["result"]["sts_a"]),
|
231
|
+
:secret_access_key => URLcrypt.decrypt(upload_resp["result"]["sts_s"]),
|
232
|
+
:session_token => URLcrypt.decrypt(upload_resp["result"]["sts_st"]),
|
233
|
+
:region => URLcrypt.decrypt(upload_resp["result"]["region"]))
|
221
234
|
resp = s3.bucket(URLcrypt.decrypt(upload_resp["result"]["bucket"])).
|
222
235
|
object(upload_resp["result"]["path"]+"/"+File.basename(file_path)).
|
223
236
|
upload_file(file_path,{:use_accelerate_endpoint=>true})
|
237
|
+
else
|
238
|
+
s4cmd_uri = URI.parse(s4cmd_path)
|
239
|
+
s4cmd_http_object = Net::HTTP.new(s4cmd_uri.host, s4cmd_uri.port)
|
240
|
+
s4cmd_http_object.use_ssl = true if s4cmd_uri.scheme == 'https'
|
241
|
+
s4cmd_request = Net::HTTP::Get.new(s4cmd_path)
|
242
|
+
|
243
|
+
s4cmd_body = ""
|
244
|
+
s4cmd_http_object.start do |http|
|
245
|
+
response = http.request s4cmd_request
|
246
|
+
s4cmd_body = response.read_body
|
247
|
+
end
|
248
|
+
|
249
|
+
s4cmd_new_body = s4cmd_body.gsub(" self.client = self.boto3.client('s3',
|
250
|
+
aws_access_key_id=aws_access_key_id,
|
251
|
+
aws_secret_access_key=aws_secret_access_key)"," self.client = self.boto3.client('s3',
|
252
|
+
aws_access_key_id='#{ URLcrypt.decrypt(upload_resp["result"]["sts_a"])}',
|
253
|
+
aws_secret_access_key='#{URLcrypt.decrypt(upload_resp["result"]["sts_s"])}',
|
254
|
+
aws_session_token='#{URLcrypt.decrypt(upload_resp["result"]["sts_st"])}')")
|
255
|
+
|
256
|
+
tmp = Tempfile.new('s4cmd.py')
|
257
|
+
tmp << s4cmd_new_body
|
258
|
+
tmp.flush
|
259
|
+
tmp.close
|
260
|
+
|
261
|
+
is_success = false
|
262
|
+
count = 0
|
263
|
+
while !is_success and count <3
|
264
|
+
|
265
|
+
resp = `python #{tmp.path} --max-singlepart-upload-size=#{MULTIPART_SPLIT} put -f #{file_path} s3://#{URLcrypt.decrypt(upload_resp["result"]["bucket"])}/#{upload_resp["result"]["path"]+"/"+File.basename(file_path)} > /dev/null 2>&1`
|
266
|
+
is_success =$?.success?
|
267
|
+
count +=1
|
268
|
+
|
269
|
+
end
|
270
|
+
resp= is_success
|
271
|
+
|
272
|
+
end
|
224
273
|
|
225
274
|
return resp
|
275
|
+
|
226
276
|
rescue =>e
|
277
|
+
if File.exist? tmp
|
278
|
+
FileUtils.rm_rf [tmp]
|
279
|
+
end
|
227
280
|
puts e
|
228
281
|
return false
|
229
282
|
|
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.0.
|
4
|
+
version: 0.0.148
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yochay Ettun
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-05-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|