Skip to content
Permalink
Browse files

extend_execute

  • Loading branch information...
jreidinger committed May 26, 2017
1 parent d0b9381 commit 2324d9959960b4d2dc40c2eca98a64f881a5d2ac
Showing with 44 additions and 9 deletions.
  1. +19 −9 library/system/src/lib/yast2/execute.rb
  2. +25 −0 library/system/test/execute_test.rb
@@ -33,10 +33,16 @@ class Execute
extend Yast::I18n
textdomain "base"

# Runs arguments with respect of changed root in installation.
# Runs arguments with respect of changed root in installation. Shows popup when failed and returns nil in such case.
# @see http://www.rubydoc.info/github/openSUSE/cheetah/Cheetah.run parameter docs
# @raise Cheetah::ExecutionFailed
def self.on_target(*args)
popup_error { on_target!(*args) }
end

# Runs arguments with respect of changed root in installation.
# @see http://www.rubydoc.info/github/openSUSE/cheetah/Cheetah.run parameter docs
# @raise Cheetah::ExecutionFailed when command failed, see cheetah documentation
def self.on_target!(*args)
root = Yast::WFM.scr_root

if args.last.is_a? ::Hash
@@ -45,17 +51,23 @@ def self.on_target(*args)
args.push(chroot: root)
end

popup_error { Cheetah.run(*args) }
Cheetah.run(*args)
end

# Runs arguments without changed root.
# Runs arguments without changed root. Shows popup when failed and returns nil in such case.
# @see http://www.rubydoc.info/github/openSUSE/cheetah/Cheetah.run parameter docs
# @raise Cheetah::ExecutionFailed
def self.locally(*args)
popup_error { Cheetah.run(*args) }
popup_error { locally!(*args) }
end

def self.popup_error(&block)
# Runs arguments without changed root.
# @see http://www.rubydoc.info/github/openSUSE/cheetah/Cheetah.run parameter docs
# @raise Cheetah::ExecutionFailed when command failed, see cheetah documentation
def self.locally!(*args)
Cheetah.run(*args)
end

private_class_method def self.popup_error(&block)
block.call
rescue Cheetah::ExecutionFailed => e
Yast.import "Report"
@@ -72,7 +84,5 @@ def self.popup_error(&block)
}
)
end

private_class_method :popup_error
end
end
@@ -27,6 +27,18 @@
end
end

describe ".locally!" do
it "passes arguments directly to cheetah" do
expect(Cheetah).to receive(:run).with("ls", "-a")

Yast::Execute.locally("ls", "-a")
end

it "raises Cheetah::ExecutionFailed if command execution failed" do
expect{Yast::Execute.locally!("false")}.to raise_error(Cheetah::ExecutionFailed)
end
end

describe ".on_target" do
it "adds to passed arguments chroot option if scr chrooted" do
allow(Yast::WFM).to receive(:scr_root).and_return("/mnt")
@@ -44,4 +56,17 @@
expect(Yast::Execute.on_target("false")).to eq nil
end
end

describe ".on_target!" do
it "adds to passed arguments chroot option if scr chrooted" do
allow(Yast::WFM).to receive(:scr_root).and_return("/mnt")
expect(Cheetah).to receive(:run).with("ls", "-a", chroot: "/mnt")

Yast::Execute.on_target("ls", "-a")
end

it "raises Cheetah::ExecutionFailed if command execution failed" do
expect{Yast::Execute.on_target!("false")}.to raise_error(Cheetah::ExecutionFailed)
end
end
end

0 comments on commit 2324d99

Please sign in to comment.
You can’t perform that action at this time.