Class: EPC::Command::PullCommand

Inherits:
BaseCommand show all
Defined in:
lib/epc/command/pull_command.rb

Constant Summary collapse

SLEEP_TIME =
1
TICKER_TICKS =

Numerators are in secs

25/SLEEP_TIME
GIVEUP_TICKS =
120/SLEEP_TIME

Instance Attribute Summary

Attributes inherited from BaseCommand

#client, #klass_name, #object_id, #object_type, #options, #target_id, #target_type

Instance Method Summary collapse

Methods inherited from BaseCommand

#check_options, #context_params, #context_params=, #go, include_module, inherited, #initialize, required_options, #say_err

Methods included from PersistentAttributes

#auth_token, #caller_id, #target_url

Constructor Details

This class inherits a constructor from EPC::Command::BaseCommand

Instance Method Details

#execute(solution_name = nil) ⇒ Object



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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/epc/command/pull_command.rb', line 13

def execute(solution_name = nil)
  first_time_pull = false
  
  path = File.expand_path(".")
  create_dir = false

  if numeric?(solution_name)
    solution_name = get_resource_name(EPC::Config::SOLUTIONS_PATH, :id, solution_name)
  end

  if !EPC::Config.is_solution_dir?(path) && !EPC::Config.is_project_dir?(path)
    if solution_name.nil?
      raise FatalError, "Solution could not be inferred"
    else
      create_dir = true
      first_time_pull = true
    end
  elsif EPC::Config.is_project_dir?(path)
    path = File.join(path, "..")
  end

  return unless check_pull_directory(project_solution_path(path))
  
  solution_name = EPC::Config.get_solution_value(project_solution_path(path), "name") if solution_name.nil?

  proceed = ask_yn("You are pulling the '#{solution_name}' solution. Correct? [Yn]: ")
  if proceed.upcase == 'N'
    return 1
  end

  
  begin
    status, id = create_pull(solution_name)
    if status.successful?
      say("Pulling - ")
      success, url, response = poll_for_pull_url(id)
      if success
        zip_path = nil
        if url
          tmpdir = Dir.tmpdir
          pulled, zip_path = pull_zip(url, tmpdir)
          return 1 unless pulled
        end
        if create_dir
          return 1 unless prep_solution_directory(path, solution_name)
          path = File.join(path, solution_name)
        end
        if zip_path
          unzip_solution(zip_path, path)
          confirm_pull(id)
        end
        refresh_command = EPC::Command::RefreshSolutionCommand.new(client, @options)
        refresh_command.options[:prompt_refresh] = false if first_time_pull
        refresh_command.execute(path)
        return 0
      else
        say_err("\nCould not retrieve URL")
      end
    end
  rescue Exception => ex
    say_err("Pull failed [#{ex.to_s}].")
  end
  return 1
end