cnvrg 1.2.7 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/cnvrg.gemspec +3 -2
 - data/lib/cnvrg/api.rb +2 -2
 - data/lib/cnvrg/cli.rb +51 -36
 - data/lib/cnvrg/data.rb +14 -3
 - data/lib/cnvrg/datafiles.rb +20 -62
 - data/lib/cnvrg/dataset.rb +198 -144
 - data/lib/cnvrg/downloader/client.rb +53 -0
 - data/lib/cnvrg/downloader/clients/azure_client.rb +22 -0
 - data/lib/cnvrg/downloader/clients/gcp_client.rb +46 -0
 - data/lib/cnvrg/downloader/clients/s3_client.rb +51 -0
 - data/lib/cnvrg/files.rb +17 -44
 - data/lib/cnvrg/helpers/executer.rb +171 -0
 - data/lib/cnvrg/job_cli.rb +33 -0
 - data/lib/cnvrg/project.rb +45 -6
 - data/lib/cnvrg/storage.rb +128 -0
 - data/lib/cnvrg/version.rb +1 -1
 - metadata +28 -7
 - data/lib/cnvrg/job.rb +0 -40
 
    
        data/lib/cnvrg/dataset.rb
    CHANGED
    
    | 
         @@ -12,7 +12,7 @@ module Cnvrg 
     | 
|
| 
       12 
12 
     | 
    
         
             
                    if project_home.present?
         
     | 
| 
       13 
13 
     | 
    
         
             
                      @local_path = project_home
         
     | 
| 
       14 
14 
     | 
    
         
             
                      @working_dir = project_home
         
     | 
| 
       15 
     | 
    
         
            -
                      config = YAML.load_file(project_home+"/.cnvrg/config.yml")
         
     | 
| 
      
 15 
     | 
    
         
            +
                      config = YAML.load_file(project_home + "/.cnvrg/config.yml")
         
     | 
| 
       16 
16 
     | 
    
         
             
                      @title = config[:dataset_name]
         
     | 
| 
       17 
17 
     | 
    
         
             
                      @slug = config[:dataset_slug]
         
     | 
| 
       18 
18 
     | 
    
         
             
                      @owner = config[:owner]
         
     | 
| 
         @@ -28,10 +28,43 @@ module Cnvrg 
     | 
|
| 
       28 
28 
     | 
    
         
             
                end
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
       30 
30 
     | 
    
         | 
| 
      
 31 
     | 
    
         
            +
                def get_storage_client
         
     | 
| 
      
 32 
     | 
    
         
            +
                  response = Cnvrg::API.request("users/#{@owner}/datasets/#{@slug}/client", 'GET')
         
     | 
| 
      
 33 
     | 
    
         
            +
                  if Cnvrg::CLI.is_response_success(response, false)
         
     | 
| 
      
 34 
     | 
    
         
            +
                    client_params = response['client']
         
     | 
| 
      
 35 
     | 
    
         
            +
                  else
         
     | 
| 
      
 36 
     | 
    
         
            +
                    client_params = get_storage_client_fallback
         
     | 
| 
      
 37 
     | 
    
         
            +
                  end
         
     | 
| 
      
 38 
     | 
    
         
            +
                  Cnvrg::Downloader::Client.factory(client_params)
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                def get_storage_client_fallback
         
     | 
| 
      
 42 
     | 
    
         
            +
                  response = Cnvrg::API.request("users/#{@owner}/datasets/#{@slug}/download_multi", "POST", {files: []})
         
     | 
| 
      
 43 
     | 
    
         
            +
                  raise StandardError.new("Can't find dataset credentials") unless Cnvrg::CLI.is_response_success(response, false)
         
     | 
| 
      
 44 
     | 
    
         
            +
                  files = response['files']
         
     | 
| 
      
 45 
     | 
    
         
            +
                  storage = files['is_s3'] ? 's3' : 'minio'
         
     | 
| 
      
 46 
     | 
    
         
            +
                  files['storage'] = storage
         
     | 
| 
      
 47 
     | 
    
         
            +
                  files
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                def get_stats(commit: nil, query: nil)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  response = Cnvrg::API.request("users/#{@owner}/datasets/#{@slug}/clone", 'POST', {commit: commit, query: query})
         
     | 
| 
      
 53 
     | 
    
         
            +
                  Cnvrg::CLI.is_response_success(response, true)
         
     | 
| 
      
 54 
     | 
    
         
            +
                  response['result']
         
     | 
| 
      
 55 
     | 
    
         
            +
                end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                def get_clone_chunk(latest_id: nil, chunk_size: 1000, offset: 0, commit: 'latest')
         
     | 
| 
      
 58 
     | 
    
         
            +
                  response = Cnvrg::API.request("users/#{@owner}/datasets/#{@slug}/clone_chunk", 'POST', {commit: commit, chunk_size: chunk_size, latest_id: latest_id, offset: offset})
         
     | 
| 
      
 59 
     | 
    
         
            +
                  return nil unless Cnvrg::CLI.is_response_success(response, false)
         
     | 
| 
      
 60 
     | 
    
         
            +
                  response['result']['files']['keys']
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
       31 
64 
     | 
    
         
             
                def backup_idx
         
     | 
| 
       32 
65 
     | 
    
         
             
                  Cnvrg::Logger.log_info("Backup idx")
         
     | 
| 
       33 
66 
     | 
    
         
             
                  idx = self.get_idx
         
     | 
| 
       34 
     | 
    
         
            -
                  File.open("#{self.local_path}/.cnvrg/idx.yml.backup", 'w') { 
     | 
| 
      
 67 
     | 
    
         
            +
                  File.open("#{self.local_path}/.cnvrg/idx.yml.backup", 'w') {|f| f.write idx.to_yaml}
         
     | 
| 
       35 
68 
     | 
    
         
             
                end
         
     | 
| 
       36 
69 
     | 
    
         | 
| 
       37 
70 
     | 
    
         
             
                def restore_idx
         
     | 
| 
         @@ -43,17 +76,17 @@ module Cnvrg 
     | 
|
| 
       43 
76 
     | 
    
         | 
| 
       44 
77 
     | 
    
         
             
                def change_url(owner: '', slug: '', title: '')
         
     | 
| 
       45 
78 
     | 
    
         
             
                  config = {dataset_home: title, dataset_slug: slug, owner: owner}
         
     | 
| 
       46 
     | 
    
         
            -
                  File.open(".cnvrg/config.yml", "w+") { 
     | 
| 
      
 79 
     | 
    
         
            +
                  File.open(".cnvrg/config.yml", "w+") {|f| f.write config.to_yaml}
         
     | 
| 
       47 
80 
     | 
    
         
             
                end
         
     | 
| 
       48 
81 
     | 
    
         | 
| 
       49 
82 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
                def self.delete(dataset_slug,owner)
         
     | 
| 
      
 83 
     | 
    
         
            +
                def self.delete(dataset_slug, owner)
         
     | 
| 
       51 
84 
     | 
    
         
             
                  response = Cnvrg::API.request("users/#{owner}/datasets/#{dataset_slug}/delete", 'DELETE')
         
     | 
| 
       52 
85 
     | 
    
         
             
                  return response
         
     | 
| 
       53 
86 
     | 
    
         
             
                end
         
     | 
| 
       54 
87 
     | 
    
         | 
| 
       55 
88 
     | 
    
         
             
                def last_local_commit
         
     | 
| 
       56 
     | 
    
         
            -
                  if 
     | 
| 
      
 89 
     | 
    
         
            +
                  if !File.exist? "#{self.local_path}/.cnvrg/idx.yml"
         
     | 
| 
       57 
90 
     | 
    
         
             
                    return nil
         
     | 
| 
       58 
91 
     | 
    
         
             
                  end
         
     | 
| 
       59 
92 
     | 
    
         
             
                  idx = YAML.load_file(@local_path + "/.cnvrg/idx.yml")
         
     | 
| 
         @@ -67,28 +100,31 @@ module Cnvrg 
     | 
|
| 
       67 
100 
     | 
    
         
             
                  return response
         
     | 
| 
       68 
101 
     | 
    
         | 
| 
       69 
102 
     | 
    
         
             
                end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
       70 
104 
     | 
    
         
             
                def list(owner)
         
     | 
| 
       71 
105 
     | 
    
         
             
                  response = Cnvrg::API.request("users/#{owner}/datasets/list", 'GET')
         
     | 
| 
       72 
106 
     | 
    
         
             
                  CLI.is_response_success(response)
         
     | 
| 
       73 
107 
     | 
    
         
             
                  return response
         
     | 
| 
       74 
108 
     | 
    
         | 
| 
       75 
109 
     | 
    
         
             
                end
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
       76 
111 
     | 
    
         
             
                def search_queries
         
     | 
| 
       77 
112 
     | 
    
         
             
                  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/queries/list", 'GET')
         
     | 
| 
       78 
113 
     | 
    
         
             
                  CLI.is_response_success(response)
         
     | 
| 
       79 
     | 
    
         
            -
                  row = [["name","id", "created_at", "username"]]
         
     | 
| 
      
 114 
     | 
    
         
            +
                  row = [["name", "id", "created_at", "username"]]
         
     | 
| 
       80 
115 
     | 
    
         
             
                  response["results"]["queries"].each do |query|
         
     | 
| 
       81 
     | 
    
         
            -
                    row << [query["name"],query["slug"], query["created_at"].in_time_zone.to_s, query["username"]]
         
     | 
| 
      
 116 
     | 
    
         
            +
                    row << [query["name"], query["slug"], query["created_at"].in_time_zone.to_s, query["username"]]
         
     | 
| 
       82 
117 
     | 
    
         
             
                  end
         
     | 
| 
       83 
118 
     | 
    
         
             
                  return row
         
     | 
| 
       84 
119 
     | 
    
         | 
| 
       85 
120 
     | 
    
         
             
                end
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
       86 
122 
     | 
    
         
             
                def get_query_file(query_slug)
         
     | 
| 
       87 
123 
     | 
    
         
             
                  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/search/#{query_slug}", 'GET')
         
     | 
| 
       88 
124 
     | 
    
         
             
                  CLI.is_response_success(response)
         
     | 
| 
       89 
     | 
    
         
            -
                  row = [["Name","Full path","URL"]]
         
     | 
| 
      
 125 
     | 
    
         
            +
                  row = [["Name", "Full path", "URL"]]
         
     | 
| 
       90 
126 
     | 
    
         
             
                  response["results"]["query_files"].each do |file|
         
     | 
| 
       91 
     | 
    
         
            -
                    row << [file["name"],file["fullpath"],file["s3_url"]]
         
     | 
| 
      
 127 
     | 
    
         
            +
                    row << [file["name"], file["fullpath"], file["s3_url"]]
         
     | 
| 
       92 
128 
     | 
    
         
             
                  end
         
     | 
| 
       93 
129 
     | 
    
         
             
                  return row
         
     | 
| 
       94 
130 
     | 
    
         | 
| 
         @@ -99,7 +135,7 @@ module Cnvrg 
     | 
|
| 
       99 
135 
     | 
    
         
             
                  CLI.is_response_success(response)
         
     | 
| 
       100 
136 
     | 
    
         
             
                  begin
         
     | 
| 
       101 
137 
     | 
    
         
             
                    path = self.working_dir
         
     | 
| 
       102 
     | 
    
         
            -
                    File.open("#{path}/#{response["results"]["filename"]}", "w+") { 
     | 
| 
      
 138 
     | 
    
         
            +
                    File.open("#{path}/#{response["results"]["filename"]}", "w+") {|f| f.write response["results"]["file_content"]}
         
     | 
| 
       103 
139 
     | 
    
         
             
                    return true
         
     | 
| 
       104 
140 
     | 
    
         
             
                  rescue
         
     | 
| 
       105 
141 
     | 
    
         
             
                    return false
         
     | 
| 
         @@ -113,7 +149,7 @@ module Cnvrg 
     | 
|
| 
       113 
149 
     | 
    
         | 
| 
       114 
150 
     | 
    
         
             
                end
         
     | 
| 
       115 
151 
     | 
    
         | 
| 
       116 
     | 
    
         
            -
                def upload_tags_via_yml(tag_file=nil)
         
     | 
| 
      
 152 
     | 
    
         
            +
                def upload_tags_via_yml(tag_file = nil)
         
     | 
| 
       117 
153 
     | 
    
         
             
                  records_yml = YAML.load_file(tag_file)
         
     | 
| 
       118 
154 
     | 
    
         
             
                  tag_file.close
         
     | 
| 
       119 
155 
     | 
    
         
             
                  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/data_tags_create", 'POST', {records_yml: records_yml})
         
     | 
| 
         @@ -129,7 +165,7 @@ module Cnvrg 
     | 
|
| 
       129 
165 
     | 
    
         
             
                  "#{url}/#{self.owner}/projects/#{self.slug}"
         
     | 
| 
       130 
166 
     | 
    
         
             
                end
         
     | 
| 
       131 
167 
     | 
    
         | 
| 
       132 
     | 
    
         
            -
                def self.verify_cnvrgignore_exist(dataset_name,remote)
         
     | 
| 
      
 168 
     | 
    
         
            +
                def self.verify_cnvrgignore_exist(dataset_name, remote)
         
     | 
| 
       133 
169 
     | 
    
         
             
                  path = ".cnvrgignore"
         
     | 
| 
       134 
170 
     | 
    
         
             
                  if !File.exist? path
         
     | 
| 
       135 
171 
     | 
    
         
             
                    path = "#{dataset_name}/.cnvrgignore"
         
     | 
| 
         @@ -142,20 +178,21 @@ module Cnvrg 
     | 
|
| 
       142 
178 
     | 
    
         
             
                      ]
         
     | 
| 
       143 
179 
     | 
    
         
             
                      FileUtils.touch list_files
         
     | 
| 
       144 
180 
     | 
    
         
             
                      cnvrgignore = Helpers.cnvrgignore_content
         
     | 
| 
       145 
     | 
    
         
            -
                      File.open(path, "w+") { 
     | 
| 
      
 181 
     | 
    
         
            +
                      File.open(path, "w+") {|f| f.write cnvrgignore}
         
     | 
| 
       146 
182 
     | 
    
         
             
                    rescue => e
         
     | 
| 
       147 
183 
     | 
    
         
             
                      return false
         
     | 
| 
       148 
184 
     | 
    
         
             
                    end
         
     | 
| 
       149 
185 
     | 
    
         | 
| 
       150 
186 
     | 
    
         
             
                  end
         
     | 
| 
       151 
187 
     | 
    
         
             
                end
         
     | 
| 
      
 188 
     | 
    
         
            +
             
     | 
| 
       152 
189 
     | 
    
         
             
                def update_ignore_list(new_ignore)
         
     | 
| 
       153 
190 
     | 
    
         | 
| 
       154 
191 
     | 
    
         
             
                  if new_ignore.nil? or new_ignore.empty?
         
     | 
| 
       155 
192 
     | 
    
         
             
                    return true
         
     | 
| 
       156 
193 
     | 
    
         
             
                  end
         
     | 
| 
       157 
194 
     | 
    
         
             
                  begin
         
     | 
| 
       158 
     | 
    
         
            -
                    File.open(self.local_path+"/.cnvrgignore", "a+") do |f|
         
     | 
| 
      
 195 
     | 
    
         
            +
                    File.open(self.local_path + "/.cnvrgignore", "a+") do |f|
         
     | 
| 
       159 
196 
     | 
    
         
             
                      f.puts("\n")
         
     | 
| 
       160 
197 
     | 
    
         | 
| 
       161 
198 
     | 
    
         
             
                      new_ignore.each do |i|
         
     | 
| 
         @@ -169,8 +206,12 @@ module Cnvrg 
     | 
|
| 
       169 
206 
     | 
    
         
             
                end
         
     | 
| 
       170 
207 
     | 
    
         | 
| 
       171 
208 
     | 
    
         
             
                def get_ignore_list
         
     | 
| 
      
 209 
     | 
    
         
            +
                  ### handle case when after clone .cnvrgignore doesnt exists
         
     | 
| 
      
 210 
     | 
    
         
            +
                  if not File.exists?(self.local_path + "/.cnvrgignore")
         
     | 
| 
      
 211 
     | 
    
         
            +
                    self.generate_cnvrg_ignore
         
     | 
| 
      
 212 
     | 
    
         
            +
                  end
         
     | 
| 
       172 
213 
     | 
    
         
             
                  ignore_list = []
         
     | 
| 
       173 
     | 
    
         
            -
                  File.open(self.local_path+"/.cnvrgignore", "r").each_line do |line|
         
     | 
| 
      
 214 
     | 
    
         
            +
                  File.open(self.local_path + "/.cnvrgignore", "r").each_line do |line|
         
     | 
| 
       174 
215 
     | 
    
         
             
                    line = line.strip
         
     | 
| 
       175 
216 
     | 
    
         
             
                    if line.start_with? "#" or ignore_list.include? line or line.empty?
         
     | 
| 
       176 
217 
     | 
    
         
             
                      next
         
     | 
| 
         @@ -192,38 +233,38 @@ module Cnvrg 
     | 
|
| 
       192 
233 
     | 
    
         
             
                end
         
     | 
| 
       193 
234 
     | 
    
         | 
| 
       194 
235 
     | 
    
         | 
| 
       195 
     | 
    
         
            -
                def self.init(owner, dataset_name, is_public=false)
         
     | 
| 
       196 
     | 
    
         
            -
             
     | 
| 
       197 
     | 
    
         
            -
             
     | 
| 
       198 
     | 
    
         
            -
             
     | 
| 
       199 
     | 
    
         
            -
             
     | 
| 
       200 
     | 
    
         
            -
             
     | 
| 
       201 
     | 
    
         
            -
             
     | 
| 
       202 
     | 
    
         
            -
             
     | 
| 
       203 
     | 
    
         
            -
             
     | 
| 
       204 
     | 
    
         
            -
             
     | 
| 
       205 
     | 
    
         
            -
             
     | 
| 
      
 236 
     | 
    
         
            +
                def self.init(owner, dataset_name, is_public = false, bucket: nil)
         
     | 
| 
      
 237 
     | 
    
         
            +
                  list_dirs = [".cnvrg"
         
     | 
| 
      
 238 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 239 
     | 
    
         
            +
                  list_files = [
         
     | 
| 
      
 240 
     | 
    
         
            +
                      ".cnvrg/config.yml"
         
     | 
| 
      
 241 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 242 
     | 
    
         
            +
                  create_ignore = false
         
     | 
| 
      
 243 
     | 
    
         
            +
                  if !File.exist? ".cnvrgignore"
         
     | 
| 
      
 244 
     | 
    
         
            +
                    list_files << ".cnvrgignore"
         
     | 
| 
      
 245 
     | 
    
         
            +
                    create_ignore = true
         
     | 
| 
      
 246 
     | 
    
         
            +
                  end
         
     | 
| 
       206 
247 
     | 
    
         | 
| 
       207 
248 
     | 
    
         | 
| 
       208 
     | 
    
         
            -
             
     | 
| 
       209 
     | 
    
         
            -
             
     | 
| 
       210 
     | 
    
         
            -
             
     | 
| 
       211 
     | 
    
         
            -
             
     | 
| 
       212 
     | 
    
         
            -
             
     | 
| 
       213 
     | 
    
         
            -
             
     | 
| 
      
 249 
     | 
    
         
            +
                  cnvrgignore = Helpers.cnvrgignore_content
         
     | 
| 
      
 250 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 251 
     | 
    
         
            +
                    response = Cnvrg::API.request("cli/create_dataset", 'POST', {title: dataset_name, owner: owner, is_public: is_public, bucket: bucket})
         
     | 
| 
      
 252 
     | 
    
         
            +
                    Cnvrg::CLI.is_response_success(response)
         
     | 
| 
      
 253 
     | 
    
         
            +
                    response = JSON.parse response["result"]
         
     | 
| 
      
 254 
     | 
    
         
            +
                    dataset_slug = response["slug"]
         
     | 
| 
       214 
255 
     | 
    
         | 
| 
       215 
     | 
    
         
            -
             
     | 
| 
       216 
     | 
    
         
            -
             
     | 
| 
       217 
     | 
    
         
            -
             
     | 
| 
      
 256 
     | 
    
         
            +
                    config = {dataset_name: dataset_name,
         
     | 
| 
      
 257 
     | 
    
         
            +
                              dataset_slug: dataset_slug,
         
     | 
| 
      
 258 
     | 
    
         
            +
                              owner: owner}
         
     | 
| 
       218 
259 
     | 
    
         | 
| 
       219 
     | 
    
         
            -
             
     | 
| 
       220 
     | 
    
         
            -
             
     | 
| 
       221 
     | 
    
         
            -
             
     | 
| 
       222 
     | 
    
         
            -
             
     | 
| 
       223 
     | 
    
         
            -
             
     | 
| 
       224 
     | 
    
         
            -
             
     | 
| 
       225 
     | 
    
         
            -
             
     | 
| 
       226 
     | 
    
         
            -
             
     | 
| 
      
 260 
     | 
    
         
            +
                    FileUtils.mkdir_p list_dirs
         
     | 
| 
      
 261 
     | 
    
         
            +
                    FileUtils.touch list_files
         
     | 
| 
      
 262 
     | 
    
         
            +
                    File.open(".cnvrg/config.yml", "w+") {|f| f.write config.to_yaml}
         
     | 
| 
      
 263 
     | 
    
         
            +
                    File.open(".cnvrgignore", "w+") {|f| f.write cnvrgignore} unless !create_ignore
         
     | 
| 
      
 264 
     | 
    
         
            +
                  rescue => e
         
     | 
| 
      
 265 
     | 
    
         
            +
                    return false
         
     | 
| 
      
 266 
     | 
    
         
            +
                  end
         
     | 
| 
      
 267 
     | 
    
         
            +
                  return true
         
     | 
| 
       227 
268 
     | 
    
         
             
                end
         
     | 
| 
       228 
269 
     | 
    
         | 
| 
       229 
270 
     | 
    
         | 
| 
         @@ -236,7 +277,7 @@ module Cnvrg 
     | 
|
| 
       236 
277 
     | 
    
         
             
                  create_ignore = false
         
     | 
| 
       237 
278 
     | 
    
         
             
                  if !File.exist? ".cnvrgignore"
         
     | 
| 
       238 
279 
     | 
    
         
             
                    list_files << ".cnvrgignore"
         
     | 
| 
       239 
     | 
    
         
            -
                    create_ignore 
     | 
| 
      
 280 
     | 
    
         
            +
                    create_ignore = true
         
     | 
| 
       240 
281 
     | 
    
         
             
                  end
         
     | 
| 
       241 
282 
     | 
    
         | 
| 
       242 
283 
     | 
    
         | 
| 
         @@ -249,15 +290,20 @@ module Cnvrg 
     | 
|
| 
       249 
290 
     | 
    
         | 
| 
       250 
291 
     | 
    
         
             
                    FileUtils.mkdir_p list_dirs
         
     | 
| 
       251 
292 
     | 
    
         
             
                    FileUtils.touch list_files
         
     | 
| 
       252 
     | 
    
         
            -
                    File.open(".cnvrg/config.yml", "w+") { 
     | 
| 
       253 
     | 
    
         
            -
                    File.open(".cnvrgignore", "w+") { 
     | 
| 
      
 293 
     | 
    
         
            +
                    File.open(".cnvrg/config.yml", "w+") {|f| f.write config.to_yaml}
         
     | 
| 
      
 294 
     | 
    
         
            +
                    File.open(".cnvrgignore", "w+") {|f| f.write cnvrgignore} unless !create_ignore
         
     | 
| 
       254 
295 
     | 
    
         
             
                  rescue => e
         
     | 
| 
       255 
296 
     | 
    
         
             
                    return false
         
     | 
| 
       256 
297 
     | 
    
         
             
                  end
         
     | 
| 
       257 
298 
     | 
    
         
             
                  return true
         
     | 
| 
       258 
299 
     | 
    
         
             
                end
         
     | 
| 
       259 
300 
     | 
    
         | 
| 
       260 
     | 
    
         
            -
                def  
     | 
| 
      
 301 
     | 
    
         
            +
                def generate_cnvrg_ignore
         
     | 
| 
      
 302 
     | 
    
         
            +
                  cnvrgignore = Helpers.cnvrgignore_content
         
     | 
| 
      
 303 
     | 
    
         
            +
                  File.open(self.local_path + "/.cnvrgignore", "w+") {|f| f.write cnvrgignore}
         
     | 
| 
      
 304 
     | 
    
         
            +
                end
         
     | 
| 
      
 305 
     | 
    
         
            +
             
     | 
| 
      
 306 
     | 
    
         
            +
                def self.verify_datasets(dataset_titles, timeout = 100)
         
     | 
| 
       261 
307 
     | 
    
         
             
                  start_time = Time.now.to_i
         
     | 
| 
       262 
308 
     | 
    
         
             
                  Cnvrg::Logger.log_info("Verifying datasets #{dataset_titles}")
         
     | 
| 
       263 
309 
     | 
    
         
             
                  Cnvrg::Logger.log_info("Timeout is  #{timeout}")
         
     | 
| 
         @@ -280,18 +326,18 @@ module Cnvrg 
     | 
|
| 
       280 
326 
     | 
    
         
             
                  end
         
     | 
| 
       281 
327 
     | 
    
         
             
                end
         
     | 
| 
       282 
328 
     | 
    
         | 
| 
       283 
     | 
    
         
            -
                def clone( 
     | 
| 
      
 329 
     | 
    
         
            +
                def clone(commit)
         
     | 
| 
       284 
330 
     | 
    
         | 
| 
       285 
331 
     | 
    
         | 
| 
       286 
332 
     | 
    
         
             
                  return response
         
     | 
| 
       287 
333 
     | 
    
         
             
                end
         
     | 
| 
       288 
334 
     | 
    
         | 
| 
       289 
     | 
    
         
            -
                def self.clone(owner, dataset_name, dataset_slug, remote=false)
         
     | 
| 
      
 335 
     | 
    
         
            +
                def self.clone(owner, dataset_name, dataset_slug, remote = false)
         
     | 
| 
       290 
336 
     | 
    
         | 
| 
       291 
337 
     | 
    
         
             
                  begin
         
     | 
| 
       292 
338 
     | 
    
         
             
                    list_dirs = []
         
     | 
| 
       293 
339 
     | 
    
         
             
                    if !remote
         
     | 
| 
       294 
     | 
    
         
            -
                      list_dirs << 
     | 
| 
      
 340 
     | 
    
         
            +
                      list_dirs << dataset_name
         
     | 
| 
       295 
341 
     | 
    
         
             
                    end
         
     | 
| 
       296 
342 
     | 
    
         
             
                    list_dirs << "#{dataset_name}/.cnvrg"
         
     | 
| 
       297 
343 
     | 
    
         
             
                    list_files = [
         
     | 
| 
         @@ -305,7 +351,7 @@ module Cnvrg 
     | 
|
| 
       305 
351 
     | 
    
         | 
| 
       306 
352 
     | 
    
         
             
                    FileUtils.mkdir_p list_dirs
         
     | 
| 
       307 
353 
     | 
    
         
             
                    FileUtils.touch list_files
         
     | 
| 
       308 
     | 
    
         
            -
                    File.open("#{dataset_name}/.cnvrg/config.yml", "w+") { 
     | 
| 
      
 354 
     | 
    
         
            +
                    File.open("#{dataset_name}/.cnvrg/config.yml", "w+") {|f| f.write config.to_yaml}
         
     | 
| 
       309 
355 
     | 
    
         
             
                  rescue => e
         
     | 
| 
       310 
356 
     | 
    
         
             
                    puts "Exception in clone request:#{e.message}"
         
     | 
| 
       311 
357 
     | 
    
         
             
                    return false
         
     | 
| 
         @@ -325,11 +371,11 @@ module Cnvrg 
     | 
|
| 
       325 
371 
     | 
    
         
             
                  trees = @files.get_trees(commit: commit)
         
     | 
| 
       326 
372 
     | 
    
         
             
                  return false if trees.nil?
         
     | 
| 
       327 
373 
     | 
    
         
             
                  pb = ProgressBar.create(:title => "Download Progress",
         
     | 
| 
       328 
     | 
    
         
            -
             
     | 
| 
       329 
     | 
    
         
            -
             
     | 
| 
       330 
     | 
    
         
            -
             
     | 
| 
       331 
     | 
    
         
            -
             
     | 
| 
       332 
     | 
    
         
            -
             
     | 
| 
      
 374 
     | 
    
         
            +
                                          :progress_mark => '=',
         
     | 
| 
      
 375 
     | 
    
         
            +
                                          :format => "%b>>%i| %p%% %t",
         
     | 
| 
      
 376 
     | 
    
         
            +
                                          :starting_at => 0,
         
     | 
| 
      
 377 
     | 
    
         
            +
                                          :total => trees.size,
         
     | 
| 
      
 378 
     | 
    
         
            +
                                          :autofinish => true)
         
     | 
| 
       333 
379 
     | 
    
         
             
                  trees.each do |tree|
         
     | 
| 
       334 
380 
     | 
    
         
             
                    pb.progress += 1
         
     | 
| 
       335 
381 
     | 
    
         
             
                    @files.download_dir(dataset_home, tree)
         
     | 
| 
         @@ -343,16 +389,16 @@ module Cnvrg 
     | 
|
| 
       343 
389 
     | 
    
         
             
                  file_path = ".cnvrg/config.yml"
         
     | 
| 
       344 
390 
     | 
    
         
             
                  file_path = "#{@slug}/" + file_path if !in_folder
         
     | 
| 
       345 
391 
     | 
    
         
             
                  if File.exist?(file_path)
         
     | 
| 
       346 
     | 
    
         
            -
                    File.open(file_path, "a") { 
     | 
| 
      
 392 
     | 
    
         
            +
                    File.open(file_path, "a") {|f| f.puts(":success: true")}
         
     | 
| 
       347 
393 
     | 
    
         
             
                  end
         
     | 
| 
       348 
394 
     | 
    
         
             
                rescue
         
     | 
| 
       349 
395 
     | 
    
         
             
                end
         
     | 
| 
       350 
396 
     | 
    
         | 
| 
       351 
     | 
    
         
            -
                def self.init_container(owner, dataset_slug,dataset_name)
         
     | 
| 
      
 397 
     | 
    
         
            +
                def self.init_container(owner, dataset_slug, dataset_name)
         
     | 
| 
       352 
398 
     | 
    
         | 
| 
       353 
399 
     | 
    
         
             
                  cnvrgignore = Helpers.cnvrgignore_content
         
     | 
| 
       354 
400 
     | 
    
         
             
                  begin
         
     | 
| 
       355 
     | 
    
         
            -
                    list_dirs = [ 
     | 
| 
      
 401 
     | 
    
         
            +
                    list_dirs = [".cnvrg"
         
     | 
| 
       356 
402 
     | 
    
         
             
                    ]
         
     | 
| 
       357 
403 
     | 
    
         
             
                    list_files = [
         
     | 
| 
       358 
404 
     | 
    
         
             
                        ".cnvrgignore",
         
     | 
| 
         @@ -364,9 +410,9 @@ module Cnvrg 
     | 
|
| 
       364 
410 
     | 
    
         
             
                    config = {dataset_name: dataset_name,
         
     | 
| 
       365 
411 
     | 
    
         
             
                              dataset_slug: dataset_slug,
         
     | 
| 
       366 
412 
     | 
    
         
             
                              owner: owner}
         
     | 
| 
       367 
     | 
    
         
            -
                    File.open(".cnvrg/config.yml", "w+") { 
     | 
| 
      
 413 
     | 
    
         
            +
                    File.open(".cnvrg/config.yml", "w+") {|f| f.write config.to_yaml}
         
     | 
| 
       368 
414 
     | 
    
         | 
| 
       369 
     | 
    
         
            -
                    File.open(".cnvrgignore", "w+") { 
     | 
| 
      
 415 
     | 
    
         
            +
                    File.open(".cnvrgignore", "w+") {|f| f.write cnvrgignore} unless File.exist? ".cnvrgignore"
         
     | 
| 
       370 
416 
     | 
    
         
             
                  rescue => e
         
     | 
| 
       371 
417 
     | 
    
         
             
                    return false
         
     | 
| 
       372 
418 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -383,23 +429,24 @@ module Cnvrg 
     | 
|
| 
       383 
429 
     | 
    
         
             
                end
         
     | 
| 
       384 
430 
     | 
    
         | 
| 
       385 
431 
     | 
    
         
             
                def set_idx(idx)
         
     | 
| 
       386 
     | 
    
         
            -
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w+') { 
     | 
| 
      
 432 
     | 
    
         
            +
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w+') {|f| f.write idx.to_yaml}
         
     | 
| 
       387 
433 
     | 
    
         
             
                end
         
     | 
| 
       388 
434 
     | 
    
         | 
| 
       389 
435 
     | 
    
         
             
                def url
         
     | 
| 
       390 
436 
     | 
    
         
             
                  url = Cnvrg::Helpers.remote_url
         
     | 
| 
       391 
437 
     | 
    
         
             
                  "#{url}/#{self.owner}/datasets/#{self.slug}"
         
     | 
| 
       392 
438 
     | 
    
         
             
                end
         
     | 
| 
       393 
     | 
    
         
            -
             
     | 
| 
      
 439 
     | 
    
         
            +
             
     | 
| 
      
 440 
     | 
    
         
            +
                def generate_chunked_idx(list_files = [], threads: IDXParallelThreads, prefix: '')
         
     | 
| 
       394 
441 
     | 
    
         
             
                  tree = {}
         
     | 
| 
       395 
442 
     | 
    
         
             
                  Parallel.map(list_files, in_threads: threads) do |file|
         
     | 
| 
       396 
443 
     | 
    
         
             
                    #check if prefix exists do prefix/path otherwise path
         
     | 
| 
       397 
444 
     | 
    
         
             
                    label = file.gsub(self.local_path + "/", "")
         
     | 
| 
       398 
445 
     | 
    
         
             
                    label = "#{prefix}/#{label}" if prefix.present?
         
     | 
| 
       399 
446 
     | 
    
         
             
                    if File.directory? file
         
     | 
| 
       400 
     | 
    
         
            -
                      tree[label+"/"] = nil
         
     | 
| 
      
 447 
     | 
    
         
            +
                      tree[label + "/"] = nil
         
     | 
| 
       401 
448 
     | 
    
         
             
                    else
         
     | 
| 
       402 
     | 
    
         
            -
                      sha1 = 
     | 
| 
      
 449 
     | 
    
         
            +
                      sha1 = OpenSSL::Digest::SHA1.file(file).hexdigest
         
     | 
| 
       403 
450 
     | 
    
         
             
                      file_name = File.basename file
         
     | 
| 
       404 
451 
     | 
    
         
             
                      file_size = File.size(file).to_f
         
     | 
| 
       405 
452 
     | 
    
         
             
                      mime_type = MimeMagic.by_path(file)
         
     | 
| 
         @@ -425,30 +472,30 @@ module Cnvrg 
     | 
|
| 
       425 
472 
     | 
    
         
             
                  if commit.blank?
         
     | 
| 
       426 
473 
     | 
    
         
             
                    resp = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/last_valid_commit", 'GET')
         
     | 
| 
       427 
474 
     | 
    
         
             
                    if CLI.is_response_success(resp, false)
         
     | 
| 
       428 
     | 
    
         
            -
             
     | 
| 
      
 475 
     | 
    
         
            +
                      commit = resp['result']['commit_sha1']
         
     | 
| 
       429 
476 
     | 
    
         
             
                    end
         
     | 
| 
       430 
477 
     | 
    
         
             
                  end
         
     | 
| 
       431 
478 
     | 
    
         
             
                  self.update_idx_with_commit(commit) if commit.present?
         
     | 
| 
       432 
479 
     | 
    
         
             
                  self.revert_next_commit
         
     | 
| 
       433 
480 
     | 
    
         
             
                end
         
     | 
| 
       434 
481 
     | 
    
         | 
| 
       435 
     | 
    
         
            -
                def list_all_files(with_ignore=false)
         
     | 
| 
       436 
     | 
    
         
            -
                  list = Dir.glob("#{self.local_path}/**/*", File::FNM_DOTMATCH).reject { 
     | 
| 
      
 482 
     | 
    
         
            +
                def list_all_files(with_ignore = false)
         
     | 
| 
      
 483 
     | 
    
         
            +
                  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/)}
         
     | 
| 
       437 
484 
     | 
    
         | 
| 
       438 
485 
     | 
    
         
             
                  #we want that big files will
         
     | 
| 
       439 
     | 
    
         
            -
                  list = list.sort_by{|fn| File.size(fn)}
         
     | 
| 
      
 486 
     | 
    
         
            +
                  list = list.sort_by {|fn| File.size(fn)}
         
     | 
| 
       440 
487 
     | 
    
         
             
                  return list if with_ignore
         
     | 
| 
       441 
     | 
    
         
            -
                  list_ignore = self.get_ignore_list.map{|ignore_file| "#{self.local_path}/#{ignore_file}"}
         
     | 
| 
      
 488 
     | 
    
         
            +
                  list_ignore = self.get_ignore_list.map {|ignore_file| "#{self.local_path}/#{ignore_file}"}
         
     | 
| 
       442 
489 
     | 
    
         
             
                  (list - list_ignore)
         
     | 
| 
       443 
490 
     | 
    
         
             
                end
         
     | 
| 
       444 
491 
     | 
    
         | 
| 
       445 
     | 
    
         
            -
                def write_idx(tree=nil, commit=nil)
         
     | 
| 
      
 492 
     | 
    
         
            +
                def write_idx(tree = nil, commit = nil)
         
     | 
| 
       446 
493 
     | 
    
         
             
                  if tree.blank?
         
     | 
| 
       447 
494 
     | 
    
         
             
                    tree = self.generate_idx[:tree]
         
     | 
| 
       448 
     | 
    
         
            -
                    tree = tree.map{|k,v| (v.present?)? [k, {sha1: v[:sha1], commit_time: Time.now}] : [k,v]}.to_h
         
     | 
| 
      
 495 
     | 
    
         
            +
                    tree = tree.map {|k, v| (v.present?) ? [k, {sha1: v[:sha1], commit_time: Time.now}] : [k, v]}.to_h
         
     | 
| 
       449 
496 
     | 
    
         
             
                  end
         
     | 
| 
       450 
497 
     | 
    
         
             
                  idx = {tree: tree, commit: commit}
         
     | 
| 
       451 
     | 
    
         
            -
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { 
     | 
| 
      
 498 
     | 
    
         
            +
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') {|f| f.write idx.to_yaml}
         
     | 
| 
       452 
499 
     | 
    
         
             
                end
         
     | 
| 
       453 
500 
     | 
    
         | 
| 
       454 
501 
     | 
    
         
             
                def write_tree(tree)
         
     | 
| 
         @@ -457,14 +504,14 @@ module Cnvrg 
     | 
|
| 
       457 
504 
     | 
    
         
             
                  self.set_idx(idx)
         
     | 
| 
       458 
505 
     | 
    
         
             
                end
         
     | 
| 
       459 
506 
     | 
    
         | 
| 
       460 
     | 
    
         
            -
                def generate_idx(show_progress=false)
         
     | 
| 
      
 507 
     | 
    
         
            +
                def generate_idx(show_progress = false)
         
     | 
| 
       461 
508 
     | 
    
         
             
                  if File.exists? "#{self.local_path}/.cnvrg/idx.yml"
         
     | 
| 
       462 
509 
     | 
    
         
             
                    old_idx = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
         
     | 
| 
       463 
510 
     | 
    
         
             
                  else
         
     | 
| 
       464 
511 
     | 
    
         
             
                    old_idx = nil
         
     | 
| 
       465 
512 
     | 
    
         
             
                  end
         
     | 
| 
       466 
513 
     | 
    
         
             
                  tree_idx = Hash.new(0)
         
     | 
| 
       467 
     | 
    
         
            -
                  list = Dir.glob("#{self.local_path}/**/*", File::FNM_DOTMATCH).reject { 
     | 
| 
      
 514 
     | 
    
         
            +
                  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/)}
         
     | 
| 
       468 
515 
     | 
    
         
             
                  list_ignore = self.get_ignore_list()
         
     | 
| 
       469 
516 
     | 
    
         
             
                  if show_progress
         
     | 
| 
       470 
517 
     | 
    
         
             
                    parallel_options = {
         
     | 
| 
         @@ -486,18 +533,18 @@ module Cnvrg 
     | 
|
| 
       486 
533 
     | 
    
         
             
                    }
         
     | 
| 
       487 
534 
     | 
    
         
             
                  end
         
     | 
| 
       488 
535 
     | 
    
         | 
| 
       489 
     | 
    
         
            -
                  Parallel.map(list, parallel_options 
     | 
| 
      
 536 
     | 
    
         
            +
                  Parallel.map(list, parallel_options) do |e|
         
     | 
| 
       490 
537 
     | 
    
         
             
                    label = e.gsub(self.local_path + "/", "")
         
     | 
| 
       491 
538 
     | 
    
         
             
                    if File.directory? e
         
     | 
| 
       492 
539 
     | 
    
         
             
                      if list_ignore.include? label
         
     | 
| 
       493 
540 
     | 
    
         
             
                        next
         
     | 
| 
       494 
541 
     | 
    
         
             
                      end
         
     | 
| 
       495 
     | 
    
         
            -
                      tree_idx[label+"/"] = nil
         
     | 
| 
      
 542 
     | 
    
         
            +
                      tree_idx[label + "/"] = nil
         
     | 
| 
       496 
543 
     | 
    
         
             
                    else
         
     | 
| 
       497 
544 
     | 
    
         
             
                      if list_ignore.include? label
         
     | 
| 
       498 
545 
     | 
    
         
             
                        next
         
     | 
| 
       499 
546 
     | 
    
         
             
                      end
         
     | 
| 
       500 
     | 
    
         
            -
                      sha1 = 
     | 
| 
      
 547 
     | 
    
         
            +
                      sha1 = OpenSSL::Digest::SHA1.file(e).hexdigest
         
     | 
| 
       501 
548 
     | 
    
         
             
                      if old_idx.nil? or old_idx.to_h["tree"].nil?
         
     | 
| 
       502 
549 
     | 
    
         
             
                        tree_idx[label] = {sha1: sha1, commit_time: nil}
         
     | 
| 
       503 
550 
     | 
    
         
             
                      elsif old_idx["tree"][label].nil? or old_idx["tree"][label]["sha1"] != sha1
         
     | 
| 
         @@ -507,15 +554,16 @@ module Cnvrg 
     | 
|
| 
       507 
554 
     | 
    
         
             
                      end
         
     | 
| 
       508 
555 
     | 
    
         
             
                    end
         
     | 
| 
       509 
556 
     | 
    
         
             
                  end
         
     | 
| 
       510 
     | 
    
         
            -
                  if !old_idx.nil? and !old_idx[:next_commit].nil? and 
     | 
| 
       511 
     | 
    
         
            -
                    idx = {commit: old_idx.to_h[:commit], tree: tree_idx, next_commit:old_idx[:next_commit] 
     | 
| 
      
 557 
     | 
    
         
            +
                  if !old_idx.nil? and !old_idx[:next_commit].nil? and !old_idx[:next_commit].empty?
         
     | 
| 
      
 558 
     | 
    
         
            +
                    idx = {commit: old_idx.to_h[:commit], tree: tree_idx, next_commit: old_idx[:next_commit]}
         
     | 
| 
       512 
559 
     | 
    
         
             
                  else
         
     | 
| 
       513 
560 
     | 
    
         
             
                    idx = {commit: old_idx.to_h[:commit], tree: tree_idx}
         
     | 
| 
       514 
561 
     | 
    
         
             
                  end
         
     | 
| 
       515 
562 
     | 
    
         
             
                  idx_yaml = idx.to_yaml
         
     | 
| 
       516 
     | 
    
         
            -
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { 
     | 
| 
      
 563 
     | 
    
         
            +
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') {|f| f.write idx_yaml}
         
     | 
| 
       517 
564 
     | 
    
         
             
                  return idx
         
     | 
| 
       518 
565 
     | 
    
         
             
                end
         
     | 
| 
      
 566 
     | 
    
         
            +
             
     | 
| 
       519 
567 
     | 
    
         
             
                def create_volume
         
     | 
| 
       520 
568 
     | 
    
         
             
                  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/volumes/create", 'POST')
         
     | 
| 
       521 
569 
     | 
    
         
             
                  CLI.is_response_success(response)
         
     | 
| 
         @@ -524,12 +572,13 @@ module Cnvrg 
     | 
|
| 
       524 
572 
     | 
    
         | 
| 
       525 
573 
     | 
    
         
             
                def download_updated_data(current_commit)
         
     | 
| 
       526 
574 
     | 
    
         
             
                  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/download_updated_data", 'POST', {current_commit: current_commit})
         
     | 
| 
       527 
     | 
    
         
            -
                  CLI.is_response_success(response,false)
         
     | 
| 
      
 575 
     | 
    
         
            +
                  CLI.is_response_success(response, false)
         
     | 
| 
       528 
576 
     | 
    
         
             
                  return response
         
     | 
| 
       529 
577 
     | 
    
         
             
                end
         
     | 
| 
       530 
     | 
    
         
            -
             
     | 
| 
      
 578 
     | 
    
         
            +
             
     | 
| 
      
 579 
     | 
    
         
            +
                def compare_idx(new_branch, commit = last_local_commit, local_idx = nil, force = false, next_commit = nil)
         
     | 
| 
       531 
580 
     | 
    
         
             
                  if local_idx.nil?
         
     | 
| 
       532 
     | 
    
         
            -
                    local_idx = 
     | 
| 
      
 581 
     | 
    
         
            +
                    local_idx = self.generate_idx
         
     | 
| 
       533 
582 
     | 
    
         
             
                  end
         
     | 
| 
       534 
583 
     | 
    
         
             
                  ignore_list = self.get_ignore_list()
         
     | 
| 
       535 
584 
     | 
    
         
             
                  if force
         
     | 
| 
         @@ -539,24 +588,24 @@ module Cnvrg 
     | 
|
| 
       539 
588 
     | 
    
         
             
                      added.flatten!
         
     | 
| 
       540 
589 
     | 
    
         
             
                    end
         
     | 
| 
       541 
590 
     | 
    
         | 
| 
       542 
     | 
    
         
            -
                    response ={"result"=> {"commit"=>next_commit,"tree"=> {"added"=> added,
         
     | 
| 
       543 
     | 
    
         
            -
             
     | 
| 
       544 
     | 
    
         
            -
             
     | 
| 
       545 
     | 
    
         
            -
             
     | 
| 
       546 
     | 
    
         
            -
             
     | 
| 
      
 591 
     | 
    
         
            +
                    response = {"result" => {"commit" => next_commit, "tree" => {"added" => added,
         
     | 
| 
      
 592 
     | 
    
         
            +
                                                                                 "updated_on_server" => [],
         
     | 
| 
      
 593 
     | 
    
         
            +
                                                                                 "updated_on_local" => [],
         
     | 
| 
      
 594 
     | 
    
         
            +
                                                                                 "deleted" => [],
         
     | 
| 
      
 595 
     | 
    
         
            +
                                                                                 "conflicts" => []}}}
         
     | 
| 
       547 
596 
     | 
    
         
             
                    return response
         
     | 
| 
       548 
597 
     | 
    
         | 
| 
       549 
598 
     | 
    
         
             
                  end
         
     | 
| 
       550 
     | 
    
         
            -
                  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})
         
     | 
| 
       551 
     | 
    
         
            -
                  CLI.is_response_success(response,false)
         
     | 
| 
      
 599 
     | 
    
         
            +
                  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})
         
     | 
| 
      
 600 
     | 
    
         
            +
                  CLI.is_response_success(response, false)
         
     | 
| 
       552 
601 
     | 
    
         
             
                  return response
         
     | 
| 
       553 
602 
     | 
    
         
             
                end
         
     | 
| 
       554 
     | 
    
         
            -
             
     | 
| 
      
 603 
     | 
    
         
            +
             
     | 
| 
       555 
604 
     | 
    
         
             
                def compare_idx_download(all_files: false, desired_commit: nil)
         
     | 
| 
       556 
605 
     | 
    
         
             
                  current_commit = self.last_local_commit
         
     | 
| 
       557 
606 
     | 
    
         
             
                  next_commit = self.get_next_commit
         
     | 
| 
       558 
607 
     | 
    
         
             
                  ignore_list = self.send_ignore_list()
         
     | 
| 
       559 
     | 
    
         
            -
                  return Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/download_status", 'POST', {current_commit: current_commit, next_commit: next_commit, ignore:ignore_list,all_files:all_files, desired_commit: desired_commit.presence})
         
     | 
| 
      
 608 
     | 
    
         
            +
                  return Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/download_status", 'POST', {current_commit: current_commit, next_commit: next_commit, ignore: ignore_list, all_files: all_files, desired_commit: desired_commit.presence})
         
     | 
| 
       560 
609 
     | 
    
         
             
                end
         
     | 
| 
       561 
610 
     | 
    
         | 
| 
       562 
611 
     | 
    
         
             
                def set_partial_commit(commit_sha1)
         
     | 
| 
         @@ -572,24 +621,25 @@ module Cnvrg 
     | 
|
| 
       572 
621 
     | 
    
         | 
| 
       573 
622 
     | 
    
         | 
| 
       574 
623 
     | 
    
         
             
                def current_status(new_branch)
         
     | 
| 
       575 
     | 
    
         
            -
             
     | 
| 
       576 
     | 
    
         
            -
             
     | 
| 
       577 
     | 
    
         
            -
             
     | 
| 
       578 
     | 
    
         
            -
             
     | 
| 
      
 624 
     | 
    
         
            +
                  commit = last_local_commit
         
     | 
| 
      
 625 
     | 
    
         
            +
                  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/status_current", 'POST', {current_commit: commit, new_branch: new_branch})
         
     | 
| 
      
 626 
     | 
    
         
            +
                  CLI.is_response_success(response, true)
         
     | 
| 
      
 627 
     | 
    
         
            +
                  return response
         
     | 
| 
       579 
628 
     | 
    
         
             
                end
         
     | 
| 
      
 629 
     | 
    
         
            +
             
     | 
| 
       580 
630 
     | 
    
         
             
                def send_ignore_list()
         
     | 
| 
       581 
631 
     | 
    
         
             
                  begin
         
     | 
| 
       582 
632 
     | 
    
         
             
                    ignore_list = []
         
     | 
| 
       583 
     | 
    
         
            -
                    File.open(self.local_path+"/.cnvrgignore", "r").each_line do |line|
         
     | 
| 
      
 633 
     | 
    
         
            +
                    File.open(self.local_path + "/.cnvrgignore", "r").each_line do |line|
         
     | 
| 
       584 
634 
     | 
    
         
             
                      line = line.strip
         
     | 
| 
       585 
635 
     | 
    
         
             
                      if line.start_with? "#" or ignore_list.include? line or line.empty?
         
     | 
| 
       586 
636 
     | 
    
         
             
                        next
         
     | 
| 
       587 
637 
     | 
    
         
             
                      end
         
     | 
| 
       588 
638 
     | 
    
         
             
                      if line.end_with? "/"
         
     | 
| 
       589 
     | 
    
         
            -
                        ignore_list << line.gsub("/","")
         
     | 
| 
       590 
     | 
    
         
            -
                        ignore_list << line+"."
         
     | 
| 
      
 639 
     | 
    
         
            +
                        ignore_list << line.gsub("/", "")
         
     | 
| 
      
 640 
     | 
    
         
            +
                        ignore_list << line + "."
         
     | 
| 
       591 
641 
     | 
    
         
             
                      elsif line.include? "*"
         
     | 
| 
       592 
     | 
    
         
            -
                        line = line.gsub("*",".*")
         
     | 
| 
      
 642 
     | 
    
         
            +
                        line = line.gsub("*", ".*")
         
     | 
| 
       593 
643 
     | 
    
         
             
                        ignore_list << line
         
     | 
| 
       594 
644 
     | 
    
         
             
                      else
         
     | 
| 
       595 
645 
     | 
    
         
             
                        ignore_list << line
         
     | 
| 
         @@ -603,15 +653,14 @@ module Cnvrg 
     | 
|
| 
       603 
653 
     | 
    
         
             
                end
         
     | 
| 
       604 
654 
     | 
    
         | 
| 
       605 
655 
     | 
    
         | 
| 
       606 
     | 
    
         
            -
             
     | 
| 
       607 
     | 
    
         
            -
             
     | 
| 
       608 
656 
     | 
    
         
             
                def compare_commits(commit)
         
     | 
| 
       609 
     | 
    
         
            -
                  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/compare_commits", 'POST', {compare_commit: commit,current_commit:last_local_commit})
         
     | 
| 
       610 
     | 
    
         
            -
                  CLI.is_response_success(response,false)
         
     | 
| 
      
 657 
     | 
    
         
            +
                  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/compare_commits", 'POST', {compare_commit: commit, current_commit: last_local_commit})
         
     | 
| 
      
 658 
     | 
    
         
            +
                  CLI.is_response_success(response, false)
         
     | 
| 
       611 
659 
     | 
    
         
             
                  return response
         
     | 
| 
       612 
660 
     | 
    
         
             
                end
         
     | 
| 
      
 661 
     | 
    
         
            +
             
     | 
| 
       613 
662 
     | 
    
         
             
                def set_next_commit(commit_sha1)
         
     | 
| 
       614 
     | 
    
         
            -
                  if 
     | 
| 
      
 663 
     | 
    
         
            +
                  if !File.exist? "#{self.local_path}/.cnvrg/idx.yml"
         
     | 
| 
       615 
664 
     | 
    
         
             
                    idx_hash = Hash.new()
         
     | 
| 
       616 
665 
     | 
    
         
             
                    idx_hash[:commit] = ""
         
     | 
| 
       617 
666 
     | 
    
         
             
                    idx_hash[:tree] = ""
         
     | 
| 
         @@ -620,37 +669,41 @@ module Cnvrg 
     | 
|
| 
       620 
669 
     | 
    
         | 
| 
       621 
670 
     | 
    
         
             
                  end
         
     | 
| 
       622 
671 
     | 
    
         
             
                  idx_hash[:next_commit] = commit_sha1
         
     | 
| 
       623 
     | 
    
         
            -
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { 
     | 
| 
      
 672 
     | 
    
         
            +
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') {|f| f.write idx_hash.to_yaml}
         
     | 
| 
       624 
673 
     | 
    
         
             
                  return true
         
     | 
| 
       625 
674 
     | 
    
         | 
| 
       626 
675 
     | 
    
         
             
                end
         
     | 
| 
      
 676 
     | 
    
         
            +
             
     | 
| 
       627 
677 
     | 
    
         
             
                def get_next_commit()
         
     | 
| 
       628 
     | 
    
         
            -
                  if 
     | 
| 
      
 678 
     | 
    
         
            +
                  if !File.exist? "#{self.local_path}/.cnvrg/idx.yml"
         
     | 
| 
       629 
679 
     | 
    
         
             
                    return nil
         
     | 
| 
       630 
680 
     | 
    
         
             
                  end
         
     | 
| 
       631 
681 
     | 
    
         
             
                  idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
         
     | 
| 
       632 
682 
     | 
    
         
             
                  return idx_hash[:next_commit]
         
     | 
| 
       633 
683 
     | 
    
         
             
                end
         
     | 
| 
      
 684 
     | 
    
         
            +
             
     | 
| 
       634 
685 
     | 
    
         
             
                def remove_next_commit()
         
     | 
| 
       635 
     | 
    
         
            -
                  if 
     | 
| 
      
 686 
     | 
    
         
            +
                  if !File.exist? "#{self.local_path}/.cnvrg/idx.yml"
         
     | 
| 
       636 
687 
     | 
    
         
             
                    return nil
         
     | 
| 
       637 
688 
     | 
    
         
             
                  end
         
     | 
| 
       638 
689 
     | 
    
         
             
                  idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
         
     | 
| 
       639 
690 
     | 
    
         
             
                  idx = Hash.new()
         
     | 
| 
       640 
691 
     | 
    
         
             
                  idx[:commit] = idx_hash[:next_commit]
         
     | 
| 
       641 
692 
     | 
    
         
             
                  idx[:tree] = idx_hash[:tree]
         
     | 
| 
       642 
     | 
    
         
            -
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { 
     | 
| 
      
 693 
     | 
    
         
            +
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') {|f| f.write idx.to_yaml}
         
     | 
| 
       643 
694 
     | 
    
         
             
                end
         
     | 
| 
      
 695 
     | 
    
         
            +
             
     | 
| 
       644 
696 
     | 
    
         
             
                def revert_next_commit()
         
     | 
| 
       645 
     | 
    
         
            -
                  if 
     | 
| 
      
 697 
     | 
    
         
            +
                  if !File.exist? "#{self.local_path}/.cnvrg/idx.yml"
         
     | 
| 
       646 
698 
     | 
    
         
             
                    return nil
         
     | 
| 
       647 
699 
     | 
    
         
             
                  end
         
     | 
| 
       648 
700 
     | 
    
         
             
                  idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
         
     | 
| 
       649 
701 
     | 
    
         
             
                  idx_hash = idx_hash.except(:next_commit)
         
     | 
| 
       650 
     | 
    
         
            -
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { 
     | 
| 
      
 702 
     | 
    
         
            +
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') {|f| f.write idx_hash.to_yaml}
         
     | 
| 
       651 
703 
     | 
    
         
             
                end
         
     | 
| 
      
 704 
     | 
    
         
            +
             
     | 
| 
       652 
705 
     | 
    
         
             
                def get_current_commit()
         
     | 
| 
       653 
     | 
    
         
            -
                  if 
     | 
| 
      
 706 
     | 
    
         
            +
                  if !File.exist? "#{self.local_path}/.cnvrg/idx.yml"
         
     | 
| 
       654 
707 
     | 
    
         
             
                    return nil
         
     | 
| 
       655 
708 
     | 
    
         
             
                  end
         
     | 
| 
       656 
709 
     | 
    
         
             
                  idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
         
     | 
| 
         @@ -658,50 +711,51 @@ module Cnvrg 
     | 
|
| 
       658 
711 
     | 
    
         
             
                end
         
     | 
| 
       659 
712 
     | 
    
         | 
| 
       660 
713 
     | 
    
         
             
                def compare_commit(commit)
         
     | 
| 
       661 
     | 
    
         
            -
             
     | 
| 
       662 
     | 
    
         
            -
             
     | 
| 
       663 
     | 
    
         
            -
                    end
         
     | 
| 
       664 
     | 
    
         
            -
                    response = Cnvrg::API.request("users/#{self.owner}/projects/#{self.slug}/commit/compare", 'POST', {current_commit: commit})
         
     | 
| 
       665 
     | 
    
         
            -
                    CLI.is_response_success(response,false)
         
     | 
| 
       666 
     | 
    
         
            -
                    update_is_new_branch(response["result"]["new_branch"])
         
     | 
| 
       667 
     | 
    
         
            -
                    return response["result"]["new_branch"]
         
     | 
| 
      
 714 
     | 
    
         
            +
                  if commit.nil? or commit.empty?
         
     | 
| 
      
 715 
     | 
    
         
            +
                    commit = last_local_commit
         
     | 
| 
       668 
716 
     | 
    
         
             
                  end
         
     | 
| 
      
 717 
     | 
    
         
            +
                  response = Cnvrg::API.request("users/#{self.owner}/projects/#{self.slug}/commit/compare", 'POST', {current_commit: commit})
         
     | 
| 
      
 718 
     | 
    
         
            +
                  CLI.is_response_success(response, false)
         
     | 
| 
      
 719 
     | 
    
         
            +
                  update_is_new_branch(response["result"]["new_branch"])
         
     | 
| 
      
 720 
     | 
    
         
            +
                  return response["result"]["new_branch"]
         
     | 
| 
      
 721 
     | 
    
         
            +
                end
         
     | 
| 
       669 
722 
     | 
    
         | 
| 
       670 
     | 
    
         
            -
             
     | 
| 
       671 
     | 
    
         
            -
             
     | 
| 
       672 
     | 
    
         
            -
             
     | 
| 
       673 
     | 
    
         
            -
             
     | 
| 
       674 
     | 
    
         
            -
             
     | 
| 
       675 
     | 
    
         
            -
                    files.each do |path|
         
     | 
| 
       676 
     | 
    
         
            -
                      idx_hash[:tree].to_h[path].to_h[:commit_time] = commit_time
         
     | 
| 
       677 
     | 
    
         
            -
                    end
         
     | 
| 
       678 
     | 
    
         
            -
                    idx_hash[:next_commit] = idx_hash[:next_commit]
         
     | 
| 
       679 
     | 
    
         
            -
                    File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { |f| f.write idx_hash.to_yaml }
         
     | 
| 
      
 723 
     | 
    
         
            +
                def update_idx_with_files_commits!(files, commit_time)
         
     | 
| 
      
 724 
     | 
    
         
            +
                  # files.flatten!
         
     | 
| 
      
 725 
     | 
    
         
            +
                  idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
         
     | 
| 
      
 726 
     | 
    
         
            +
                  # idx_hash[:commit] = commit
         
     | 
| 
       680 
727 
     | 
    
         | 
| 
       681 
     | 
    
         
            -
             
     | 
| 
      
 728 
     | 
    
         
            +
                  files.each do |path|
         
     | 
| 
      
 729 
     | 
    
         
            +
                    idx_hash[:tree].to_h[path].to_h[:commit_time] = commit_time
         
     | 
| 
       682 
730 
     | 
    
         
             
                  end
         
     | 
| 
       683 
     | 
    
         
            -
             
     | 
| 
       684 
     | 
    
         
            -
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { 
     | 
| 
      
 731 
     | 
    
         
            +
                  idx_hash[:next_commit] = idx_hash[:next_commit]
         
     | 
| 
      
 732 
     | 
    
         
            +
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') {|f| f.write idx_hash.to_yaml}
         
     | 
| 
       685 
733 
     | 
    
         | 
| 
       686 
734 
     | 
    
         
             
                  return true
         
     | 
| 
       687 
735 
     | 
    
         
             
                end
         
     | 
| 
       688 
736 
     | 
    
         | 
| 
      
 737 
     | 
    
         
            +
                def update_idx(idx)
         
     | 
| 
      
 738 
     | 
    
         
            +
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') {|f| f.write idx.to_yaml}
         
     | 
| 
      
 739 
     | 
    
         
            +
             
     | 
| 
      
 740 
     | 
    
         
            +
                  return true
         
     | 
| 
      
 741 
     | 
    
         
            +
                end
         
     | 
| 
       689 
742 
     | 
    
         | 
| 
       690 
     | 
    
         
            -
                  def update_idx_with_commit!(commit)
         
     | 
| 
       691 
     | 
    
         
            -
                    idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
         
     | 
| 
       692 
     | 
    
         
            -
                    idx_hash[:commit] = commit
         
     | 
| 
       693 
743 
     | 
    
         | 
| 
       694 
     | 
    
         
            -
             
     | 
| 
       695 
     | 
    
         
            -
             
     | 
| 
       696 
     | 
    
         
            -
                   
     | 
| 
      
 744 
     | 
    
         
            +
                def update_idx_with_commit!(commit)
         
     | 
| 
      
 745 
     | 
    
         
            +
                  idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
         
     | 
| 
      
 746 
     | 
    
         
            +
                  idx_hash[:commit] = commit
         
     | 
| 
       697 
747 
     | 
    
         | 
| 
       698 
     | 
    
         
            -
                   
     | 
| 
       699 
     | 
    
         
            -
             
     | 
| 
       700 
     | 
    
         
            -
             
     | 
| 
       701 
     | 
    
         
            -
                    # CLI.is_response_success(response)
         
     | 
| 
      
 748 
     | 
    
         
            +
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') {|f| f.write idx_hash.to_yaml}
         
     | 
| 
      
 749 
     | 
    
         
            +
                  return true
         
     | 
| 
      
 750 
     | 
    
         
            +
                end
         
     | 
| 
       702 
751 
     | 
    
         | 
| 
      
 752 
     | 
    
         
            +
                def revert(working_dir)
         
     | 
| 
      
 753 
     | 
    
         
            +
                  FileUtils.rm_rf working_dir
         
     | 
| 
      
 754 
     | 
    
         
            +
                  # response     = Cnvrg::API.request("users/#{self.owner}/projects/#{self.slug}/revert", 'GET')
         
     | 
| 
      
 755 
     | 
    
         
            +
                  # CLI.is_response_success(response)
         
     | 
| 
       703 
756 
     | 
    
         | 
| 
       704 
     | 
    
         
            -
                  end
         
     | 
| 
       705 
757 
     | 
    
         | 
| 
       706 
758 
     | 
    
         
             
                end
         
     | 
| 
      
 759 
     | 
    
         
            +
             
     | 
| 
       707 
760 
     | 
    
         
             
              end
         
     | 
| 
      
 761 
     | 
    
         
            +
            end
         
     |