Class: MiGA::Cli::Action::Archive

Inherits:
MiGA::Cli::Action show all
Defined in:
lib/miga/cli/action/archive.rb

Constant Summary

Constants included from MiGA

MiGA::CITATION, VERSION, VERSION_DATE, VERSION_NAME

Instance Attribute Summary

Attributes inherited from MiGA::Cli::Action

#cli

Attributes included from MiGA::Common::Net

#remote_connection_uri

Instance Method Summary collapse

Methods inherited from MiGA::Cli::Action

#complete, #empty_action, #initialize, #launch, load, #name

Methods inherited from MiGA

CITATION, CITATION_ARRAY, DEBUG, DEBUG_OFF, DEBUG_ON, DEBUG_TRACE_OFF, DEBUG_TRACE_ON, FULL_VERSION, LONG_VERSION, VERSION, VERSION_DATE, #advance, debug?, debug_trace?, initialized?, #like_io?, #num_suffix, rc_path, #result_files_exist?, #say

Methods included from MiGA::Common::Path

#root_path, #script_path

Methods included from MiGA::Common::Format

#clean_fasta_file, #seqs_length, #tabulate

Methods included from MiGA::Common::Net

#download_file_ftp, #http_request, #known_hosts, #main_server, #net_method, #normalize_encoding, #remote_connection

Methods included from MiGA::Common::SystemCall

#run_cmd, #run_cmd_opts

Constructor Details

This class inherits a constructor from MiGA::Cli::Action

Instance Method Details

#parse_cliObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/miga/cli/action/archive.rb', line 8

def parse_cli
  cli.parse do |opt|
    opt.on(
      '-o', '--tarball PATH',
      '(Mandatory) Path to the archive to be created ending in .tar.gz'
    ) { |v| cli[:tarball] = v }
    opt.on(
      '-f', '--folder STRING',
      'Name of the output folder. By default: name of the source project'
    ) { |v| cli[:folder] = v }
    cli.opt_object(opt, [:project, :dataset_opt])
    cli.opt_filter_datasets(opt)
  end
end

#performObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/miga/cli/action/archive.rb', line 23

def perform
  cli.ensure_par(tarball: '-o')
  unless cli[:tarball] =~ /\.tar\.gz$/
    raise 'The tarball path (-o) must have .tar.gz extension'
  end

  cli[:folder] ||= cli.load_project.name
  ds = cli.load_and_filter_datasets

  open_tarball do |tar|
    # Datasets
    cli.say 'Archiving datasets'
    each_file_listed(ds) do |rel_path, abs_path|
      add_file_to_tar(tar, rel_path, abs_path)
    end

    # Project
    cli.say 'Archiving project'
    pmd = cli.load_project..dup
    pmd[:datasets] = ds.map(&:name)
    add_string_to_tar(tar, 'miga.project.json', pmd.to_json)
    add_string_to_tar(tar, 'daemon/daemon.json', '{}')
  end
end