Class: MiGA::Cli::Action::GetDb
- Inherits:
-
MiGA::Cli::Action
- Object
- MiGA
- MiGA::Cli::Action
- MiGA::Cli::Action::GetDb
- Defined in:
- lib/miga/cli/action/get_db.rb
Constant Summary
Constants included from MiGA
MiGA::CITATION, VERSION, VERSION_DATE, VERSION_NAME
Instance Attribute Summary
Attributes inherited from MiGA::Cli::Action
Instance Method Summary collapse
Methods inherited from MiGA::Cli::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
Methods included from MiGA::Common::Format
#clean_fasta_file, #seqs_length, #tabulate
Methods included from MiGA::Common::Net
#download_file_ftp, #known_hosts
Methods included from MiGA::Common::SystemCall
Constructor Details
This class inherits a constructor from MiGA::Cli::Action
Instance Method Details
#complete ⇒ Object
85 86 87 88 |
# File 'lib/miga/cli/action/get_db.rb', line 85 def complete @ftp.close unless @ftp.nil? super end |
#empty_action ⇒ Object
81 82 83 |
# File 'lib/miga/cli/action/get_db.rb', line 81 def empty_action cli.puts 'Downloading latest version of the default database' end |
#parse_cli ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/miga/cli/action/get_db.rb', line 8 def parse_cli cli.defaults = { database: :recommended, version: :latest, local: File.('.miga_db', ENV['MIGA_HOME']), host: MiGA::MiGA.known_hosts(:miga_db), pb: true, reuse_archive: false, overwrite: true } cli.parse do |opt| opt.on( '-n', '--database STRING', "Name of the database to download. By default: #{cli[:database]}" ) { |v| cli[:database] = v.to_sym } opt.on( '--db-version STRING', "Database version to download. By default: #{cli[:version]}" ) { |v| cli[:version] = v.to_sym } opt.on( '-l', '--local-dir PATH', "Local directory to store the database. By default: #{cli[:local]}" ) { |v| cli[:local] = v } opt.on( '-h', '--host STRING', "Remote host of the database. By default: #{cli[:host]}" ) { |v| cli[:db] = v.to_sym } opt.on( '--list', 'List available databases and exit' ) { |v| cli[:list_databases] = v } opt.on( '--list-versions', 'List available versions of the database and exit' ) { |v| cli[:list_versions] = v } opt.on( '--reuse-archive', 'Reuse a previously downloaded archive if available' ) { |v| cli[:reuse_archive] = v } opt.on( '--no-overwrite', 'Exit without downloading if the target database already exists' ) { |v| cli[:overwrite] = v } opt.on('--no-progress', 'Supress progress bars') { |v| cli[:pb] = v } end end |
#perform ⇒ Object
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 |
# File 'lib/miga/cli/action/get_db.rb', line 55 def perform # Quick check when the database is not an alias dir = File.join(cli[:local], cli[:database].to_s) if !cli[:overwrite] && Dir.exist?(dir) cli.puts "Database exists: #{dir}" return end # Remote manifest @ftp = remote_connection manif = remote_manifest(@ftp) cli.puts "# Host: #{manif[:host]}" cli.puts "# Manifest last update: #{manif[:last_update]}" list_databases(manif) and return db = db_requested(manif) list_versions(db) and return ver = version_requested(db) check_target and return # Download and expand file = download_file(@ftp, ver[:path], cli[:reuse_archive]) check_digest(ver, file) unarchive(file) register_database(manif, db, ver) end |