Class: Scissor::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/scissor-video/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Command

Returns a new instance of Command.



9
10
11
12
13
14
# File 'lib/scissor-video/command.rb', line 9

def initialize(args)
  @command = args[:command]
  @work_dir = args[:work_dir] || Dir.tmpdir + "/scissor-video-work-" + $$.to_s
  @work_dir = Pathname.new(@work_dir)
  @work_dir.mkpath
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



7
8
9
# File 'lib/scissor-video/command.rb', line 7

def command
  @command
end

#work_dirObject

Returns the value of attribute work_dir.



7
8
9
# File 'lib/scissor-video/command.rb', line 7

def work_dir
  @work_dir
end

Instance Method Details

#_run(option, force = false) ⇒ Object



36
37
38
39
# File 'lib/scissor-video/command.rb', line 36

def _run(option, force = false)
  cmd = [@command, option.keys.map {|k| "#{k} #{option[k]}"}].flatten.join(' ')
  run_command(cmd, force)
end

#run(option_str, force = false) ⇒ Object

パラメタ指定順番意識するものもあるので



42
43
44
# File 'lib/scissor-video/command.rb', line 42

def run(option_str, force = false)
  run_command([@command, option_str].join(' '), force)
end

#run_command(cmd, force = false) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/scissor-video/command.rb', line 16

def run_command(cmd, force = false)
  Scissor.logger.debug("run_command: #{cmd}")

  result = ''
  status = Open4.popen4(cmd) do |pid, stdin, stdout, stderr|
    err = stderr.read
    Scissor.logger.debug(err)
    result = stdout.read
    if force && err
      result = err
    end
  end

  if status.exitstatus != 0 && !force
    raise CommandFailed.new(cmd)
  end

  return result
end

#which(command) ⇒ Object



46
47
48
# File 'lib/scissor-video/command.rb', line 46

def which(command)
  run_command("which #{command}").chomp
end