Class: Cnvrg::Dataset

Inherits:
Object
  • Object
show all
Defined in:
lib/cnvrg/dataset.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_home) ⇒ Dataset

Returns a new instance of Dataset.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cnvrg/dataset.rb', line 10

def initialize(project_home)
  begin
    config = YAML.load_file(project_home+"/.cnvrg/config.yml")
    @local_path = project_home
    @title = config[:dataset_name]
    @slug = config[:dataset_slug]
    @owner = config[:owner]
    @working_dir = project_home
  rescue => e

  end
end

Instance Attribute Details

#local_pathObject (readonly)

Returns the value of attribute local_path.



4
5
6
# File 'lib/cnvrg/dataset.rb', line 4

def local_path
  @local_path
end

#ownerObject (readonly)

Returns the value of attribute owner.



4
5
6
# File 'lib/cnvrg/dataset.rb', line 4

def owner
  @owner
end

#slugObject (readonly)

Returns the value of attribute slug.



4
5
6
# File 'lib/cnvrg/dataset.rb', line 4

def slug
  @slug
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/cnvrg/dataset.rb', line 4

def title
  @title
end

#working_dirObject (readonly)

Returns the value of attribute working_dir.



4
5
6
# File 'lib/cnvrg/dataset.rb', line 4

def working_dir
  @working_dir
end

Class Method Details

.blank_clone(owner, dataset_name, dataset_slug) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/cnvrg/dataset.rb', line 201

def self.blank_clone(owner, dataset_name, dataset_slug)
  list_dirs = [".cnvrg"
  ]
  list_files = [
      ".cnvrg/config.yml"
  ]
  create_ignore = false
  if !File.exist? ".cnvrgignore"
    list_files << ".cnvrgignore"
    create_ignore  = true
  end


  cnvrgignore = Helpers.cnvrgignore_content
  begin

    config = {dataset_name: dataset_name,
              dataset_slug: dataset_slug,
              owner: owner}

    FileUtils.mkdir_p list_dirs
    FileUtils.touch list_files
    File.open(".cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
    File.open(".cnvrgignore", "w+") { |f| f.write cnvrgignore } unless !create_ignore
  rescue => e
    return false
  end
  return true
end

.clone(owner, dataset_name, dataset_slug) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/cnvrg/dataset.rb', line 238

def self.clone(owner, dataset_name, dataset_slug)

  begin
    list_dirs = [ dataset_name, "#{dataset_name}/.cnvrg"
    ]
    list_files = [
        "#{dataset_name}/.cnvrg/config.yml"
    ]

    config = {dataset_name: dataset_name,
              dataset_slug: dataset_slug,
              owner: owner}


    FileUtils.mkdir_p list_dirs
    FileUtils.touch list_files
    File.open("#{dataset_name}/.cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
  rescue => e
    puts "Exception in clone request:#{e.message}"
    return false
  end
  return true
end

.delete(dataset_slug, owner) ⇒ Object



24
25
26
27
# File 'lib/cnvrg/dataset.rb', line 24

def self.delete(dataset_slug,owner)
  response = Cnvrg::API.request("users/#{owner}/datasets/#{dataset_slug}/delete", 'DELETE')
  return response
end

.init(owner, dataset_name, is_public = false) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/cnvrg/dataset.rb', line 166

def self.init(owner, dataset_name, is_public=false)
    list_dirs = [".cnvrg"
    ]
    list_files = [
        ".cnvrg/config.yml"
    ]
    create_ignore = false
    if !File.exist? ".cnvrgignore"
      list_files << ".cnvrgignore"
      create_ignore  = true
    end


    cnvrgignore = Helpers.cnvrgignore_content
    begin
        response = Cnvrg::API.request("cli/create_dataset", 'POST', {title: dataset_name, owner: owner, is_public: is_public})
        Cnvrg::CLI.is_response_success(response)
      response = JSON.parse response["result"]
      dataset_slug = response["slug"]

      config = {dataset_name: dataset_name,
                dataset_slug: dataset_slug,
                owner: owner}

      FileUtils.mkdir_p list_dirs
      FileUtils.touch list_files
      File.open(".cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
      File.open(".cnvrgignore", "w+") { |f| f.write cnvrgignore } unless !create_ignore
    rescue => e
      return false
    end
    return true
end

.init_container(owner, dataset_slug, dataset_name) ⇒ Object



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/cnvrg/dataset.rb', line 262

def self.init_container(owner, dataset_slug,dataset_name)

  cnvrgignore = Helpers.cnvrgignore_content
  begin
    list_dirs = [ ".cnvrg"
    ]
    list_files = [
        ".cnvrgignore",
        ".cnvrg/config.yml"
    ]
    FileUtils.mkdir_p list_dirs
    FileUtils.touch list_files

    config = {dataset_name: dataset_name,
              dataset_slug: dataset_slug,
              owner: owner}
    File.open(".cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }

    File.open(".cnvrgignore", "w+") { |f| f.write cnvrgignore } unless File.exist? ".cnvrgignore"
  rescue => e
    return false
  end
  return true
end

.verify_cnvrgignore_exist(dataset_name, remote) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/cnvrg/dataset.rb', line 103

def self.verify_cnvrgignore_exist(dataset_name,remote)
  path = ".cnvrgignore"
  if !File.exist? path
    path = "#{dataset_name}/.cnvrgignore"
  end
  ignore_exits = File.exist? path
  if !ignore_exits
    begin
      list_files = [
          path
      ]
      FileUtils.touch list_files
      cnvrgignore = Helpers.cnvrgignore_content
      File.open(path, "w+") { |f| f.write cnvrgignore }
    rescue => e
      return false
    end

  end
end

Instance Method Details

#clone(commit) ⇒ Object



232
233
234
235
236
# File 'lib/cnvrg/dataset.rb', line 232

def clone( commit)


  return response
end

#compare_commit(commit) ⇒ Object



510
511
512
513
514
515
516
517
518
# File 'lib/cnvrg/dataset.rb', line 510

def compare_commit(commit)
  if commit.nil? or commit.empty?
    commit = last_local_commit
  end
  response = Cnvrg::API.request("users/#{self.owner}/projects/#{self.slug}/commit/compare", 'POST', {current_commit: commit})
  CLI.is_response_success(response,false)
  update_is_new_branch(response["result"]["new_branch"])
  return response["result"]["new_branch"]
end

#compare_commits(commit) ⇒ Object



466
467
468
469
470
# File 'lib/cnvrg/dataset.rb', line 466

def compare_commits(commit)
  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/compare_commits", 'POST', {compare_commit: commit,current_commit:last_local_commit})
  CLI.is_response_success(response,false)
  return response
end

#compare_idx(new_branch, commit = last_local_commit, local_idx = nil, force = false, next_commit = nil) ⇒ Object



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'lib/cnvrg/dataset.rb', line 399

def compare_idx(new_branch, commit=last_local_commit,local_idx=nil,force = false, next_commit = nil)
  if local_idx.nil?
    local_idx =  self.generate_idx
  end
  ignore_list = self.get_ignore_list()
  if force
    added = []
    if local_idx[:tree]
      added << local_idx[:tree].keys
      added.flatten!
    end

    response ={"result"=> {"commit"=>next_commit,"tree"=> {"added"=> added,
                                                   "updated_on_server"=> [],
                                                   "updated_on_local"=> [],
                                                   "deleted"=> [],
                                                   "conflicts"=> []} } }
    return response

  end
  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/status", 'POST', {idx: local_idx, new_branch: new_branch, current_commit: commit, ignore:ignore_list, next_commit: next_commit})
  CLI.is_response_success(response,false)
  return response
end

#compare_idx_download(commit = last_local_commit, local_idx = nil, all = false) ⇒ Object



423
424
425
426
427
428
429
430
431
# File 'lib/cnvrg/dataset.rb', line 423

def compare_idx_download(commit=last_local_commit,local_idx=nil,all=false)
  if local_idx.nil?
    local_idx =  self.generate_idx
  end
  ignore_list = self.send_ignore_list()
  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/download_status", 'POST', {idx: local_idx,  current_commit: commit, ignore:ignore_list,all_files:all})
  CLI.is_response_success(response,false)
  return response
end

#create_volumeObject



388
389
390
391
392
# File 'lib/cnvrg/dataset.rb', line 388

def create_volume
  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/volumes/create", 'POST')
  CLI.is_response_success(response)
  return response
end

#current_status(new_branch) ⇒ Object



432
433
434
435
436
437
# File 'lib/cnvrg/dataset.rb', line 432

def current_status(new_branch)
    commit=last_local_commit
    response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/status_current", 'POST', {current_commit: commit,new_branch: new_branch})
    CLI.is_response_success(response,true)
    return response
end

#download_tags_yamlObject



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/cnvrg/dataset.rb', line 68

def download_tags_yaml
  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/tags_yml", 'GET')
  CLI.is_response_success(response)
  begin
    path = self.working_dir
    File.open("#{path}/#{response["results"]["filename"]}", "w+") { |f| f.write response["results"]["file_content"] }
    return true
  rescue
    return false
  end
end

#download_updated_data(current_commit) ⇒ Object



394
395
396
397
398
# File 'lib/cnvrg/dataset.rb', line 394

def download_updated_data(current_commit)
  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/download_updated_data", 'POST', {current_commit: current_commit})
  CLI.is_response_success(response,false)
  return response
end

#generate_chunked_idx(list_files = [], threads: IDXParallelThreads) ⇒ Object



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/cnvrg/dataset.rb', line 295

def generate_chunked_idx(list_files=[], threads: IDXParallelThreads)
  tree = {}
  Parallel.map(list_files, in_threads: IDXParallelThreads) do |file|
    label = file.gsub(self.local_path + "/", "")
    if File.directory? file
      tree[label+"/"] = nil
    else
      sha1 =  OpenSSL::Digest::SHA1.file(file).hexdigest
      file_name = File.basename file
      file_size = File.size(file).to_f
      mime_type = MimeMagic.by_path(file)
      content_type = !(mime_type.nil? or mime_type.text?) ? mime_type.type : "text/plain"
      relative_path = file.gsub(/^#{@local_path + "/"}/, "")
      tree[label] = {sha1: sha1, file_name: file_name, file_size: file_size, content_type: content_type, absolute_path: file, relative_path: relative_path}
    end
  end
  return tree
end

#generate_idx(show_progress = false) ⇒ Object



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# File 'lib/cnvrg/dataset.rb', line 329

def generate_idx(show_progress=false)
  if File.exists? "#{self.local_path}/.cnvrg/idx.yml"
    old_idx = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
  else
    old_idx = nil
  end
  tree_idx = Hash.new(0)
  list = Dir.glob("#{self.local_path}/**/*", File::FNM_DOTMATCH).reject { |x| (x =~ /\/\.{1,2}$/) or (x =~ /^#{self.local_path}\/\.cnvrg\/*/) or (x =~/^#{self.local_path}\/\.cnvrgignore.conflict*/) and not (x =~/^#{self.local_path}\/\.cnvrgignore/) }
  list_ignore = self.get_ignore_list()
  if show_progress
    parallel_options = {
        :progress => {
            :title => "Checking Dataset",
            :progress_mark => '=',
            :format => "%b>>%i| %p%% %t",
            :starting_at => 0,
            :total => (list).size,
            :autofinish => true
        },
        in_threads: IDXParallelThreads,
        isolation: true
    }
  else
    parallel_options = {
        in_threads: IDXParallelThreads,
        isolation: true
    }
  end

  Parallel.map(list, parallel_options ) do |e|
    label = e.gsub(self.local_path + "/", "")
    if File.directory? e
      if list_ignore.include? label
        next
      end
      tree_idx[label+"/"] = nil
    else
      if list_ignore.include? label
        next
      end
      sha1 =  OpenSSL::Digest::SHA1.file(e).hexdigest
      if old_idx.nil? or old_idx.to_h["tree"].nil?
        tree_idx[label] = {sha1: sha1, commit_time: nil}
      elsif old_idx["tree"][label].nil? or old_idx["tree"][label]["sha1"] != sha1
        tree_idx[label] = {sha1: sha1, commit_time: nil}
      else
        tree_idx[label] = old_idx["tree"][label]
      end
    end
  end
  if !old_idx.nil? and !old_idx[:next_commit].nil? and  !old_idx[:next_commit].empty?
    idx = {commit: old_idx.to_h[:commit], tree: tree_idx, next_commit:old_idx[:next_commit] }
  else
    idx = {commit: old_idx.to_h[:commit], tree: tree_idx}
  end
  idx_yaml = idx.to_yaml
  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { |f| f.write idx_yaml }
  return idx
end

#get_idxObject



288
289
290
# File 'lib/cnvrg/dataset.rb', line 288

def get_idx
  YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
end

#get_ignore_listObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/cnvrg/dataset.rb', line 142

def get_ignore_list
  ignore_list = []
  File.open(self.local_path+"/.cnvrgignore", "r").each_line do |line|
    line = line.strip
    if line.start_with? "#" or ignore_list.include? line or line.empty?
      next
    end
    if line.end_with? "/" or File.directory?(line)
      ignore_list << line
      all_sub = Dir.glob("#{line}/**/*", File::FNM_DOTMATCH).flatten

      ignore_list << all_sub.flatten
    elsif line.include? "*"
      regex_list = Dir.glob("**/*#{line}", File::FNM_DOTMATCH).flatten
      ignore_list << regex_list
    else
      ignore_list << line
    end
  end
  return ignore_list.flatten

end

#get_next_commitObject



485
486
487
488
489
490
491
492
# File 'lib/cnvrg/dataset.rb', line 485

def get_next_commit()
  if  !File.exist? "#{self.local_path}/.cnvrg/idx.yml"
    return nil
  end
  idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
  return idx_hash[:next_commit]

end

#get_query_file(query_slug) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/cnvrg/dataset.rb', line 57

def get_query_file(query_slug)
  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/search/#{query_slug}", 'GET')
  CLI.is_response_success(response)
  row = [["Name","Full path","URL"]]
  response["results"]["query_files"].each do |file|
    row << [file["name"],file["fullpath"],file["s3_url"]]
  end
  return row

end

#last_local_commitObject



29
30
31
32
# File 'lib/cnvrg/dataset.rb', line 29

def last_local_commit
  idx = YAML.load_file(@local_path + "/.cnvrg/idx.yml")
  return idx[:commit]
end

#list(owner) ⇒ Object



41
42
43
44
45
46
# File 'lib/cnvrg/dataset.rb', line 41

def list(owner)
  response = Cnvrg::API.request("users/#{owner}/datasets/list", 'GET')
  CLI.is_response_success(response)
  return response

end

#list_all_filesObject



314
315
316
317
318
# File 'lib/cnvrg/dataset.rb', line 314

def list_all_files
  list = Dir.glob("#{self.local_path}/**/*", File::FNM_DOTMATCH).reject { |x| (x =~ /\/\.{1,2}$/) or (x =~ /^#{self.local_path}\/\.cnvrg\/*/) or (x =~/^#{self.local_path}\/\.cnvrgignore.conflict*/) and not (x =~/^#{self.local_path}\/\.cnvrgignore/) }
  list_ignore = self.get_ignore_list()
  return list.select{|file| !list_ignore.include? file}
end

#list_commitsObject



80
81
82
83
84
85
# File 'lib/cnvrg/dataset.rb', line 80

def list_commits
  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/list_commits", 'GET')
  CLI.is_response_success(response)
  return response

end

#list_files(commit, json) ⇒ Object



505
506
507
508
509
# File 'lib/cnvrg/dataset.rb', line 505

def list_files(commit, json)
  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/list", 'GET', {commit_sha1:commit, as_json:json})
  CLI.is_response_success(response,true)
  return response
end

#remove_next_commitObject



493
494
495
496
497
498
499
500
501
502
503
504
# File 'lib/cnvrg/dataset.rb', line 493

def remove_next_commit()
  if  !File.exist? "#{self.local_path}/.cnvrg/idx.yml"
    return nil
  end
  idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
  idx = Hash.new()
  idx[:commit] = idx_hash[:next_commit]
  idx[:tree] = idx_hash[:tree]
  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { |f| f.write idx.to_yaml }


end

#revert(working_dir) ⇒ Object



548
549
550
551
552
553
554
# File 'lib/cnvrg/dataset.rb', line 548

def revert(working_dir)
  FileUtils.rm_rf working_dir
  # response     = Cnvrg::API.request("users/#{self.owner}/projects/#{self.slug}/revert", 'GET')
  # CLI.is_response_success(response)


end

#search_queriesObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/cnvrg/dataset.rb', line 47

def search_queries
  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/queries/list", 'GET')
  CLI.is_response_success(response)
  row = [["name","id", "created_at", "username"]]
  response["results"]["queries"].each do |query|
    row << [query["name"],query["slug"], query["created_at"].in_time_zone.to_s, query["username"]]
  end
  return row

end

#send_ignore_listObject



438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/cnvrg/dataset.rb', line 438

def send_ignore_list()
  begin
    ignore_list = []
    File.open(self.local_path+"/.cnvrgignore", "r").each_line do |line|
      line = line.strip
      if line.start_with? "#" or ignore_list.include? line or line.empty?
        next
      end
      if line.end_with? "/"
        ignore_list << line.gsub("/","")
        ignore_list << line+"."
      elsif line.include? "*"
        line = line.gsub("*",".*")
        ignore_list << line
      else
        ignore_list << line
      end
    end
    return ignore_list.flatten
  rescue
    return []
  end

end

#set_next_commit(commit_sha1) ⇒ Object



471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File 'lib/cnvrg/dataset.rb', line 471

def set_next_commit(commit_sha1)
  if  !File.exist? "#{self.local_path}/.cnvrg/idx.yml"
    idx_hash = Hash.new()
    idx_hash[:commit] = ""
    idx_hash[:tree] = ""
  else
    idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")

  end
  idx_hash[:next_commit] = commit_sha1
  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { |f| f.write idx_hash.to_yaml }
  return true

end

#snapshotObject



34
35
36
37
38
39
40
# File 'lib/cnvrg/dataset.rb', line 34

def snapshot
  commit = last_local_commit
  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/volumes/create", 'POST', {data_commit: commit})
  CLI.is_response_success(response)
  return response

end

#update_idx(idx) ⇒ Object



533
534
535
536
537
# File 'lib/cnvrg/dataset.rb', line 533

def update_idx(idx)
  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { |f| f.write idx.to_yaml }

  return true
end

#update_idx_with_commit!(commit) ⇒ Object



540
541
542
543
544
545
546
# File 'lib/cnvrg/dataset.rb', line 540

def update_idx_with_commit!(commit)
  idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
  idx_hash[:commit] = commit

  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { |f| f.write idx_hash.to_yaml }
  return true
end

#update_idx_with_files_commits!(files, commit_time) ⇒ Object



520
521
522
523
524
525
526
527
528
529
530
531
532
# File 'lib/cnvrg/dataset.rb', line 520

def update_idx_with_files_commits!(files, commit_time)
  # files.flatten!
  idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
  # idx_hash[:commit] = commit

  files.each do |path|
    idx_hash[:tree].to_h[path].to_h[:commit_time] = commit_time
  end
  idx_hash[:next_commit] = idx_hash[:next_commit]
  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { |f| f.write idx_hash.to_yaml }

  return true
end

#update_ignore_list(new_ignore) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/cnvrg/dataset.rb', line 123

def update_ignore_list(new_ignore)

  if new_ignore.nil? or new_ignore.empty?
    return true
  end
  begin
    File.open(self.local_path+"/.cnvrgignore", "a+") do |f|
      f.puts("\n")

      new_ignore.each do |i|
        f.puts("#{i}\n")
      end
    end
    return true
  rescue
    return false
  end
end

#upload_tags_via_yml(tag_file = nil) ⇒ Object



87
88
89
90
91
92
93
94
95
96
# File 'lib/cnvrg/dataset.rb', line 87

def upload_tags_via_yml(tag_file=nil)
  records_yml = YAML.load_file(tag_file)
  tag_file.close
  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/data_tags_create", 'POST', {records_yml: records_yml})
  if response["status"] == 200
    return true
  else
    return false
  end
end

#urlObject



98
99
100
101
# File 'lib/cnvrg/dataset.rb', line 98

def url
  url = Cnvrg::Helpers.remote_url
  "#{url}/#{self.owner}/projects/#{self.slug}"
end

#write_idx(tree = nil, commit = nil) ⇒ Object



320
321
322
323
324
325
326
327
# File 'lib/cnvrg/dataset.rb', line 320

def write_idx(tree=nil, commit=nil)
  if tree.blank?
    tree = self.generate_idx[:tree]
    tree = tree.map{|k,v| (v.present?)? [k, {sha1: v[:sha1], commit_time: Time.now}] : [k,v]}.to_h
  end
  idx = {tree: tree, commit: commit}
  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { |f| f.write idx.to_yaml }
end