Module: StickyFlag::ExternalCmds

Included in:
ThorApp
Defined in:
lib/stickyflag/external_cmds.rb

Constant Summary collapse

EXTERNAL_CMDS =
{
  'pdftk' => 'read and write PDF tags',
  'mkvextract' => 'read MKV tags',
  'mkvpropedit' => 'write MKV tags'
}

Instance Method Summary collapse

Instance Method Details

#find_external_cmdsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/stickyflag/external_cmds.rb', line 12

def find_external_cmds
  EXTERNAL_CMDS.each do |cmd, desc|
    path = get_config "#{cmd}_path"
  
    # First, make sure that the listed file actually exists and is executable,
    # so that if it isn't, we'll be able to fix it by checking $PATH down
    # below.
    unless path.nil? || path.empty?
      unless File.executable? path
        say_status :error, "Path set for #{cmd} is invalid", :red unless options.quiet?

        path = ''
        set_config "#{cmd}_path", ''
        set_config "have_#{cmd}", false
      else
        # We do have this, make sure it's set that way
        set_config "have_#{cmd}", true
      end
    end
  
    if path.nil? || path.empty?
      # We don't have a path for this command, see if we can find it
      found = which(cmd)
      if found.nil?
        say_status :warning, "Cannot find #{cmd} in path, will not be able to #{desc}", :yellow unless options.quiet?
        set_config "have_#{cmd}", false
        next
      end
    
      # Okay, found it, set the configuration parameter
      set_config "#{cmd}_path", found
      set_config "have_#{cmd}", true
    end
  end

  # Save our results out to the configuration file
  save_config!
end