Class: Populus::RemoteRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/populus/remote_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(backend, &run_it) ⇒ RemoteRunner

Returns a new instance of RemoteRunner.



8
9
10
11
# File 'lib/populus/remote_runner.rb', line 8

def initialize(backend, &run_it)
  @backend = backend
  instance_exec(&run_it)
end

Instance Method Details

#create_file(path, template = "", context = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/populus/remote_runner.rb', line 22

def create_file(path, template="", context=nil)
  file = Tempfile.new(".populus-tmp")
  content = ERB.new(template).result(context || binding)
  file.write content
  file.close
  @backend.send_file(file.path, path)
  Populus.logger.info("Created Successfully: %s" % path)

  FileUtils.rm_f(file.path)
end

#execute(*command) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/populus/remote_runner.rb', line 13

def execute(*command)
  Populus.logger.info("Running command: %s" % command.inspect)

  res = @backend.run_command(command.join(" "))
  Populus.logger.debug("stdout:\n%s" % res.stdout)
  Populus.logger.debug("stderr:\n%s" % res.stderr)
  Populus.logger.info("Command exited: %d" % res.exit_status)
end

#upload_dir(to_dir, local: nil) ⇒ Object

Raises:

  • (ArgumentError)


39
40
41
42
43
# File 'lib/populus/remote_runner.rb', line 39

def upload_dir(to_dir, local: nil)
  raise ArgumentError unless local
  @backend.send_directory(local, to_dir)
  Populus.logger.info("Upload Directory Successfully: %s to %s" % [local, to_dir])
end

#upload_file(to_path, local: nil) ⇒ Object

Raises:

  • (ArgumentError)


33
34
35
36
37
# File 'lib/populus/remote_runner.rb', line 33

def upload_file(to_path, local: nil)
  raise ArgumentError unless local
  @backend.send_file(local, to_path)
  Populus.logger.info("Upload Successfully: %s to %s" % [local, to_path])
end