Class: Babushka::Task

Inherits:
Object show all
Includes:
LogHelpers, PathHelpers, ShellHelpers
Defined in:
lib/babushka/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ShellHelpers

cmd_dir, current_username, log_shell, login_shell, raw_shell, shell, shell!, shell?, shell_cmd, sudo, which

Methods included from LogHelpers

debug, deprecated!, log, log_block, log_error, log_ok, log_stderr, log_warn, removed!

Methods included from PathHelpers

cd, in_build_dir, in_download_dir

Constructor Details

#initializeTask



9
10
11
# File 'lib/babushka/task.rb', line 9

def initialize
  clear
end

Instance Attribute Details

#cmdObject (readonly)

Returns the value of attribute cmd



7
8
9
# File 'lib/babushka/task.rb', line 7

def cmd
  @cmd
end

#current_depObject (readonly)

Returns the value of attribute current_dep



7
8
9
# File 'lib/babushka/task.rb', line 7

def current_dep
  @current_dep
end

#persistent_logObject (readonly)

Returns the value of attribute persistent_log



7
8
9
# File 'lib/babushka/task.rb', line 7

def persistent_log
  @persistent_log
end

Instance Method Details

#clearObject



13
14
15
16
# File 'lib/babushka/task.rb', line 13

def clear
  @cmd = nil
  @running = false
end

#log_path_for(dep) ⇒ Object



49
50
51
# File 'lib/babushka/task.rb', line 49

def log_path_for dep
  log_prefix / dep.contextual_name
end

#open_log!(mode = 'a') ⇒ Object



53
54
55
56
57
# File 'lib/babushka/task.rb', line 53

def open_log! mode = 'a'
  log_prefix.mkdir
  @persistent_log.try(:close) # If the log was already open, close it.
  @persistent_log = log_path_for(current_dep).open(mode).tap {|f| f.sync = true }
end

#opt(name) ⇒ Object



41
42
43
# File 'lib/babushka/task.rb', line 41

def opt name
  cmd.opts[name] unless cmd.nil?
end

#process(dep_names, with_args, cmd) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/babushka/task.rb', line 18

def process dep_names, with_args, cmd
  raise "A task is already running." if running?
  @cmd = cmd
  @running = true
  cleanup_obsolete_data # TODO: remove after August '13 or so.
  dep_names.all? {|dep_name| process_dep(dep_name, with_args) }
rescue SourceLoadError => e
  Babushka::Logging.log_exception(e)
ensure
  clear
end

#process_dep(dep_name, with_args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/babushka/task.rb', line 30

def process_dep dep_name, with_args
  Base.sources.find_or_suggest(dep_name) do |dep|
    @current_dep = dep
    with_logging {
      dep.with(task_args_for(dep, with_args)).process(!opt(:dry_run))
    }.tap {
      @current_dep = nil
    }
  end
end

#running?Boolean



45
46
47
# File 'lib/babushka/task.rb', line 45

def running?
  @running
end