Class: Redmine::Installer::Exec

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/redmine-installer/exec.rb

Constant Summary collapse

REFRESH_TIMER =

in s

1

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

included

Constructor Details

#initialize(command, title = nil, timer = true) ⇒ Exec

Returns a new instance of Exec.



15
16
17
18
19
20
# File 'lib/redmine-installer/exec.rb', line 15

def initialize(command, title=nil, timer=true)
  @command = command

  with_title(title)
  with_timer(timer)
end

Instance Attribute Details

#stderrObject (readonly)

Returns the value of attribute stderr.



13
14
15
# File 'lib/redmine-installer/exec.rb', line 13

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



13
14
15
# File 'lib/redmine-installer/exec.rb', line 13

def stdout
  @stdout
end

Instance Method Details

#run(repeatable = false) ⇒ Object



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
77
# File 'lib/redmine-installer/exec.rb', line 40

def run(repeatable=false)
  show_title

  Open3.popen3(@command) do |stdin, stdout, stderr, wait_thr|
    # log = StringIO.new
    # redirect_stream(stdout, log)
    # redirect_stream(stderr, log)

    # For example: rake db:create can ask for root login
    # if current setting does not work
    # stdin.closes

    exit_status = wait_thr.value
    @stdout = stdout.read
    @stderr = stderr.read

    stop_timer
    if exit_status.success?
      print_result(true)
      @return_value = true
    else
      print_result(false)
      @return_value = false
      # raise Redmine::Installer::Error, stderr.read
    end
  end

  unless success
    # print_error
    if repeatable && repeat?
      return run(repeatable)
    end
  end

  return success
ensure
  # stop_timer
end

#with_timer(yes_no) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/redmine-installer/exec.rb', line 31

def with_timer(yes_no)
  if $stdout.tty?
    @with_timer = yes_no
  else
    @with_timer = false
  end
  self
end

#with_title(title) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/redmine-installer/exec.rb', line 22

def with_title(title)
  if title.is_a?(Symbol)
    title = I18n.translate(title)
  end

  @title = title
  self
end