class MiGA::Cli::Action::Init

Public Instance Methods

empty_action() click to toggle source
# File lib/miga/cli/action/init.rb, line 61
def empty_action
end
install_r_package(cli, paths, pkg) click to toggle source
# File lib/miga/cli/action/init.rb, line 78
def install_r_package(cli, paths, pkg)
  r_cmd = "install.packages('#{pkg}', repos='http://cran.rstudio.com/')"
  run_r_cmd(cli, paths, r_cmd)
end
install_ruby_gem(cli, paths, pkg) click to toggle source
# File lib/miga/cli/action/init.rb, line 89
def install_ruby_gem(cli, paths, pkg)
  gem_cmd = "Gem::GemRunner.new.run %w(install --user #{pkg})"
  run_cmd(cli, "#{paths['ruby'].shellescape} \
      -r rubygems -r rubygems/gem_runner \
      -e #{gem_cmd.shellescape} 2>&1")
end
list_requirements() click to toggle source
# File lib/miga/cli/action/init.rb, line 96
def list_requirements
  if cli.ask_user(
        'Would you like to see all the requirements before starting?',
        'no', %w(yes no)) == 'yes'
    cli.puts ''
    req_path = File.expand_path('utils/requirements.txt', MiGA.root_path)
    File.open(req_path, 'r') do |fh|
      fh.each_line { |ln| cli.puts ln }
    end
    cli.puts ''
  end
end
parse_cli() click to toggle source
# File lib/miga/cli/action/init.rb, line 11
def parse_cli
  cli.interactive = true
  cli.defaults = { mytaxa: nil,
    config: File.expand_path('.miga_modules', ENV['HOME']),
    ask: false, auto: false, dtype: :bash }
  cli.parse do |opt|
    opt.on(
      '-c', '--config PATH',
      'Path to the Bash configuration file',
      "By default: #{cli[:config]}"
    ){ |v| cli[:config] = v }
    opt.on(
      '--[no-]mytaxa',
      'Should I try setting up MyTaxa its dependencies?',
      'By default: interactive (true if --auto)'
    ){ |v| cli[:mytaxa] = v }
    opt.on(
      '--daemon-type STRING',
      'Type of daemon launcher, one of: bash, qsub, msub, slurm',
      "By default: interactive (#{cli[:dtype]} if --auto)"
    ){ |v| cli[:dtype] = v.to_sym }
    opt.on(
      '--ask-all',
      'Ask for the location of all software',
      'By default, only the locations missing in PATH are requested'
    ){ |v| cli[:ask] = v }
  end
end
perform() click to toggle source
# File lib/miga/cli/action/init.rb, line 40
  def perform
    cli.puts <<BANNER
===[ Welcome to MiGA, the Microbial Genome Atlas ]===

I'm the initialization script, and I'll sniff around your computer to
make sure you have all the requirements for MiGA data processing.

BANNER
    list_requirements
    rc_fh = open_rc_file
    check_configuration_script rc_fh
    paths = check_software_requirements rc_fh
    check_additional_files paths
    check_r_packages paths
    check_ruby_gems paths
    configure_daemon
    close_rc_file rc_fh
    cli.puts 'Configuration complete. MiGA is ready to work!'
    cli.puts ''
  end
run_cmd(cli, cmd) click to toggle source
# File lib/miga/cli/action/init.rb, line 64
def run_cmd(cli, cmd)
  %x. "#{cli[:config]}" && #{cmd}`
end
run_r_cmd(cli, paths, cmd) click to toggle source
# File lib/miga/cli/action/init.rb, line 68
def run_r_cmd(cli, paths, cmd)
  run_cmd(cli,
    "echo #{cmd.shellescape} | #{paths['R'].shellescape} --vanilla -q 2>&1")
end
test_r_package(cli, paths, pkg) click to toggle source
# File lib/miga/cli/action/init.rb, line 73
def test_r_package(cli, paths, pkg)
  run_r_cmd(cli, paths, "library('#{pkg}')")
  $?.success?
end
test_ruby_gem(cli, paths, pkg) click to toggle source
# File lib/miga/cli/action/init.rb, line 83
def test_ruby_gem(cli, paths, pkg)
  run_cmd(cli,
    "#{paths['ruby'].shellescape} -r #{pkg.shellescape} -e '' 2>/dev/null")
  $?.success?
end