diff options
author | Robin Houston <robin.houston@gmail.com> | 2012-01-17 14:23:09 +0000 |
---|---|---|
committer | Robin Houston <robin.houston@gmail.com> | 2012-01-17 14:23:09 +0000 |
commit | 384f4b0d75753ad8e3a7ee405156433c8930a6ec (patch) | |
tree | ced12b77e5acedc85a94e03b01f986837be25197 /lib/alaveteli_external_command.rb | |
parent | 80e56fde3b4bdb9d2483a7c858960a6d2bd964e0 (diff) |
Paths for external commands
Look for external commands in a config-defined path (defaulting
to /usr/bin:/usr/local/bin), rather than requiring the path to be
hard-coded or the caller to resolve it.
Diffstat (limited to 'lib/alaveteli_external_command.rb')
-rw-r--r-- | lib/alaveteli_external_command.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/alaveteli_external_command.rb b/lib/alaveteli_external_command.rb index b967c89b5..e83d8d49a 100644 --- a/lib/alaveteli_external_command.rb +++ b/lib/alaveteli_external_command.rb @@ -11,7 +11,22 @@ module AlaveteliExternalCommand opts = args.pop end - xc = ExternalCommand.new(program_name, *args) + if program_name =~ %r(^/) + program_path = program_name + else + utility_search_path = MySociety::Config.get("UTILITY_SEARCH_PATH", ["/usr/bin", "/usr/local/bin"]) + found = false + utility_search_path.each do |d| + program_path = File.join(d, program_name) + if File.file? program_path and File.executable? program_path + found = true + break + end + end + raise "Could not find #{program_name} in any of #{utility_search_path.join(', ')}" if !found + end + + xc = ExternalCommand.new(program_path, *args) if opts.has_key? :append_to xc.out = opts[:append_to] end |