Class: Quandl::Command::Tasks::Update

Inherits:
Quandl::Command::Task show all
Defined in:
lib/quandl/command/tasks/update.rb

Defined Under Namespace

Classes: QuandlUtils

Constant Summary collapse

PACKAGE_URL =
'http://s3.amazonaws.com/quandl-command/'

Constants included from Quandl::Command::Task::Updatable

Quandl::Command::Task::Updatable::VERSION_URL

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Quandl::Command::Task::Inputable

#args_or_stdin, #each_line_in_background, #file_or_stdin

Methods included from Quandl::Command::Task::Reportable

#ask_to_send_crash_reports, #call

Methods included from Quandl::Command::Task::Clientable

#current_user

Methods included from Quandl::Command::Task::Updatable

#check_for_update, #check_for_update_once_daily

Methods included from Quandl::Command::Task::Threading

#await_thread_pool_lock!, #background_job, #exiting?, #mutex, #obtain_thread_pool_lock, #release_thread_pool_lock, #shutdown_thread_pool_on_sigint, #thread_pool, #thread_pool_locked?, #thread_pool_locks, #threads, #threads?

Methods included from Quandl::Command::Task::Presentation

#present

Methods included from Quandl::Command::Task::Logging

#configure_logger, #debug, #error, #fatal, #info, #initialize_logger, #log_request_time, #logger, #start_request_timer, #stderr_logger, #summarize, #summarize_hash, #table

Methods included from Quandl::Command::Task::Commandable

#initialize

Methods included from Quandl::Command::Task::Validations

#run_task_validations!

Methods included from Quandl::Command::Task::Callbacks

#call

Methods included from Quandl::Command::Task::Configurable

#ask_for_confirmation!, #config, #confirmed?, #declared_params, #force_yes?, #page, #trace?, #verbose?

Class Method Details

.package_url(revision = nil) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/quandl/command/tasks/update.rb', line 23

def package_url(revision=nil)
  # are we on windows?
  platform = Quandl::Utility::Config.windows? ? 'windows' : nil
  # build filename
  filename = ['quandl-command', platform, revision, 'tar.gz'].compact.join(".")
  # append s3 url
  File.join(PACKAGE_URL, filename)
end

Instance Method Details

#executeObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/quandl/command/tasks/update.rb', line 33

def execute
  if args[0] == 'rollback'
    execute_rollback
  else
    execute_update
  end
rescue => err
  # log error
  error(err)
  debug(err.backtrace.join("\n"))
  # report failure and rollback
  error("----\nAn error has occured! Rolling back to previous version ... ")
  error("If the problem persists reinstall with: #{installer_url}")
  rollback_update
end

#execute_rollbackObject



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/quandl/command/tasks/update.rb', line 67

def execute_rollback
  info "Rolling back from #{current_timestamp} ... "
  previous_timestamp = find_timestamp_before(current_timestamp)
  if previous_timestamp.blank?
    info("nothing to rollback to!")
    return false 
  end
  info "to: #{previous_timestamp}"
  install_timestamp( previous_timestamp )
  version = %x{quandl -v}.to_s.strip.rstrip
  info "You have rolled back! ( #{version} )"
end

#execute_updateObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/quandl/command/tasks/update.rb', line 49

def execute_update
  info "Updating from #{Quandl::Command::VERSION} ... "
  # wipe update/ and backup/ folders
  prepare_for_update
  download_tarball
  # ensure package was downloaded
  return error("'#{package_url}' not found") unless File.exists?(tarball_path)
  # install
  extract_tarball
  install_update
  install_executable
  # success
  version = %x{quandl -v}.to_s.strip.rstrip
  cleanup_releases
  
  info "You are up to date! ( #{version} )"
end

#installer_urlObject



80
81
82
83
# File 'lib/quandl/command/tasks/update.rb', line 80

def installer_url
  return File.join(PACKAGE_URL, "Quandl Setup.exe") if Quandl::Utility::Config.windows?
  return File.join(PACKAGE_URL, "quandl-toolbelt.pkg") if Quandl::Utility::Config.macosx?
end