From 384f4b0d75753ad8e3a7ee405156433c8930a6ec Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Tue, 17 Jan 2012 14:23:09 +0000 Subject: 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. --- lib/alaveteli_external_command.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'lib/alaveteli_external_command.rb') 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 -- cgit v1.2.3 From 604ec14bc34d4c7b64b7ca36d9fcda03e51daea6 Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Tue, 17 Jan 2012 15:00:50 +0000 Subject: Replace all `which command` calls The trouble with `which command` is twofold: - It spawns a whole shell just to find out the path to a binary, every time; - The results are environment-dependent, since they depend on $PATH. It would be better to specify the search path in the configuration file where everything else is specified rather than in the environment. This commit replaces it with the new mechanism from AlaveteliExternalCommand. --- lib/alaveteli_external_command.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/alaveteli_external_command.rb') diff --git a/lib/alaveteli_external_command.rb b/lib/alaveteli_external_command.rb index e83d8d49a..737b48fa9 100644 --- a/lib/alaveteli_external_command.rb +++ b/lib/alaveteli_external_command.rb @@ -23,14 +23,14 @@ module AlaveteliExternalCommand break end end - raise "Could not find #{program_name} in any of #{utility_search_path.join(', ')}" if !found + 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 - xc.run() + xc.run(opts[:stdin_string]) if xc.status != 0 # Error $stderr.puts("Error from #{program_name} #{args.join(' ')}:") -- cgit v1.2.3 From 41d544631dcb6748ea792f1d8019b5e301056d18 Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Tue, 17 Jan 2012 19:35:48 +0000 Subject: Force the 'C' locale for elinks The behaviour of elinks is locale-dependent. This patch forces LANG=C which makes the behaviour consistent across platforms. --- lib/alaveteli_external_command.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/alaveteli_external_command.rb') diff --git a/lib/alaveteli_external_command.rb b/lib/alaveteli_external_command.rb index 737b48fa9..b1d4f17d1 100644 --- a/lib/alaveteli_external_command.rb +++ b/lib/alaveteli_external_command.rb @@ -30,7 +30,7 @@ module AlaveteliExternalCommand if opts.has_key? :append_to xc.out = opts[:append_to] end - xc.run(opts[:stdin_string]) + xc.run(opts[:stdin_string], opts[:env] || {}) if xc.status != 0 # Error $stderr.puts("Error from #{program_name} #{args.join(' ')}:") -- cgit v1.2.3