cnvrg 0.7.7 → 0.7.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cnvrg.gemspec +1 -7
- data/lib/cnvrg/api.rb +15 -1
- data/lib/cnvrg/cli.rb +286 -722
- data/lib/cnvrg/cli/flow.rb +116 -0
- data/lib/cnvrg/cli/subcommand.rb +26 -0
- data/lib/cnvrg/cli/task.rb +116 -0
- data/lib/cnvrg/data.rb +0 -1
- data/lib/cnvrg/datafiles.rb +55 -35
- data/lib/cnvrg/dataset.rb +50 -9
- data/lib/cnvrg/files.rb +263 -76
- data/lib/cnvrg/flow.rb +75 -0
- data/lib/cnvrg/helpers.rb +54 -0
- data/lib/cnvrg/hyper.rb +21 -0
- data/lib/cnvrg/logger.rb +102 -0
- data/lib/cnvrg/project.rb +86 -19
- data/lib/cnvrg/task.rb +165 -0
- data/lib/cnvrg/version.rb +2 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b19ed887eb07e3f10c710d73849c7578cf10824
|
4
|
+
data.tar.gz: 397910ae8ce973da74c4b921ab6fc2e59ea63388
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47f085ae30d741751dfca95a8196cc794460ce36cb1cb9e2847a577cb94936488f8c2abd0571d3cc6e4a894aa01bf2d8fb1efbb7fe8199770bdaca92466ed91a
|
7
|
+
data.tar.gz: '06699e08c81ed1626ef49ac09f2a5b8deb90b29c41ecd3b1d6b6984c5f4f8351848aea342b397b3186b7dbfffab0459bccbfa9c6fbf744a94c16810d2914a449'
|
data/cnvrg.gemspec
CHANGED
data/lib/cnvrg/api.rb
CHANGED
@@ -61,8 +61,9 @@ module Cnvrg
|
|
61
61
|
success = false
|
62
62
|
while !success and retries < 20
|
63
63
|
begin
|
64
|
-
|
64
|
+
response = conn.get "#{resource}", data
|
65
65
|
success = true
|
66
|
+
Cnvrg::API.parse_version(response)
|
66
67
|
rescue => e
|
67
68
|
sleep(5)
|
68
69
|
retries +=1
|
@@ -89,6 +90,7 @@ module Cnvrg
|
|
89
90
|
response = conn.post "#{resource}", data if method.eql? 'POST'
|
90
91
|
response = conn.put "#{resource}", data if method.eql? 'PUT'
|
91
92
|
success = true
|
93
|
+
Cnvrg::API.parse_version(response)
|
92
94
|
|
93
95
|
rescue => e
|
94
96
|
sleep(5)
|
@@ -119,6 +121,7 @@ module Cnvrg
|
|
119
121
|
begin
|
120
122
|
response = conn.post "#{resource}", new_data
|
121
123
|
success = true
|
124
|
+
Cnvrg::API.parse_version(response)
|
122
125
|
|
123
126
|
rescue => e
|
124
127
|
sleep(5)
|
@@ -171,6 +174,7 @@ module Cnvrg
|
|
171
174
|
data[:file] = Faraday::UploadIO.new("#{temp_path}", "plain/text")
|
172
175
|
|
173
176
|
response = conn.post "#{endpoint_uri}/#{resource}", data
|
177
|
+
Cnvrg::API.parse_version(response)
|
174
178
|
|
175
179
|
FileUtils.rm_rf(temp_path)
|
176
180
|
if response.to_hash[:status] == 404
|
@@ -185,6 +189,7 @@ module Cnvrg
|
|
185
189
|
end
|
186
190
|
when 'DELETE'
|
187
191
|
response = conn.delete "#{endpoint_uri}/#{resource}", data
|
192
|
+
Cnvrg::API.parse_version(response)
|
188
193
|
if response.to_hash[:status] == 404
|
189
194
|
return false
|
190
195
|
end
|
@@ -215,6 +220,15 @@ module Cnvrg
|
|
215
220
|
"Oops, an error occurred! Reason: #{response['message']}"
|
216
221
|
end
|
217
222
|
|
223
|
+
def self.parse_version(resp)
|
224
|
+
begin
|
225
|
+
version = resp.headers["cnvrg-version"]
|
226
|
+
Cnvrg::Helpers.update_version(version)
|
227
|
+
rescue => e
|
228
|
+
Cnvrg::Logger.log_error(e)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
218
232
|
# Internal: Ensure the response returns a HTTP 200.
|
219
233
|
#
|
220
234
|
# If the response status isn't a HTTP 200, we need to find out why. This
|
data/lib/cnvrg/cli.rb
CHANGED
@@ -23,6 +23,9 @@ require 'cnvrg/datafiles'
|
|
23
23
|
require 'cnvrg/data'
|
24
24
|
require 'cnvrg/ssh'
|
25
25
|
require 'cnvrg/result'
|
26
|
+
require 'cnvrg/logger'
|
27
|
+
require 'cnvrg/cli/flow'
|
28
|
+
require 'cnvrg/cli/task'
|
26
29
|
require 'logstash-logger'
|
27
30
|
require 'cnvrg/job'
|
28
31
|
require 'docker'
|
@@ -157,9 +160,18 @@ module Cnvrg
|
|
157
160
|
super
|
158
161
|
end
|
159
162
|
end
|
160
|
-
desc "data", "upload and manage datasets", :hide =>
|
163
|
+
desc "data", "upload and manage datasets", :hide => false
|
161
164
|
subcommand "data", Data
|
162
165
|
|
166
|
+
# desc "flow", "mange project flows", :hide => true
|
167
|
+
# subcommand "flow", Cnvrg::Commands::Flow
|
168
|
+
|
169
|
+
|
170
|
+
def initialize(*args)
|
171
|
+
super
|
172
|
+
self.log_handler
|
173
|
+
end
|
174
|
+
|
163
175
|
desc "", "", :hide => true
|
164
176
|
|
165
177
|
def test
|
@@ -207,7 +219,7 @@ module Cnvrg
|
|
207
219
|
owner = url_parts[project_index - 1]
|
208
220
|
res = Cnvrg::API.request("users/#{owner}/datasets/#{slug}", 'GET')
|
209
221
|
unless Cnvrg::CLI.is_response_success(res, false)
|
210
|
-
raise SignalException.new
|
222
|
+
raise SignalException.new
|
211
223
|
end
|
212
224
|
@dataset = Dataset.new(Dir.pwd)
|
213
225
|
result = res['result']
|
@@ -873,7 +885,7 @@ module Cnvrg
|
|
873
885
|
:autofinish => true)
|
874
886
|
|
875
887
|
while files['keys'].length > 0
|
876
|
-
|
888
|
+
Cnvrg::Logger.log_info("download multiple files, #{downloaded_files.size} files downloaded")
|
877
889
|
@files.download_multiple_files_s3(files, dataset_home, progressbar: progressbar, read_only: read)
|
878
890
|
|
879
891
|
downloaded_files += files['keys'].length
|
@@ -1249,7 +1261,7 @@ module Cnvrg
|
|
1249
1261
|
# say "Please fix #{num}, and retry", Thor::Shell::Color::RED
|
1250
1262
|
# exit(1)
|
1251
1263
|
#
|
1252
|
-
#
|
1264
|
+
# en
|
1253
1265
|
check = Helpers.checkmark()
|
1254
1266
|
|
1255
1267
|
if result["added"].empty? and result["updated_on_local"].empty? and result["deleted"].empty?
|
@@ -1804,9 +1816,7 @@ module Cnvrg
|
|
1804
1816
|
@files = Cnvrg::Files.new(@project.owner, slug)
|
1805
1817
|
response = @project.clone(remote, commit_to_clone)
|
1806
1818
|
Cnvrg::CLI.is_response_success response
|
1807
|
-
working_dir = project_home
|
1808
1819
|
idx = {commit: response["result"]["commit"], tree: response["result"]["tree"]}
|
1809
|
-
File.open(working_dir + "/.cnvrg/idx.yml", "w+") {|f| f.write idx.to_yaml}
|
1810
1820
|
|
1811
1821
|
log_message("Downloading files", Thor::Shell::Color::BLUE)
|
1812
1822
|
files = response["result"]["files"]
|
@@ -1814,6 +1824,7 @@ module Cnvrg
|
|
1814
1824
|
if !files.nil?
|
1815
1825
|
begin
|
1816
1826
|
download_result = @files.download_multpile_files_s3(files, project_home)
|
1827
|
+
@project.set_idx(idx)
|
1817
1828
|
|
1818
1829
|
rescue Interrupt
|
1819
1830
|
log_message("Couldn't download, Rolling Back all changes.", Thor::Shell::Color::RED)
|
@@ -1876,6 +1887,7 @@ module Cnvrg
|
|
1876
1887
|
end
|
1877
1888
|
successful_changes = response["result"]["tree"]
|
1878
1889
|
if !successful_changes.nil? and is_success
|
1890
|
+
@project.set_idx(idx)
|
1879
1891
|
Project.verify_cnvrgignore_exist(project_name,remote)
|
1880
1892
|
log_message("Done.\nDownloaded #{successful_changes.size}/#{response["result"]["tree"].size} files", Thor::Shell::Color::GREEN)
|
1881
1893
|
else
|
@@ -1919,6 +1931,7 @@ module Cnvrg
|
|
1919
1931
|
verify_logged_in()
|
1920
1932
|
log_start(__method__, args, options)
|
1921
1933
|
@project = Project.new(get_project_home)
|
1934
|
+
|
1922
1935
|
new_branch = options["new_branch"] || false
|
1923
1936
|
force = options["force"] || false
|
1924
1937
|
|
@@ -2030,9 +2043,6 @@ module Cnvrg
|
|
2030
2043
|
if upload_res < 0
|
2031
2044
|
return
|
2032
2045
|
end
|
2033
|
-
# if !upload_res
|
2034
|
-
# return
|
2035
|
-
# end
|
2036
2046
|
invoke :end_commit_data,[commit, success: true, uploaded_files: upload_res] , :new_branch=>new_branch, :force =>force
|
2037
2047
|
if tags
|
2038
2048
|
log_message('Uploading Tags', Thor::Shell::Color::BLUE)
|
@@ -2051,70 +2061,57 @@ module Cnvrg
|
|
2051
2061
|
log_message('There was some error in uploading Tags', Thor::Shell::Color::RED)
|
2052
2062
|
end
|
2053
2063
|
end
|
2054
|
-
|
2055
|
-
|
2056
|
-
|
2057
|
-
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2064
|
-
|
2065
|
-
|
2066
|
-
|
2067
|
-
|
2068
|
-
|
2064
|
+
rescue => e
|
2065
|
+
Cnvrg::Logger.log_error(e)
|
2066
|
+
say "\nAborting", Thor::Shell::Color::BLUE
|
2067
|
+
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
2068
|
+
return false if dataset_dir.blank?
|
2069
|
+
@dataset = Dataset.new(dataset_dir)
|
2070
|
+
return false
|
2071
|
+
rescue SignalException => e
|
2072
|
+
Cnvrg::Logger.log_error(e)
|
2073
|
+
say "\nAborting", Thor::Shell::Color::BLUE
|
2074
|
+
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
2075
|
+
return false if dataset_dir.blank?
|
2076
|
+
@dataset = Dataset.new(dataset_dir)
|
2077
|
+
return false
|
2078
|
+
end
|
2069
2079
|
end
|
2070
2080
|
|
2071
2081
|
desc 'start_commit', 'start data commit'
|
2072
2082
|
method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
|
2073
|
-
method_option :direct, :type => :boolean, :aliases => ["-d","--direct"], :desc => "was called directed", :default => true
|
2074
|
-
method_option :force, :type => :boolean, :aliases => ["-f","--force"], :default => false
|
2083
|
+
method_option :direct, :type => :boolean, :aliases => ["-d", "--direct"], :desc => "was called directed", :default => true
|
2084
|
+
method_option :force, :type => :boolean, :aliases => ["-f", "--force"], :default => false
|
2075
2085
|
method_option :chunk_size, :type => :numeric, :aliases => ["-ch"], :default => 0
|
2076
2086
|
|
2077
2087
|
def start_commit_data()
|
2078
|
-
|
2079
|
-
|
2080
|
-
|
2081
|
-
|
2082
|
-
|
2083
|
-
|
2084
|
-
|
2085
|
-
|
2086
|
-
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2090
|
-
|
2091
|
-
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
|
2098
|
-
|
2099
|
-
# resp = @files.start_commit(new_branch,force, chunks: chunks)
|
2100
|
-
# commit_sha1 = resp["result"]["commit_sha1"]
|
2101
|
-
# @dataset.set_next_commit(commit_sha1)
|
2102
|
-
# else
|
2103
|
-
# commit_sha1 = resp["result"]["commit_sha1"]
|
2104
|
-
# end
|
2105
|
-
# else
|
2106
|
-
# resp = @files.start_commit(new_branch,force, chunks: chunks)
|
2107
|
-
# commit_sha1 = resp["result"]["commit_sha1"]
|
2108
|
-
# @dataset.set_next_commit(commit_sha1)
|
2109
|
-
# end
|
2110
|
-
commit_sha1 = resp["result"]["commit_sha1"]
|
2111
|
-
@dataset.set_next_commit(commit_sha1)
|
2112
|
-
if direct
|
2113
|
-
puts commit_sha1
|
2114
|
-
end
|
2115
|
-
return commit_sha1
|
2088
|
+
verify_logged_in(true)
|
2089
|
+
log_start(__method__, args, options)
|
2090
|
+
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
2091
|
+
direct = options[:direct]
|
2092
|
+
new_branch = options["new_branch"] || false
|
2093
|
+
force = options["force"] || false
|
2094
|
+
chunk_size = options["chunk_size"] || false
|
2095
|
+
commit_sha1 = nil
|
2096
|
+
@dataset = Dataset.new(dataset_dir)
|
2097
|
+
@dataset.backup_idx
|
2098
|
+
@files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug)
|
2099
|
+
next_commit = @dataset.get_next_commit #if there was a partial commit..
|
2100
|
+
chunks = (@dataset.list_all_files.length.to_f / chunk_size).ceil
|
2101
|
+
resp = @files.start_commit(new_branch, force, chunks: chunks, dataset: @dataset)
|
2102
|
+
if !resp['result']['can_commit']
|
2103
|
+
log_message("Cant upload files because a new version of this dataset exists, please download it or upload with --force", Thor::Shell::Color::RED)
|
2104
|
+
exit(1)
|
2105
|
+
end
|
2106
|
+
commit_sha1 = resp["result"]["commit_sha1"]
|
2107
|
+
unless commit_sha1.eql? next_commit
|
2108
|
+
@dataset.set_partial_commit(next_commit)
|
2116
2109
|
end
|
2110
|
+
@dataset.set_next_commit(commit_sha1)
|
2111
|
+
return commit_sha1
|
2117
2112
|
end
|
2113
|
+
|
2114
|
+
|
2118
2115
|
desc 'end_commit', 'start data commit'
|
2119
2116
|
method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
|
2120
2117
|
method_option :force, :type => :boolean, :aliases => ["-f","--force"], :default => false
|
@@ -2128,15 +2125,16 @@ module Cnvrg
|
|
2128
2125
|
@files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug)
|
2129
2126
|
force = options["force"] || false
|
2130
2127
|
resp = @files.end_commit(commit, force, success: success, uploaded_files: uploaded_files)
|
2131
|
-
if (resp and resp["result"])
|
2128
|
+
if (resp.present? and resp["result"])
|
2132
2129
|
check = Helpers.checkmark
|
2133
2130
|
if resp["result"]["new_commit"].blank?
|
2134
|
-
@dataset.revert_next_commit
|
2131
|
+
@dataset.revert_next_commit #removes the next commit
|
2135
2132
|
log_message("#{check} Dataset is up to date", Thor::Shell::Color::GREEN)
|
2136
2133
|
else
|
2137
2134
|
log_message("#{check} Data files were updated successfully", Thor::Shell::Color::GREEN)
|
2138
|
-
@dataset.
|
2139
|
-
@dataset.
|
2135
|
+
@dataset.remove_next_commit #takes the next commit and put it as current commit
|
2136
|
+
@dataset.set_partial_commit(nil)
|
2137
|
+
@dataset.backup_idx
|
2140
2138
|
end
|
2141
2139
|
end
|
2142
2140
|
end
|
@@ -2188,253 +2186,59 @@ module Cnvrg
|
|
2188
2186
|
|
2189
2187
|
def upload_data_files(new_commit, *files)
|
2190
2188
|
begin
|
2191
|
-
|
2192
|
-
|
2193
|
-
|
2194
|
-
|
2195
|
-
|
2196
|
-
|
2197
|
-
|
2198
|
-
|
2199
|
-
|
2200
|
-
|
2201
|
-
force = options[:force] || false
|
2202
|
-
chunk_size = options[:chunk_size]
|
2203
|
-
chunk_size = [chunk_size, 1].max
|
2204
|
-
new_branch = options["new_branch"] || false
|
2205
|
-
new_tree = {}
|
2206
|
-
force = options["force"] || false
|
2207
|
-
parallel_threads = options["parallel"] || ParallelThreads
|
2208
|
-
all_files = @dataset.list_all_files
|
2209
|
-
progressbar = ProgressBar.create(:title => "Upload Progress",
|
2210
|
-
:progress_mark => '=',
|
2211
|
-
:format => "%b>>%i| %p%% %t",
|
2212
|
-
:starting_at => 0,
|
2213
|
-
:total => all_files.length,
|
2214
|
-
:autofinish => true)
|
2215
|
-
files_uploaded = 0
|
2216
|
-
all_files.each_slice(chunk_size).each do |list_files|
|
2217
|
-
temp_tree = @dataset.generate_chunked_idx(list_files, threads: parallel_threads)
|
2218
|
-
|
2219
|
-
upload_resp = @files.upload_multiple_files(new_commit, temp_tree, threads: parallel_threads, force: force, new_branch: new_branch, progressbar: progressbar)
|
2220
|
-
|
2221
|
-
if upload_resp.is_a? Cnvrg::Result
|
2222
|
-
log_message(upload_resp.msg, upload_resp.msg_color)
|
2223
|
-
raise SignalException.new(upload_resp.msg)
|
2224
|
-
# return -1
|
2225
|
-
|
2226
|
-
else
|
2227
|
-
files_uploaded += upload_resp
|
2228
|
-
next if upload_resp == 0
|
2229
|
-
end
|
2230
|
-
|
2231
|
-
temp_tree.each do |k,v|
|
2232
|
-
new_tree[k] = (v.present?) ? {sha1: v.try(:fetch, :sha1, nil), commit_time: nil} : nil
|
2233
|
-
end
|
2234
|
-
@dataset.write_idx(new_tree, new_commit)
|
2235
|
-
end
|
2236
|
-
return files_uploaded
|
2189
|
+
verify_logged_in(true)
|
2190
|
+
log_start(__method__, args, options)
|
2191
|
+
dataset_dir = is_cnvrg_dir(Dir.pwd)
|
2192
|
+
@dataset = Dataset.new(dataset_dir)
|
2193
|
+
@files = Cnvrg::Datafiles.new(@dataset.owner, @dataset.slug)
|
2194
|
+
new_commit ||= @dataset.get_next_commit()
|
2195
|
+
partial_commit = @dataset.get_partial_commit
|
2196
|
+
if new_commit.blank?
|
2197
|
+
log_message("You must specify commit, run start_commit to create new commit", Thor::Shell::Color::RED)
|
2198
|
+
return false
|
2237
2199
|
end
|
2238
|
-
|
2239
|
-
|
2240
|
-
|
2241
|
-
|
2242
|
-
|
2243
|
-
|
2244
|
-
|
2245
|
-
|
2246
|
-
|
2247
|
-
|
2248
|
-
|
2249
|
-
|
2250
|
-
|
2251
|
-
|
2252
|
-
|
2253
|
-
|
2254
|
-
|
2255
|
-
|
2256
|
-
|
2257
|
-
|
2258
|
-
|
2259
|
-
|
2260
|
-
|
2261
|
-
|
2262
|
-
|
2263
|
-
|
2264
|
-
|
2265
|
-
|
2266
|
-
|
2267
|
-
#
|
2268
|
-
|
2269
|
-
|
2270
|
-
|
2271
|
-
|
2272
|
-
|
2273
|
-
# end
|
2274
|
-
# log_message("Creating new commit for dataset: #{@dataset.slug}", Thor::Shell::Color::BLUE) unless options[:sync]
|
2275
|
-
|
2276
|
-
|
2277
|
-
# # upload / update
|
2278
|
-
# begin
|
2279
|
-
|
2280
|
-
# parallel_options = {
|
2281
|
-
# :progress => {
|
2282
|
-
# :title => "Upload Progress",
|
2283
|
-
# :progress_mark => '=',
|
2284
|
-
# :format => "%b>>%i| %p%% %t",
|
2285
|
-
# :starting_at => 0,
|
2286
|
-
# :total => (result["added"] + result["updated_on_local"]).size,
|
2287
|
-
# :autofinish => true
|
2288
|
-
# },
|
2289
|
-
# in_threads: ParallelThreads,
|
2290
|
-
# isolation: true
|
2291
|
-
# }
|
2292
|
-
# successful_updates = []
|
2293
|
-
# update_count =0
|
2294
|
-
# update_total = (result["added"] + result["updated_on_local"] + result["deleted"]).size
|
2295
|
-
|
2296
|
-
# if (result["added"] + result["updated_on_local"]).size > 0
|
2297
|
-
# begin
|
2298
|
-
# upload_result = Parallel.map((result["added"] + result["updated_on_local"]), parallel_options) do |f|
|
2299
|
-
# absolute_path = "#{@dataset.local_path}/#{f}"
|
2300
|
-
# relative_path = f.gsub(/^#{@dataset.local_path + "/"}/, "")
|
2301
|
-
# if File.directory?(absolute_path)
|
2302
|
-
# if dirs_uploaded.include? f
|
2303
|
-
# #Already uploaded and didn't finish commit
|
2304
|
-
# log_message("Already uploaded dir: #{f}", Thor::Shell::Color::BLUE, options["verbose"])
|
2305
|
-
|
2306
|
-
# next
|
2307
|
-
# end
|
2308
|
-
# log_message("uploading dir: #{f}", Thor::Shell::Color::BLUE, options["verbose"])
|
2309
|
-
|
2310
|
-
# resDir = @files.create_dir(absolute_path, relative_path, commit_sha1)
|
2311
|
-
# if resDir
|
2312
|
-
# update_count += 1
|
2313
|
-
# successful_updates<< relative_path
|
2314
|
-
# else
|
2315
|
-
# log_message("Failed to upload directory: #{ relative_path }", Thor::Shell::Color::RED)
|
2316
|
-
|
2317
|
-
# raise Parallel::Kill
|
2318
|
-
# end
|
2319
|
-
|
2320
|
-
# else
|
2321
|
-
# if files_uploaded_names.include? f
|
2322
|
-
# log_message("Already uploaded file: #{f}", Thor::Shell::Color::BLUE, options["verbose"])
|
2323
|
-
|
2324
|
-
# next
|
2325
|
-
# end
|
2326
|
-
# log_message("uploading: #{f}", Thor::Shell::Color::BLUE, options["verbose"])
|
2327
|
-
|
2328
|
-
# res = @files.upload_file(absolute_path, relative_path, commit_sha1)
|
2329
|
-
# if res
|
2330
|
-
# update_count += 1
|
2331
|
-
|
2332
|
-
# successful_updates<< relative_path
|
2333
|
-
# else
|
2334
|
-
# log_message("Failed to upload: #{ File.basename(absolute_path) }", Thor::Shell::Color::RED)
|
2335
|
-
|
2336
|
-
# raise Parallel::Kill
|
2337
|
-
|
2338
|
-
# end
|
2339
|
-
# end
|
2340
|
-
# end
|
2341
|
-
# rescue SignalException
|
2342
|
-
# log_message("Exception while trying to upload, look at the log for more details", Thor::Shell::Color::RED)
|
2343
|
-
|
2344
|
-
|
2345
|
-
# exit(1)
|
2346
|
-
# end
|
2347
|
-
# end
|
2348
|
-
|
2349
|
-
# end
|
2350
|
-
# successful_updates = upload_result.to_a + dirs_uploaded + files_uploaded_names
|
2351
|
-
# successful_deletions =[]
|
2352
|
-
|
2353
|
-
|
2354
|
-
# # delete
|
2355
|
-
|
2356
|
-
# deleted = update_deleted(result["deleted"])
|
2357
|
-
# begin
|
2358
|
-
|
2359
|
-
# deleted_result = Parallel.map(deleted, in_threads: ParallelThreads) do |f|
|
2360
|
-
|
2361
|
-
# relative_path = f.gsub(/^#{@dataset.local_path + "/"}/, "")
|
2362
|
-
# if relative_path.end_with?("/")
|
2363
|
-
# log_message("deleting dir: #{f}", Thor::Shell::Color::RED, options["verbose"])
|
2364
|
-
|
2365
|
-
# if @files.delete_dir(f, relative_path, commit_sha1)
|
2366
|
-
# successful_deletions << f
|
2367
|
-
# else
|
2368
|
-
# log_message("Failed to delete directory: #{ f }", Thor::Shell::Color::RED)
|
2369
|
-
# raise Parallel::Kill
|
2370
|
-
|
2371
|
-
# end
|
2372
|
-
# else
|
2373
|
-
# log_message("deleteing file: #{f}", Thor::Shell::Color::RED, options["verbose"])
|
2374
|
-
|
2375
|
-
# if @files.delete_file(f, relative_path, commit_sha1)
|
2376
|
-
# successful_deletions << f
|
2377
|
-
|
2378
|
-
# else
|
2379
|
-
# log_message("Failed to delete file: #{ f }", Thor::Shell::Color::RED)
|
2380
|
-
# raise Parallel::Kill
|
2381
|
-
|
2382
|
-
|
2383
|
-
# end
|
2384
|
-
# end
|
2385
|
-
# end
|
2386
|
-
|
2387
|
-
|
2388
|
-
# successful_deletions += successful_deletions.select { |x| not x.nil? }
|
2389
|
-
|
2390
|
-
|
2391
|
-
# successful_updates = successful_updates.select { |x| not x.nil? }
|
2392
|
-
|
2393
|
-
# update_count = successful_updates.size
|
2394
|
-
|
2395
|
-
# rescue SignalException
|
2396
|
-
# say "User aborted", Thor::Shell::Color::RED
|
2397
|
-
# exit(0)
|
2398
|
-
# rescue => e
|
2399
|
-
# log_message("Exception while trying to upload, look at the log for more details", Thor::Shell::Color::RED)
|
2400
|
-
# log_error(e)
|
2401
|
-
# exit(0)
|
2402
|
-
# end
|
2403
|
-
# if !result["deleted"].nil? and !result["deleted"].empty?
|
2404
|
-
# update_count += result["deleted"].size
|
2405
|
-
# end
|
2406
|
-
|
2407
|
-
# if update_count == update_total
|
2408
|
-
# begin
|
2409
|
-
# @dataset.update_idx_with_files_commits!((successful_deletions+successful_updates), commit_time)
|
2410
|
-
|
2411
|
-
# return true
|
2412
|
-
# rescue => e
|
2413
|
-
# log_message("Exception while trying to upload, look at the log for more details", Thor::Shell::Color::RED)
|
2414
|
-
|
2415
|
-
# exit(1)
|
2416
|
-
|
2417
|
-
# end
|
2418
|
-
|
2419
|
-
# end
|
2420
|
-
# rescue => e
|
2421
|
-
|
2422
|
-
# log_message("Exception while trying to upload, look at the log for more details", Thor::Shell::Color::RED)
|
2423
|
-
# log_error(e)
|
2424
|
-
|
2425
|
-
# exit(1)
|
2426
|
-
# rescue SignalException
|
2427
|
-
|
2428
|
-
# say "\nAborting", Thor::Shell::Color::BLUE
|
2429
|
-
# exit(1)
|
2430
|
-
# end
|
2431
|
-
|
2200
|
+
force = options[:force] || false
|
2201
|
+
chunk_size = options[:chunk_size]
|
2202
|
+
chunk_size = [chunk_size, 1].max
|
2203
|
+
new_branch = options["new_branch"] || false
|
2204
|
+
new_tree = {}
|
2205
|
+
force = options["force"] || false
|
2206
|
+
parallel_threads = options["parallel"] || ParallelThreads
|
2207
|
+
all_files = @dataset.list_all_files
|
2208
|
+
progressbar = ProgressBar.create(:title => "Upload Progress",
|
2209
|
+
:progress_mark => '=',
|
2210
|
+
:format => "%b>>%i| %p%% %t",
|
2211
|
+
:starting_at => 0,
|
2212
|
+
:total => all_files.length,
|
2213
|
+
:autofinish => true)
|
2214
|
+
files_uploaded = 0
|
2215
|
+
all_files.each_slice(chunk_size).each do |list_files|
|
2216
|
+
Cnvrg::Logger.log_info("Uploading files into #{@dataset.slug}, #{files_uploaded} files uploaded")
|
2217
|
+
temp_tree = @dataset.generate_chunked_idx(list_files, threads: parallel_threads)
|
2218
|
+
upload_resp = @files.upload_multiple_files(new_commit, temp_tree,
|
2219
|
+
threads: parallel_threads,
|
2220
|
+
force: force,
|
2221
|
+
new_branch: new_branch,
|
2222
|
+
progressbar: progressbar,
|
2223
|
+
partial_commit: partial_commit)
|
2224
|
+
files_uploaded += upload_resp
|
2225
|
+
temp_tree.each do |k, v|
|
2226
|
+
new_tree[k] = (v.present?) ? {sha1: v.try(:fetch, :sha1, nil), commit_time: nil} : nil
|
2227
|
+
end
|
2228
|
+
end
|
2229
|
+
@dataset.write_tree(new_tree) #we dont want to re-run it every time so just on finish.
|
2230
|
+
rescue => e
|
2231
|
+
Cnvrg::Logger.log_error(e)
|
2232
|
+
raise e
|
2233
|
+
end
|
2234
|
+
return files_uploaded
|
2432
2235
|
end
|
2433
2236
|
|
2434
2237
|
|
2435
2238
|
desc 'upload', 'Upload updated files'
|
2436
2239
|
method_option :ignore, :type => :string, :aliases => ["-i"], :desc => "ignore following files", :default => ""
|
2437
2240
|
method_option :new_branch, :type => :boolean, :aliases => ["-nb", "--new_branch"], :desc => "create new branch of commits"
|
2241
|
+
method_option :in_exp, :type => :boolean, :aliases => ["-ie", "--in-exp"], :desc => "In Experiment"
|
2438
2242
|
method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
|
2439
2243
|
method_option :sync, :type => :boolean, :aliases => ["-s"], :default => false
|
2440
2244
|
method_option :force, :type => :boolean, :aliases => ["-f", "--force"], :default => false
|
@@ -2446,7 +2250,7 @@ module Cnvrg
|
|
2446
2250
|
method_option :job_slug, :type => :string, :aliases => ["--job"], :default => nil, :hide=>true
|
2447
2251
|
method_option :job_type, :type => :string, :aliases => [ "--job_type"], :default => nil, :hide=>true
|
2448
2252
|
|
2449
|
-
def upload(link = false, sync = false, direct = false, ignore_list = "", in_exp = false, force = false,output_dir="output",job_type=nil,job_slug=nil
|
2253
|
+
def upload(link = false, sync = false, direct = false, ignore_list = "", in_exp = false, force = false, output_dir = "output", job_type = nil, job_slug = nil)
|
2450
2254
|
begin
|
2451
2255
|
# we are passing "force" twice.. doesnt really make sense :\\
|
2452
2256
|
verify_logged_in(true)
|
@@ -2457,7 +2261,7 @@ module Cnvrg
|
|
2457
2261
|
commit_msg = ""
|
2458
2262
|
end
|
2459
2263
|
return_id = options["return_id"]
|
2460
|
-
@files = Cnvrg::Files.new(@project.owner, @project.slug)
|
2264
|
+
@files = Cnvrg::Files.new(@project.owner, @project.slug, project_home: get_project_home)
|
2461
2265
|
ignore = options[:ignore] || ""
|
2462
2266
|
force = options[:force] || force || false
|
2463
2267
|
spec_files_to_upload = options["files"]
|
@@ -2467,19 +2271,19 @@ module Cnvrg
|
|
2467
2271
|
spec_files_to_upload = spec_files_to_upload.split(",")
|
2468
2272
|
end
|
2469
2273
|
if @project.is_git
|
2470
|
-
|
2471
|
-
|
2472
|
-
|
2473
|
-
|
2474
|
-
|
2475
|
-
|
2476
|
-
|
2477
|
-
|
2478
|
-
|
2274
|
+
git_output_dir = options["output_dir"] || output_dir
|
2275
|
+
if git_output_dir.present?
|
2276
|
+
if git_output_dir.ends_with? "/"
|
2277
|
+
git_output_dir = git_output_dir[0..-2]
|
2278
|
+
end
|
2279
|
+
list = @project.generate_output_dir(git_output_dir)
|
2280
|
+
spec_files_to_upload = list
|
2281
|
+
if spec_files_to_upload.blank?
|
2282
|
+
log_message("#{check} Project is up to date", Thor::Shell::Color::GREEN, (((options["sync"] or sync) and !direct) ? false : true))
|
2479
2283
|
return true
|
2284
|
+
end
|
2285
|
+
force = true
|
2480
2286
|
end
|
2481
|
-
force = true
|
2482
|
-
end
|
2483
2287
|
end
|
2484
2288
|
|
2485
2289
|
if ignore.nil? or ignore.empty?
|
@@ -2498,7 +2302,7 @@ module Cnvrg
|
|
2498
2302
|
end
|
2499
2303
|
new_branch = options["new_branch"] || @project.is_branch
|
2500
2304
|
|
2501
|
-
result = @project.compare_idx(new_branch, force: force, deploy: options["deploy"],in_exp:in_exp, specific_files: spec_files_to_upload)
|
2305
|
+
result = @project.compare_idx(new_branch, force: force, deploy: options["deploy"], in_exp: in_exp, specific_files: spec_files_to_upload)
|
2502
2306
|
commit = result["result"]["commit"]
|
2503
2307
|
|
2504
2308
|
if !link
|
@@ -2511,7 +2315,12 @@ module Cnvrg
|
|
2511
2315
|
end
|
2512
2316
|
result = result["result"]["tree"]
|
2513
2317
|
if result["added"].empty? and result["updated_on_local"].empty? and result["deleted"].empty?
|
2514
|
-
|
2318
|
+
msg = "#{check} Project is up to date"
|
2319
|
+
if return_id
|
2320
|
+
Cnvrg::Logger.jsonify(msg: msg, success: true)
|
2321
|
+
else
|
2322
|
+
log_message(msg, Thor::Shell::Color::GREEN, (((options["sync"] or sync) and !direct) ? false : true))
|
2323
|
+
end
|
2515
2324
|
return true
|
2516
2325
|
end
|
2517
2326
|
update_count = 0
|
@@ -2537,233 +2346,78 @@ module Cnvrg
|
|
2537
2346
|
end
|
2538
2347
|
job_type = options['job_type'] || job_type
|
2539
2348
|
job_slug = options['job_slug'] || job_slug
|
2540
|
-
commit_sha1 = @files.start_commit(new_branch, force: force, exp_start_commit:exp_start_commit,
|
2541
|
-
job_type: job_type, job_slug: job_slug, start_commit: current_commit)["result"]["commit_sha1"]
|
2349
|
+
commit_sha1 = @files.start_commit(new_branch, force: force, exp_start_commit: exp_start_commit,
|
2350
|
+
job_type: job_type, job_slug: job_slug, start_commit: current_commit, message: options["message"])["result"]["commit_sha1"]
|
2542
2351
|
# upload / update
|
2543
|
-
|
2544
|
-
|
2545
|
-
|
2546
|
-
|
2547
|
-
|
2548
|
-
|
2549
|
-
|
2550
|
-
|
2551
|
-
|
2552
|
-
|
2553
|
-
|
2554
|
-
|
2555
|
-
|
2556
|
-
|
2557
|
-
|
2558
|
-
|
2559
|
-
|
2560
|
-
|
2561
|
-
|
2562
|
-
|
2563
|
-
|
2564
|
-
|
2565
|
-
|
2566
|
-
|
2567
|
-
|
2568
|
-
|
2569
|
-
|
2570
|
-
|
2571
|
-
|
2572
|
-
|
2573
|
-
|
2574
|
-
|
2575
|
-
|
2576
|
-
|
2577
|
-
|
2578
|
-
else
|
2579
|
-
log_message("uploading: #{f}", Thor::Shell::Color::BLUE, options["verbose"])
|
2580
|
-
|
2581
|
-
res = @files.upload_file(absolute_path, relative_path, commit_sha1)
|
2582
|
-
if res
|
2583
|
-
f
|
2584
|
-
update_count += 1
|
2585
|
-
|
2586
|
-
successful_updates << relative_path
|
2587
|
-
else
|
2588
|
-
log_message("Failed to upload: #{ File.basename(absolute_path) }", Thor::Shell::Color::RED)
|
2589
|
-
|
2590
|
-
raise Parallel::Kill
|
2591
|
-
|
2592
|
-
end
|
2593
|
-
end
|
2594
|
-
end
|
2595
|
-
rescue SignalException
|
2596
|
-
log_message("Couldn't upload, Rolling Back all changes.", Thor::Shell::Color::RED)
|
2597
|
-
@files.rollback_commit(commit_sha1)
|
2598
|
-
return false
|
2599
|
-
end
|
2600
|
-
end
|
2601
|
-
|
2602
|
-
|
2603
|
-
successful_updates = upload_result.to_a
|
2604
|
-
|
2605
|
-
|
2606
|
-
# delete
|
2607
|
-
|
2608
|
-
deleted = update_deleted(result["deleted"])
|
2609
|
-
begin
|
2610
|
-
|
2611
|
-
deleted_result = Parallel.map(deleted, in_processes: ParallelProcesses, in_thread: ParallelThreads) do |f|
|
2612
|
-
|
2613
|
-
relative_path = f.gsub(/^#{@project.local_path + "/"}/, "")
|
2614
|
-
if relative_path.end_with?("/")
|
2615
|
-
log_message("deleting dir: #{f}", Thor::Shell::Color::RED, options["verbose"])
|
2616
|
-
|
2617
|
-
if @files.delete_dir(f, relative_path, commit_sha1)
|
2618
|
-
f
|
2619
|
-
else
|
2620
|
-
log_message("Failed to delete directory: #{ f }", Thor::Shell::Color::RED)
|
2621
|
-
|
2622
|
-
end
|
2623
|
-
else
|
2624
|
-
log_message("deleteing file: #{f}", Thor::Shell::Color::RED, options["verbose"])
|
2625
|
-
|
2626
|
-
if @files.delete_file(f, relative_path, commit_sha1)
|
2627
|
-
f
|
2628
|
-
else
|
2629
|
-
log_message("Failed to delete file: #{ f }", Thor::Shell::Color::RED)
|
2630
|
-
|
2631
|
-
end
|
2632
|
-
end
|
2633
|
-
end
|
2634
|
-
rescue Interrupt
|
2635
|
-
log_message("Couldn't upload, Rolling Back all changes.", Thor::Shell::Color::RED)
|
2636
|
-
@files.rollback_commit(commit_sha1)
|
2637
|
-
|
2638
|
-
return false
|
2639
|
-
|
2640
|
-
end
|
2641
|
-
|
2642
|
-
|
2643
|
-
successful_deletions += successful_deletions.select {|x| not x.nil?}
|
2644
|
-
|
2645
|
-
|
2646
|
-
successful_updates = successful_updates.select {|x| not x.nil?}
|
2647
|
-
|
2648
|
-
update_count = successful_updates.size
|
2649
|
-
|
2650
|
-
rescue SignalException
|
2651
|
-
@files.rollback_commit(commit_sha1)
|
2652
|
-
say "User aborted, Rolling Back all changes.", Thor::Shell::Color::RED
|
2653
|
-
return false
|
2654
|
-
rescue => e
|
2655
|
-
@files.rollback_commit(commit_sha1)
|
2656
|
-
log_message("Exception while trying to upload, Rolling back", Thor::Shell::Color::RED)
|
2657
|
-
log_error(e)
|
2658
|
-
return false
|
2659
|
-
end
|
2660
|
-
if !result["deleted"].nil? and !result["deleted"].empty?
|
2661
|
-
update_count += result["deleted"].size
|
2662
|
-
end
|
2663
|
-
|
2664
|
-
if update_count == update_total
|
2665
|
-
res = @files.end_commit(commit_sha1, force: force, message: commit_msg)
|
2666
|
-
if (Cnvrg::CLI.is_response_success(res, false))
|
2667
|
-
# save idx
|
2668
|
-
begin
|
2669
|
-
@project.update_idx_with_files_commits!((successful_deletions + successful_updates), res["result"]["commit_time"])
|
2670
|
-
|
2671
|
-
@project.update_idx_with_commit!(commit_sha1)
|
2672
|
-
rescue => e
|
2673
|
-
@files.rollback_commit(commit_sha1)
|
2674
|
-
log_message("Couldn't commit updates, Rolling Back all changes.", Thor::Shell::Color::RED)
|
2675
|
-
log_error(e)
|
2676
|
-
return false
|
2677
|
-
|
2678
|
-
end
|
2679
|
-
image = is_project_with_docker(Dir.pwd)
|
2680
|
-
if image and image.is_docker
|
2681
|
-
image.update_image_activity(commit_sha1, nil)
|
2682
|
-
end
|
2683
|
-
|
2684
|
-
if options["verbose"]
|
2685
|
-
log_message("#{check} Done", Thor::Shell::Color::BLUE)
|
2686
|
-
if successful_updates.size > 0
|
2687
|
-
successful_updates.flatten!
|
2688
|
-
log_message("Updated:", Thor::Shell::Color::GREEN)
|
2689
|
-
suc = successful_updates.map {|x| x = Helpers.checkmark() + " " + x}
|
2690
|
-
log_message(suc.join("\n"), Thor::Shell::Color::GREEN)
|
2691
|
-
end
|
2692
|
-
if successful_deletions.size > 0
|
2693
|
-
successful_deletions.flatten!
|
2694
|
-
|
2695
|
-
log_message("Deleted:", Thor::Shell::Color::GREEN)
|
2696
|
-
del = successful_updates.map {|x| x = Helpers.checkmark() + " " + x}
|
2697
|
-
log_message(del.join("\n"), Thor::Shell::Color::GREEN)
|
2698
|
-
end
|
2699
|
-
log_message("Total of #{update_count} / #{update_total} files.", Thor::Shell::Color::GREEN)
|
2700
|
-
else
|
2701
|
-
if return_id
|
2702
|
-
print_res = {
|
2703
|
-
'success' => "true",
|
2704
|
-
'commit_sha1' => res["result"]["commit_id"]
|
2705
|
-
}
|
2706
|
-
puts JSON[print_res]
|
2707
|
-
return JSON[print_res]
|
2708
|
-
end
|
2709
|
-
if (options["sync"] or sync) and direct
|
2710
|
-
log_message("#{check} Syncing project completed successfully", Thor::Shell::Color::GREEN)
|
2711
|
-
return true
|
2712
|
-
|
2713
|
-
else
|
2714
|
-
log_message("#{check} Changes were updated successfully", Thor::Shell::Color::GREEN)
|
2715
|
-
return true
|
2716
|
-
|
2717
|
-
end
|
2718
|
-
|
2719
|
-
end
|
2720
|
-
|
2721
|
-
else
|
2722
|
-
@files.rollback_commit(commit_sha1)
|
2723
|
-
if return_id
|
2724
|
-
print_res = {
|
2725
|
-
'success' => "false",
|
2726
|
-
'message' => 'couldn\'t commit changes, Rolling Back all changes.'
|
2727
|
-
}
|
2728
|
-
puts JSON[print_res]
|
2729
|
-
else
|
2730
|
-
log_message("Error: couldn't commit changes, Rolling Back all changes.", Thor::Shell::Color::RED)
|
2731
|
-
|
2732
|
-
end
|
2733
|
-
return false
|
2734
|
-
end
|
2352
|
+
# delete
|
2353
|
+
to_upload = result["added"] + result["updated_on_local"]
|
2354
|
+
deleted = result["deleted"]
|
2355
|
+
progressbar = ProgressBar.create(:title => "Upload Progress",
|
2356
|
+
:progress_mark => '=',
|
2357
|
+
:format => "%b>>%i| %p%% %t",
|
2358
|
+
:starting_at => 0,
|
2359
|
+
:total => (to_upload.size + deleted.size),
|
2360
|
+
:autofinish => true)
|
2361
|
+
@files.upload_multiple_files(to_upload, commit_sha1, progress: progressbar)
|
2362
|
+
@files.delete_files_from_server(deleted, commit_sha1)
|
2363
|
+
progressbar.progress += deleted.size
|
2364
|
+
res = @files.end_commit(commit_sha1, force: force, message: commit_msg)
|
2365
|
+
unless Cnvrg::CLI.is_response_success(res, false)
|
2366
|
+
raise StandardError.new("Cant end commit")
|
2367
|
+
end
|
2368
|
+
# save idx
|
2369
|
+
@project.update_idx_with_files_commits!((to_upload + deleted), res["result"]["commit_time"])
|
2370
|
+
@project.update_idx_with_commit!(commit_sha1)
|
2371
|
+
if options["verbose"]
|
2372
|
+
log_message("#{check} Done", Thor::Shell::Color::BLUE)
|
2373
|
+
if successful_updates.size > 0
|
2374
|
+
successful_updates.flatten!
|
2375
|
+
log_message("Updated:", Thor::Shell::Color::GREEN)
|
2376
|
+
suc = successful_updates.map {|x| x = Helpers.checkmark() + " " + x}
|
2377
|
+
log_message(suc.join("\n"), Thor::Shell::Color::GREEN)
|
2378
|
+
end
|
2379
|
+
if successful_deletions.size > 0
|
2380
|
+
successful_deletions.flatten!
|
2381
|
+
log_message("Deleted:", Thor::Shell::Color::GREEN)
|
2382
|
+
del = successful_updates.map {|x| x = Helpers.checkmark() + " " + x}
|
2383
|
+
log_message(del.join("\n"), Thor::Shell::Color::GREEN)
|
2384
|
+
end
|
2385
|
+
log_message("Total of #{update_count} / #{update_total} files.", Thor::Shell::Color::GREEN)
|
2735
2386
|
else
|
2736
|
-
@files.rollback_commit(commit_sha1)
|
2737
2387
|
if return_id
|
2738
2388
|
print_res = {
|
2739
|
-
'success' => "
|
2740
|
-
'
|
2741
|
-
|
2389
|
+
'success' => "true",
|
2390
|
+
'commit_sha1' => res["result"]["commit_id"]
|
2742
2391
|
}
|
2743
2392
|
puts JSON[print_res]
|
2393
|
+
return JSON[print_res]
|
2394
|
+
end
|
2395
|
+
if (options["sync"] or sync) and direct
|
2396
|
+
log_message("#{check} Syncing project completed successfully", Thor::Shell::Color::GREEN)
|
2397
|
+
return true
|
2744
2398
|
else
|
2745
|
-
|
2399
|
+
log_message("#{check} Changes were updated successfully", Thor::Shell::Color::GREEN)
|
2400
|
+
return true
|
2746
2401
|
end
|
2747
|
-
return false
|
2748
|
-
|
2749
2402
|
end
|
2750
2403
|
rescue => e
|
2751
|
-
|
2752
|
-
|
2753
|
-
|
2754
|
-
|
2755
|
-
|
2756
|
-
|
2757
|
-
|
2758
|
-
rescue SignalException
|
2759
|
-
|
2760
|
-
say "\nAborting", Thor::Shell::Color::BLUE
|
2761
|
-
say "\nRolling back all changes", Thor::Shell::Color::BLUE
|
2404
|
+
if e.is_a? SignalException
|
2405
|
+
say "\nAborting", Thor::Shell::Color::BLUE
|
2406
|
+
say "\nRolling back all changes", Thor::Shell::Color::BLUE
|
2407
|
+
else
|
2408
|
+
log_message("Error occurred, \nAborting", Thor::Shell::Color::RED)
|
2409
|
+
log_error(e)
|
2410
|
+
end
|
2762
2411
|
@files.rollback_commit(commit_sha1) unless commit_sha1.nil?
|
2412
|
+
print_res = {
|
2413
|
+
'success' => "false",
|
2414
|
+
'message' => 'couldn\'t commit changes, Rolling Back all changes.'
|
2415
|
+
}
|
2416
|
+
puts JSON[print_res] if return_id
|
2763
2417
|
return false
|
2764
2418
|
end
|
2765
|
-
|
2766
2419
|
end
|
2420
|
+
|
2767
2421
|
desc 'download_file_data', 'Download one data files'
|
2768
2422
|
method_option :verbose, :type => :boolean, :aliases => ["-v", "--verbose"], :default => false
|
2769
2423
|
method_option :commit, :type => :string, :aliases => ["-c", "--commit"], :desc => "download specified commit", :default => nil
|
@@ -2848,9 +2502,11 @@ module Cnvrg
|
|
2848
2502
|
end
|
2849
2503
|
result = res["result"]["tree"]
|
2850
2504
|
commit = res["result"]["commit"]
|
2505
|
+
can_commit = res["result"]["can_commit"] || false #can commit means that our next commit is newer than the latest commit
|
2506
|
+
# so if can_commit is true it means that we have to be up-to-date with the dataset.
|
2851
2507
|
update_total = [result['added'], result["updated_on_server"], result["conflicts"], result["deleted"]].compact.flatten.size
|
2852
2508
|
successful_changes = 0
|
2853
|
-
if update_total == 0
|
2509
|
+
if update_total == 0 or can_commit
|
2854
2510
|
log_message("Dataset is up to date", Thor::Shell::Color::GREEN) if !sync
|
2855
2511
|
return true
|
2856
2512
|
elsif options["verbose"]
|
@@ -2858,6 +2514,8 @@ module Cnvrg
|
|
2858
2514
|
else
|
2859
2515
|
log_message("Syncing Dataset", Thor::Shell::Color::BLUE, !sync)
|
2860
2516
|
end
|
2517
|
+
Cnvrg::Logger.log_info("Current commit: #{@dataset.get_current_commit}, destination commit: #{commit}")
|
2518
|
+
Cnvrg::Logger.log_info("Compare idx res: #{result}")
|
2861
2519
|
conflicts = @files.mark_conflicts(result)
|
2862
2520
|
|
2863
2521
|
log_message("Found some conflicts, check .conflict files.", Thor::Shell::Color::BLUE) if conflicts > 0
|
@@ -2887,12 +2545,13 @@ module Cnvrg
|
|
2887
2545
|
end
|
2888
2546
|
return true
|
2889
2547
|
end
|
2890
|
-
rescue SignalException
|
2548
|
+
rescue SignalException => e
|
2549
|
+
Cnvrg::Logger.log_error(e)
|
2891
2550
|
say "\nAborting", Thor::Shell::Color::BLUE
|
2892
2551
|
exit(1)
|
2893
2552
|
rescue => e
|
2894
2553
|
log_message("Error occurred, \nAborting", Thor::Shell::Color::BLUE)
|
2895
|
-
log_error(e)
|
2554
|
+
Cnvrg::Logger.log_error(e)
|
2896
2555
|
exit(1)
|
2897
2556
|
end
|
2898
2557
|
end
|
@@ -2949,7 +2608,7 @@ module Cnvrg
|
|
2949
2608
|
log_start(__method__, args, options)
|
2950
2609
|
project_home = get_project_home
|
2951
2610
|
@project = Project.new(project_home)
|
2952
|
-
@files = Cnvrg::Files.new(@project.owner, @project.slug)
|
2611
|
+
@files = Cnvrg::Files.new(@project.owner, @project.slug, project_home: project_home)
|
2953
2612
|
git = options["git"]
|
2954
2613
|
commit = options["commit"]
|
2955
2614
|
if git or @project.is_git
|
@@ -2971,174 +2630,89 @@ module Cnvrg
|
|
2971
2630
|
log_message("Couldn't append new ignore files to .cnvrgignore", Thor::Shell::Color::YELLOW)
|
2972
2631
|
end
|
2973
2632
|
new_branch = options["new_branch"] || @project.is_branch || false
|
2974
|
-
res = @project.compare_idx(new_branch,
|
2633
|
+
res = @project.compare_idx(new_branch, in_exp: in_exp, download: true)["result"]
|
2975
2634
|
result = res["tree"]
|
2976
2635
|
|
2977
2636
|
commit = res["commit"]
|
2978
|
-
|
2637
|
+
|
2638
|
+
#here im grouping the files by their current status.
|
2639
|
+
#
|
2640
|
+
# all the files that changed in the server (added + updated)
|
2641
|
+
changed_files = result['updated_on_server'] + result['added']
|
2642
|
+
|
2643
|
+
# non-conflicted files, all the files that changed remotely but not locally
|
2644
|
+
updated_files = changed_files - result["update_local"]
|
2645
|
+
# conflicted - files that changed remotely and locally
|
2646
|
+
conflicted_files = changed_files & result["update_local"]
|
2647
|
+
|
2648
|
+
# all deleted files
|
2649
|
+
all_deleted = result['deleted']
|
2650
|
+
# cant delete files - files that deleted on the server but changed locally
|
2651
|
+
conflicted_deleted = all_deleted & result["update_local"]
|
2652
|
+
# files to delete - files that deleted on the server and unchanged locally
|
2653
|
+
deleted_files = all_deleted - conflicted_deleted
|
2654
|
+
|
2655
|
+
|
2656
|
+
update_total = [all_deleted, changed_files ].flatten.size
|
2657
|
+
|
2658
|
+
if update_total < 1
|
2979
2659
|
if !@project.last_local_commit.eql? commit
|
2660
|
+
Cnvrg::Logger.log_info("Finish commit, updating idx with commit")
|
2980
2661
|
@project.update_idx_with_commit!(commit)
|
2981
2662
|
end
|
2982
2663
|
log_message("Project is up to date", Thor::Shell::Color::GREEN, ((options["sync"] or sync) ? false : true))
|
2983
2664
|
return true
|
2984
2665
|
end
|
2985
|
-
|
2986
|
-
|
2666
|
+
Cnvrg::Logger.log_info("Got #{update_total} changes from server")
|
2987
2667
|
|
2988
2668
|
successful_changes = []
|
2989
2669
|
if update_total == 1
|
2990
2670
|
log_message("Downloading #{update_total} file", Thor::Shell::Color::BLUE, !options["sync"])
|
2991
|
-
elsif update_total == 0
|
2992
|
-
log_message("Project is up to date", Thor::Shell::Color::GREEN, !options["sync"])
|
2993
|
-
return true
|
2994
2671
|
elsif options["verbose"]
|
2995
2672
|
log_message("Downloading #{update_total} files", Thor::Shell::Color::BLUE)
|
2996
2673
|
else
|
2997
2674
|
log_message("Syncing files", Thor::Shell::Color::BLUE, !options["sync"])
|
2998
|
-
|
2999
2675
|
end
|
3000
|
-
parallel_options = {
|
3001
|
-
:progress => {
|
3002
|
-
:title => "Download Progress",
|
3003
|
-
:progress_mark => '=',
|
3004
|
-
:format => "%b>>%i| %p%% %t",
|
3005
|
-
:starting_at => 0,
|
3006
|
-
:total => result["updated_on_server"].size,
|
3007
|
-
:autofinish => true
|
3008
|
-
},
|
3009
|
-
in_processes: ParallelProcesses,
|
3010
|
-
in_thread: ParallelThreads
|
3011
|
-
}
|
3012
|
-
if !result["conflicts"].empty?
|
3013
|
-
begin
|
3014
|
-
|
3015
|
-
|
3016
|
-
conflicts_result = Parallel.map(result["conflicts"], in_processes: ParallelProcesses, in_thread: ParallelThreads) do |f|
|
3017
|
-
|
3018
|
-
relative_path = f.gsub(/^#{@project.local_path}/, "")
|
3019
|
-
log_message("downloading: #{f}.conflict", Thor::Shell::Color::BLUE, options["verbose"])
|
3020
|
-
if relative_path.eql? ".cnvrgignore"
|
3021
|
-
if @files.download_file_s3(f, relative_path, project_home, commit_sha1 = nil, conflict = false)
|
3022
|
-
f
|
3023
|
-
else
|
3024
|
-
log_message("Couldn't download: #{f}", Thor::Shell::Color::RED)
|
3025
|
-
raise Parallel::Kill
|
3026
|
-
end
|
3027
|
-
else
|
3028
|
-
if @files.download_file_s3(f, relative_path, project_home, commit_sha1 = nil, conflict = true)
|
3029
|
-
f
|
3030
|
-
else
|
3031
|
-
log_message("Couldn't download: #{f}", Thor::Shell::Color::RED)
|
3032
|
-
raise Parallel::Kill
|
3033
|
-
|
3034
|
-
end
|
3035
|
-
end
|
3036
|
-
end
|
3037
|
-
rescue Interrupt
|
3038
|
-
|
3039
|
-
log_message("Couldn't download, Rolling Back all changes.", Thor::Shell::Color::RED)
|
3040
|
-
|
3041
|
-
@files.revoke_download(result["conflicts"], [])
|
3042
|
-
exit(1)
|
3043
|
-
end
|
3044
|
-
end
|
3045
|
-
|
3046
|
-
|
3047
|
-
successful_changes += conflicts_result.to_a
|
3048
|
-
if !result["updated_on_server"].empty?
|
3049
|
-
begin
|
3050
|
-
updated_on_server_result = Parallel.map(result["updated_on_server"], parallel_options) do |f|
|
3051
|
-
|
3052
|
-
relative_path = f.gsub(/^#{@project.local_path}/, "")
|
3053
|
-
if f.end_with? "/"
|
3054
|
-
# dir
|
3055
|
-
log_message("downloading dir: #{f}", Thor::Shell::Color::BLUE, options["verbose"])
|
3056
|
-
|
3057
|
-
if @files.download_dir(f, relative_path, project_home)
|
3058
|
-
f
|
3059
|
-
else
|
3060
|
-
log_message("Couldn't create directory: #{f}", Thor::Shell::Color::RED)
|
3061
|
-
raise Parallel::Kill
|
3062
|
-
|
3063
|
-
|
3064
|
-
end
|
3065
|
-
|
3066
|
-
else
|
3067
|
-
# blob
|
3068
|
-
log_message("downloading file: #{f}", Thor::Shell::Color::BLUE, options["verbose"])
|
3069
|
-
if @files.download_file_s3(f, relative_path, project_home)
|
3070
|
-
f
|
3071
|
-
else
|
3072
|
-
|
3073
|
-
|
3074
|
-
log_message("Couldn't download: #{f}", Thor::Shell::Color::RED)
|
3075
|
-
raise Parallel::Kill
|
3076
|
-
|
3077
|
-
|
3078
|
-
end
|
3079
|
-
end
|
3080
|
-
|
3081
|
-
|
3082
|
-
end
|
3083
|
-
successful_changes += updated_on_server_result.to_a
|
3084
|
-
rescue Interrupt
|
3085
|
-
log_message("Couldn't download, Rolling Back all changes.", Thor::Shell::Color::RED)
|
3086
|
-
|
3087
|
-
@files.revoke_download(result["conflicts"], result["updated_on_server"])
|
3088
|
-
exit(1)
|
3089
|
-
|
3090
|
-
end
|
3091
|
-
end
|
3092
|
-
|
3093
|
-
deleted = result["deleted"].to_a
|
3094
|
-
delete_res = @files.delete_commit_files_local(deleted)
|
3095
|
-
if !delete_res
|
3096
|
-
log_message("Couldn't delete #{deleted.join(" ")}", Thor::Shell::Color::RED)
|
3097
|
-
log_message("Couldn't download, Rolling Back all changes.", Thor::Shell::Color::RED)
|
3098
|
-
|
3099
|
-
@files.revoke_download(result["conflicts"], result["updated_on_server"])
|
3100
|
-
exit(1)
|
3101
|
-
|
3102
|
-
end
|
3103
|
-
successful_changes += deleted
|
3104
2676
|
|
2677
|
+
progressbar = ProgressBar.create(:title => "Download Progress",
|
2678
|
+
:progress_mark => '=',
|
2679
|
+
:format => "%b>>%i| %p%% %t",
|
2680
|
+
:starting_at => 0,
|
2681
|
+
:total => update_total,
|
2682
|
+
:autofinish => true)
|
3105
2683
|
|
3106
|
-
successful_changes = successful_changes.select {|x| not x.nil?}
|
3107
2684
|
|
3108
|
-
|
3109
|
-
|
3110
|
-
@project.update_idx_with_commit!(commit)
|
3111
|
-
check = Helpers.checkmark()
|
2685
|
+
Cnvrg::Logger.log_info("Downloading updated files:#{updated_files.join(",")}")
|
2686
|
+
@files.download_files(updated_files, commit, progress: progressbar) if updated_files.present?
|
3112
2687
|
|
3113
|
-
|
3114
|
-
|
3115
|
-
log_message(successful_changes.join("\n"), Thor::Shell::Color::GREEN)
|
3116
|
-
log_message("Total of #{successful_changes.size} / #{update_total} files.", Thor::Shell::Color::GREEN)
|
3117
|
-
else
|
3118
|
-
log_message("#{check} Downloaded changes successfully", Thor::Shell::Color::GREEN, ((sync or options["sync"]) ? false : true))
|
3119
|
-
end
|
2688
|
+
Cnvrg::Logger.log_info("Downloading conflicted files:#{conflicted_files.join(",")}")
|
2689
|
+
@files.download_files(conflicted_files, commit, postfix: ".conflict", progress: progressbar) if conflicted_files.present?
|
3120
2690
|
|
2691
|
+
Cnvrg::Logger.log_info("Delete files: #{deleted_files.join(",")}")
|
2692
|
+
@files.delete_files_local(deleted_files, conflicted: conflicted_deleted, progress: progressbar)
|
3121
2693
|
|
2694
|
+
# update idx with latest commit
|
2695
|
+
@project.update_idx_with_commit!(commit)
|
2696
|
+
#TODO Sync, remove idx, sync again and pray
|
2697
|
+
check = Helpers.checkmark()
|
2698
|
+
Cnvrg::Logger.log_info("Finished downloading successfuly")
|
2699
|
+
if options["verbose"]
|
2700
|
+
log_message("#{check} Done, Downloaded:", Thor::Shell::Color::GREEN)
|
2701
|
+
log_message(successful_changes.join("\n"), Thor::Shell::Color::GREEN)
|
2702
|
+
log_message("Total of #{successful_changes.size} / #{update_total} files.", Thor::Shell::Color::GREEN)
|
2703
|
+
else
|
2704
|
+
log_message("#{check} Downloaded changes successfully", Thor::Shell::Color::GREEN, ((sync or options["sync"]) ? false : true))
|
3122
2705
|
end
|
3123
2706
|
rescue => e
|
3124
|
-
|
3125
2707
|
log_message("Error occurred, \nAborting", Thor::Shell::Color::BLUE)
|
3126
|
-
log_error(e)
|
3127
|
-
|
3128
|
-
|
3129
|
-
|
3130
|
-
|
3131
|
-
@files.revoke_download(result["conflicts"], result["updated_on_server"])
|
3132
|
-
end
|
2708
|
+
Cnvrg::Logger.log_error(e)
|
2709
|
+
exit(1)
|
2710
|
+
rescue Exception => e
|
2711
|
+
Cnvrg::Logger.log_error(e)
|
2712
|
+
log_message("Error occurred, \nAborting", Thor::Shell::Color::BLUE)
|
3133
2713
|
exit(1)
|
3134
2714
|
rescue SignalException
|
3135
|
-
|
3136
|
-
if successful_changes.nil?
|
3137
|
-
exit(1)
|
3138
|
-
end
|
3139
|
-
begin
|
3140
|
-
@files.revoke_download(result["conflicts"], result["updated_on_server"])
|
3141
|
-
end
|
2715
|
+
log_message("\nAborting", Thor::Shell::Color::BLUE)
|
3142
2716
|
exit(1)
|
3143
2717
|
end
|
3144
2718
|
end
|
@@ -3168,7 +2742,24 @@ module Cnvrg
|
|
3168
2742
|
resolver = resp['result']['resolver']
|
3169
2743
|
latest = resp['result']['latest']
|
3170
2744
|
commit = resp['result']['commit']
|
3171
|
-
|
2745
|
+
updated_files = compare['updated_on_server']
|
2746
|
+
conflicted_files = compare['conflicts']
|
2747
|
+
deleted_files = compare['deleted']
|
2748
|
+
overall_changes = [updated_files, conflicted_files, deleted_files].flatten.size
|
2749
|
+
|
2750
|
+
|
2751
|
+
progressbar = ProgressBar.create(:title => "Download Progress",
|
2752
|
+
:progress_mark => '=',
|
2753
|
+
:format => "%b>>%i| %p%% %t",
|
2754
|
+
:starting_at => 0,
|
2755
|
+
:total => overall_changes,
|
2756
|
+
:autofinish => true)
|
2757
|
+
|
2758
|
+
@files.download_files(updated_files, commit_sha1, progress: progressbar)
|
2759
|
+
@files.download_files(conflicted_files, commit_sha1, progress: progressbar, postfix: '.conflicted')
|
2760
|
+
@files.delete_files_local(deleted_files, progress: progressbar)
|
2761
|
+
|
2762
|
+
|
3172
2763
|
@project.set_on_branch(latest)
|
3173
2764
|
@project.update_idx_with_commit!(commit)
|
3174
2765
|
@project.generate_idx
|
@@ -3326,9 +2917,10 @@ module Cnvrg
|
|
3326
2917
|
job_slug = options['job_slug']
|
3327
2918
|
job_type = options['job_type']
|
3328
2919
|
in_exp = options["in_exp"] || (job_slug.present? and job_type.present?)
|
2920
|
+
in_exp = false if job_type.present? and job_type == "NotebookSession"
|
3329
2921
|
run_download = true
|
3330
2922
|
if options[:force] or options[:files].present? or options[:output_dir].present? or in_exp
|
3331
|
-
run_download =false
|
2923
|
+
run_download = false
|
3332
2924
|
end
|
3333
2925
|
if run_download
|
3334
2926
|
invoke :download, [true, "", in_exp ], :new_branch => options["new_branch"], :verbose => options["verbose"], :sync => true
|
@@ -3336,8 +2928,6 @@ module Cnvrg
|
|
3336
2928
|
invoke :upload, [false, true, direct, "",in_exp,options[:force], options["output_dir"],job_type, job_slug ], :new_branch => options["new_branch"], :verbose => options["verbose"], :sync => true,
|
3337
2929
|
:ignore => options[:ignore], :force => options[:force], :message => options[:message], :deploy => options["deploy"], :return_id => options["return_id"],
|
3338
2930
|
:files => options["files"], :output_dir => options["output_dir"], :job_slug => job_slug, :job_type => job_type
|
3339
|
-
|
3340
|
-
|
3341
2931
|
end
|
3342
2932
|
|
3343
2933
|
desc 'run cmd', 'Runs an experiment'
|
@@ -3371,7 +2961,7 @@ module Cnvrg
|
|
3371
2961
|
method_option :data_query, :type => :string, :aliases => ["-q", "--query"], :default => nil
|
3372
2962
|
method_option :git_commit, :type => :string, :aliases => [ "--git_commit"], :default => nil
|
3373
2963
|
method_option :git_branch, :type => :string, :aliases => [ "--git_branch"], :default => nil
|
3374
|
-
method_option :restart_if_stuck, :type => :boolean, :aliases => ["--restart"], :default => nil
|
2964
|
+
method_option :restart_if_stuck, :type => :boolean, :aliases => ["--restart","--restart_if_stuck"], :default => nil
|
3375
2965
|
method_option :local_folders, :type => :string, :aliases => ["--local_folders"], :default => nil
|
3376
2966
|
|
3377
2967
|
def run(*cmd)
|
@@ -3413,6 +3003,7 @@ module Cnvrg
|
|
3413
3003
|
git_branch = options["git_branch"]
|
3414
3004
|
restart_if_stuck = options["restart_if_stuck"]
|
3415
3005
|
|
3006
|
+
|
3416
3007
|
options_hash = Hash[options]
|
3417
3008
|
|
3418
3009
|
if local
|
@@ -3786,6 +3377,7 @@ module Cnvrg
|
|
3786
3377
|
method_option :local_folders, :type => :string, :aliases => ["--local_folders"], :default => nil
|
3787
3378
|
|
3788
3379
|
def exec_remote(*cmd)
|
3380
|
+
|
3789
3381
|
verify_logged_in(true)
|
3790
3382
|
log_start(__method__, args, options)
|
3791
3383
|
working_dir = is_cnvrg_dir
|
@@ -3852,7 +3444,7 @@ module Cnvrg
|
|
3852
3444
|
git_branch = options["git_branch"]
|
3853
3445
|
options_hash = Hash[options]
|
3854
3446
|
local_folders_options = options["local_folders"]
|
3855
|
-
options_hash.except!("schedule", "machine_type", "image", "upload_output", "grid", "data", "data_commit",
|
3447
|
+
options_hash.except!("schedule", "machine_type", "image", "upload_output", "grid", "data", "data_commit", "title",
|
3856
3448
|
"local", "small", "medium", "large", "gpu", "gpuxl", "gpuxxl","max_time","dataset_only_tree",
|
3857
3449
|
"data_query", "git_commit","git_branch", "restart_if_stuck","local_folders" )
|
3858
3450
|
exec_options = options_hash.map {|x| "--#{x[0]}=#{x[1]}"}.flatten.join(" ")
|
@@ -5909,33 +5501,15 @@ module Cnvrg
|
|
5909
5501
|
say message, type
|
5910
5502
|
end
|
5911
5503
|
begin
|
5912
|
-
|
5913
|
-
$LOG.info message: message, type: "info"
|
5914
|
-
elsif type == Thor::Shell::Color::RED
|
5915
|
-
$LOG.error message: message, type: "error"
|
5916
|
-
elsif type == Thor::Shell::Color::YELLOW
|
5917
|
-
$LOG.warn message: message, type: "warning"
|
5918
|
-
elsif type == Thor::Shell::Color::GREEN
|
5919
|
-
$LOG.info message: message, type: "success"
|
5920
|
-
else
|
5921
|
-
$LOG.info message: message, type: "unknown"
|
5922
|
-
end
|
5923
|
-
|
5504
|
+
Cnvrg::Logger.log_info(message)
|
5924
5505
|
rescue => e
|
5925
|
-
|
5506
|
+
Cnvrg::Logger.log_error(e)
|
5926
5507
|
end
|
5927
5508
|
end
|
5928
5509
|
|
5929
5510
|
def log_error(e)
|
5930
5511
|
begin
|
5931
|
-
|
5932
|
-
size = e.backtrace.size
|
5933
|
-
min = 10
|
5934
|
-
if min >= size
|
5935
|
-
min = size
|
5936
|
-
end
|
5937
|
-
$LOG.error message: "Error: #{e.message}, Backtrace: #{e.backtrace[0..min].join(",")}", type: "error"
|
5938
|
-
rescue
|
5512
|
+
Cnvrg::Logger.log_error(e)
|
5939
5513
|
end
|
5940
5514
|
end
|
5941
5515
|
|
@@ -5952,6 +5526,7 @@ module Cnvrg
|
|
5952
5526
|
end
|
5953
5527
|
|
5954
5528
|
def self.is_response_success(response, should_exit = true)
|
5529
|
+
|
5955
5530
|
begin
|
5956
5531
|
if response.nil? or !response
|
5957
5532
|
# if !Cnvrg::Helpers.internet_connection?
|
@@ -5965,7 +5540,7 @@ module Cnvrg
|
|
5965
5540
|
return false
|
5966
5541
|
end
|
5967
5542
|
elsif response["status"] != 200
|
5968
|
-
error = response['message']
|
5543
|
+
error = response['message'] || "Unknown error"
|
5969
5544
|
# Cnvrg::CLI.log_end(1, error)
|
5970
5545
|
if response["status"] == 500
|
5971
5546
|
say("<%= color('Server Error', RED) %>")
|
@@ -6027,6 +5602,10 @@ module Cnvrg
|
|
6027
5602
|
end
|
6028
5603
|
|
6029
5604
|
def get_project_home
|
5605
|
+
return Cnvrg::CLI.get_project_home
|
5606
|
+
end
|
5607
|
+
|
5608
|
+
def self.get_project_home
|
6030
5609
|
absolute_path = Dir.pwd
|
6031
5610
|
dirs = absolute_path.split("/")
|
6032
5611
|
dirs.pop while not Dir.exists?("#{dirs.join("/")}/.cnvrg") and dirs.size != 0
|
@@ -6093,24 +5672,9 @@ module Cnvrg
|
|
6093
5672
|
$LOG = LogStashLogger.new(type: :file, path: logfile, sync: true, config: config)
|
6094
5673
|
remove_old_log_files()
|
6095
5674
|
rescue
|
6096
|
-
|
6097
5675
|
end
|
6098
5676
|
end
|
6099
5677
|
|
6100
|
-
def remove_old_log_files()
|
6101
|
-
begin
|
6102
|
-
last_week = (Time.now - (7 * 24 * 60 * 60)).strftime("%Y-%m-%d")
|
6103
|
-
home = File.expand_path('~')
|
6104
|
-
log_files = Dir["#{home}/.cnvrg/tmp/*.log"]
|
6105
|
-
log_files.each do |l|
|
6106
|
-
if File.mtime(l).strftime("%Y-%m-%d") < last_week
|
6107
|
-
FileUtils.rm_rf(l)
|
6108
|
-
end
|
6109
|
-
end
|
6110
|
-
end
|
6111
|
-
|
6112
|
-
end
|
6113
|
-
|
6114
5678
|
def verify_logged_in(in_dir=true)
|
6115
5679
|
begin
|
6116
5680
|
log_handler()
|