Class: Cnvrg::Data

Inherits:
SubCommandBase show all
Defined in:
lib/cnvrg/data.rb

Defined Under Namespace

Modules: ConfigValidation

Instance Method Summary collapse

Methods inherited from SubCommandBase

banner, subcommand_prefix

Instance Method Details

#block(*dataset_slugs) ⇒ Object



199
200
201
202
203
204
# File 'lib/cnvrg/data.rb', line 199

def block(*dataset_slugs)
  not_verified = true
  while not_verified
    not_verified = dataset_slugs.select{|slug| not Dataset.verify_dataset(slug)}.present?
  end
end

#clone(dataset_url) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/cnvrg/data.rb', line 158

def clone(dataset_url)
  cli = Cnvrg::CLI.new()
  only_tree =options[:only_tree]
  commit =options[:commit]
  query =options[:query]
  read = options[:read]
  remote = options[:remote]
  soft = options[:soft]
  flatten = options[:flatten]
  threads = options[:threads]
  cache_link = options[:cache_link]
  cli.clone_data(
      dataset_url,
      only_tree=only_tree,
      commit=commit,
      query=query,
      read=read,
      remote=remote,
      flatten: flatten,
      relative: options[:relative],
      soft: soft,
      threads: threads,
      cache_link: cache_link
  )
end

#clone_query(dataset_url) ⇒ Object



277
278
279
280
281
282
283
# File 'lib/cnvrg/data.rb', line 277

def clone_query(dataset_url)
  cli = Cnvrg::CLI.new()
  query = options[:query]
  flatten = options[:flatten]
  soft =options[:soft]
  cli.clone_data_query(dataset_url,query=query, flatten, soft: soft)
end

#commits(dataset_url) ⇒ Object



301
302
303
304
305
# File 'lib/cnvrg/data.rb', line 301

def commits(dataset_url)
  cli = Cnvrg::CLI.new()
  commit_sha1 = options[:commit_sha1]
  cli.list_dataset_commits(dataset_url, commit_sha1:commit_sha1)
end

#delete(dataset_slug) ⇒ Object



286
287
288
289
290
# File 'lib/cnvrg/data.rb', line 286

def delete(dataset_slug)
  cli = Cnvrg::CLI.new()
  cli.delete_data(dataset_slug)

end

#downloadObject



138
139
140
141
142
143
144
145
146
# File 'lib/cnvrg/data.rb', line 138

def download()
  cli = Cnvrg::CLI.new()
  verbose = options["verbose"]
  sync = options["sync"]
  new_branch = options["new_branch"]
  commit = options["commit"]
  all_files = options["all_files"]
  cli.download_data_new(verbose,sync,new_branch, commit,all_files)
end

#download_tags_yamlObject



338
339
340
341
# File 'lib/cnvrg/data.rb', line 338

def download_tags_yaml
  cli = Cnvrg::CLI.new()
  cli.download_tags_yaml()
end

#files(dataset_url) ⇒ Object



312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/cnvrg/data.rb', line 312

def files(dataset_url)
  cli = Cnvrg::CLI.new()
  cli.verify_logged_in(false)
  cli.log_start(__method__, args, options)
  @dataset = Dataset.new(dataset_url: dataset_url)
  files = @dataset.list_files(
      commit_sha1: options[:commit_sha1],
      limit: options[:limit],
      expires: options[:expires],
      offset: options[:offset])
  cli.log_message(files)
end

#initObject



27
28
29
30
31
32
33
# File 'lib/cnvrg/data.rb', line 27

def init
  cli = Cnvrg::CLI.new()
  public = options["public"]
  bucket = options["bucket"]
  title = options["title"]
  cli.init_data(public, bucket: bucket, title: title)
end


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/cnvrg/data.rb', line 36

def link(dataset=nil)
  begin
    cli = Cnvrg::CLI.new()
    cli.verify_logged_in(false)
    cli.log_start(__method__, args, options)
    
    if dataset.include? "/"
      ## this case is to support DATASET_URL expected example: domain.com/organization_name/datasets/dataset_name
      url_parts = dataset.split("/")
      dataset_index = Cnvrg::Helpers.look_for_in_path(dataset, "datasets")
      dataset_slug = url_parts[dataset_index + 1]
      owner = url_parts[dataset_index - 1]
      raise Exception.new("Can't find all dataset information please check the URL") if dataset_slug.blank? or owner.blank?
    else
      ## this case is to support DATASET_SLUG expected example: dataset_name
      # in this case it will take the organization from the config file
      dataset_slug = dataset
      raise Exception.new("Please enter dataset name or dataset full url") if dataset_slug.blank?
      owner = CLI.get_owner
    end

    config_validation = Dataset.validate_config
    if config_validation[:validation] == Data::ConfigValidation::SUCCESS
      cli.log_message(config_validation[:message])
      return
    else
      Cnvrg::Logger.log_error_message(config_validation)
      FileUtils.rmtree(".cnvrg")
    end

    cli.log_message("Linking dataset: #{dataset_slug} to the current directory", Thor::Shell::Color::BLUE)
    success = Dataset.link_dataset(owner: owner, slug: dataset_slug)
    if success
      cli.log_message("Dataset: #{dataset_slug} linked successfully to the current directory")
    else
      cli.log_message("Linking failed\nAborting", Thor::Shell::Color::RED)
    end
  rescue => e
    Cnvrg::Logger.log_error(e)
    cli.log_message("Aborting\n#{e.message}", Thor::Shell::Color::RED)
    exit(1)
  rescue Exception => e
    Cnvrg::Logger.log_error(e)
    cli.log_message("Aborting\n#{e.message}", Thor::Shell::Color::RED)
    exit(1)
  end
end

#listObject



292
293
294
295
296
297
# File 'lib/cnvrg/data.rb', line 292

def list()
  cli = Cnvrg::CLI.new()

  cli.list_dataset()

end

#put(dataset_url, *files) ⇒ Object



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/cnvrg/data.rb', line 228

def put(dataset_url, *files)
  cli = Cnvrg::CLI.new()
  dir = options[:dir]
  force = options[:force]
  override = options[:override]
  # commit = options[:commit]
  commit = ''
  message = options[:message]
  threads = options[:threads]
  chunk_size = options[:chunk_size]
  auto_cache = options[:auto_cache]
  external_disk = options[:external_disk]
  cli.data_put(
    dataset_url,
    files: files,
    dir: dir,
    commit: commit,
    force: force,
    override: override,
    threads: threads,
    chunk_size: chunk_size,
    message: message,
    auto_cache: auto_cache,
    external_disk: external_disk
  )
end

#queriesObject



326
327
328
329
# File 'lib/cnvrg/data.rb', line 326

def queries()
  cli = Cnvrg::CLI.new()
  cli.queries()
end

#query_files(query) ⇒ Object



332
333
334
335
# File 'lib/cnvrg/data.rb', line 332

def query_files(query)
  cli = Cnvrg::CLI.new()
  cli.query_files(query)
end

#rm(dataset_url, *regex_list) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/cnvrg/data.rb', line 259

def rm(dataset_url, *regex_list)
  cli = Cnvrg::CLI.new()
  message = options[:message]
  auto_cache = options[:auto_cache]
  external_disk = options[:external_disk]
  cli.data_rm(
    dataset_url,
    regex_list: regex_list,
    message: message,
    auto_cache: auto_cache,
    external_disk: external_disk
  )
end

#scanObject



193
194
195
196
# File 'lib/cnvrg/data.rb', line 193

def scan()
  cli = Cnvrg::CLI.new()
  cli.scan_datasets()
end

#setObject



208
209
210
211
212
213
214
215
# File 'lib/cnvrg/data.rb', line 208

def set
  cli = Cnvrg::CLI.new
  cli.log_start(__method__)
  cli.log_handler
  if options['url'].present?
    cli.set_data_url(options['url'])
  end
end

#sync_data_newObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/cnvrg/data.rb', line 116

def sync_data_new()
  cli = Cnvrg::CLI.new()
  force = options["force"]
  new_branch = options["new_branch"]
  verbose = options["verbose"]
  commit = options["commit"]
  all_files = options["all_files"]
  tags = options["tags"]
  parallel=options["parallel"]
  chunk_size = options["chunk_size"]
  init = options["init"]
  message = options["message"]
  cli.sync_data_new(new_branch, force, verbose, commit, all_files, tags, parallel, chunk_size, init, message)
end

#test(data_url) ⇒ Object



345
346
347
348
349
350
351
352
353
354
# File 'lib/cnvrg/data.rb', line 345

def test(data_url)
  cli = Cnvrg::CLI.new
  cli.verify_logged_in(true)
  cli.log_start(__method__, args, options)
  @dataset = Dataset.new(dataset_url: data_url)
  resp = @dataset.get_storage_client
  @dataset.init_home(remote: false)
  @dataset.download_softlink

end

#uploadObject



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/cnvrg/data.rb', line 93

def upload
  cli = Cnvrg::CLI.new()
  verbose = options["verbose"]
  sync = options["sync"]
  force = options["force"]
  new_branch = options["new_branch"]
  chunk_size = options["chunk_size"]
  tags = options["tags"]
  message = options["message"]
  cli.upload_data_new(new_branch, verbose, sync, force, tags, chunk_size, message:message)
end

#verify(*dataset_titles) ⇒ Object



186
187
188
189
190
# File 'lib/cnvrg/data.rb', line 186

def verify(*dataset_titles)
  cli = Cnvrg::CLI.new()
  timeout =options[:timeout]
  cli.verify_datasets(dataset_titles, timeout)
end