Class: Yast::Execute

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
I18n
Defined in:
library/system/src/lib/yast2/execute.rb

Overview

A module for executing scripts/programs in a safe way (not prone to shell quoting bugs). It uses Cheetah as the backend, but adds support for chrooting during the installation. It also globally switches the default Cheetah logger to Y2Logger.

Examples:

Methods of this class can be chained.


Yast::Execute.locally!.stdout("ls", "-l")
Yast::Execute.stdout.on_target!("ls", "-l")

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Execute

Constructor


57
58
59
60
61
# File 'library/system/src/lib/yast2/execute.rb', line 57

def initialize(options = {})
  textdomain "base"

  @options = options
end

Instance Method Details

#locally(*args) ⇒ Object

Runs without chroot; a failure becomes a popup. Runs a command described by args, disregarding a chroot(2) specified by the installation (WFM.scr_root). Shows a popup if the command fails and returns nil in such case. It also globally switches the default Cheetah logger to Y2Logger.


96
97
98
# File 'library/system/src/lib/yast2/execute.rb', line 96

def locally(*args)
  chaining_object(yast_popup: true).locally!(*args)
end

#locally!(*args) ⇒ Object

Runs without chroot; a failure becomes an exception. Runs a command described by args, disregarding a chroot(2) specified by the installation (WFM.scr_root). It also globally switches the default Cheetah logger to Y2Logger.

Raises:

  • Cheetah::ExecutionFailed if the command fails


107
108
109
# File 'library/system/src/lib/yast2/execute.rb', line 107

def locally!(*args)
  run_or_chain(args)
end

#on_target(*args) ⇒ Object

Runs with chroot; a failure becomes a popup. Runs a command described by args, in a chroot(2) specified by the installation (WFM.scr_root). Shows a popup if the command fails and returns nil in such case. It also globally switches the default Cheetah logger to Y2Logger.


71
72
73
# File 'library/system/src/lib/yast2/execute.rb', line 71

def on_target(*args)
  chaining_object(yast_popup: true).on_target!(*args)
end

#on_target!(*args) ⇒ Object

Runs with chroot; a failure becomes an exception. Runs a command described by args, in a chroot(2) specified by the installation (WFM.scr_root). It also globally switches the default Cheetah logger to Y2Logger.

Raises:

  • Cheetah::ExecutionFailed if the command fails


82
83
84
85
86
# File 'library/system/src/lib/yast2/execute.rb', line 82

def on_target!(*args)
  root = Yast::WFM.scr_root

  chaining_object(chroot: root).run_or_chain(args)
end

#run_or_chain(args) ⇒ Object, ExecuteClass (protected)

Decides either to run the command or to chain the call in case that no argmuments are given.


129
130
131
# File 'library/system/src/lib/yast2/execute.rb', line 129

def run_or_chain(args)
  args.none? ? self : run(*args)
end

#stdout(*args) ⇒ String

Runs a command described by args and returns its output

It also globally switches the default Cheetah logger to Y2Logger.


118
119
120
# File 'library/system/src/lib/yast2/execute.rb', line 118

def stdout(*args)
  chaining_object(yast_stdout: true, stdout: :capture).run_or_chain(args)
end