Skip to content
This repository has been archived by the owner on Oct 23, 2021. It is now read-only.

Commit

Permalink
Add a script to check that all binaries exist on the system, for all …
Browse files Browse the repository at this point in the history
…languages we handle.
  • Loading branch information
relrod committed Nov 2, 2012
1 parent 3c2567f commit 6572586
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
32 changes: 32 additions & 0 deletions check_for_all_binaries.rb
@@ -0,0 +1,32 @@
#!/usr/bin/env ruby
# Goes through all languages and makes sure that all needed binaries exist to
# evaluate code in it.

$LOAD_PATH.unshift File.dirname(__FILE__)
require 'eval/eval'
require 'eval/config'
require 'eval/languages'

missing_binaries = []

Language.languages.each do |language, values|
if values[:special]
missing_binaries << "[special] #{language}"
next
end

sandbox = Sandbox.new(Language.by_name(language))
if sandbox.binaries_all_exist?
print '.'
sleep 0.005
else
print '!'
sleep 0.05
missing_binaries << language
end
end

puts

puts "Languages missing binaries:"
puts missing_binaries.join("\n")
26 changes: 13 additions & 13 deletions eval/eval.rb
Expand Up @@ -180,6 +180,19 @@ def pastebin(credentials = {})
"Output truncated: #{paste['url']} (#{@result.lines.count} lines of total output)"
end

# Public: Checks to make sure all needed binaries to perform an evaluation
# (@binaries_must_exist) exist and are located in a directory that
# is in $PATH.
#
# Returns false if a needed binary doesn't exist, and true if they all do.
def binaries_all_exist?
@binaries_must_exist.each do |binary|
next if File.exists? binary
return false unless ENV['PATH'].split(':').any? { |path| File.exists? File.join(path, '/', binary) }
end
true
end

private

# Internal: Copies evaluated code to someplace safe, for audit purposes.
Expand All @@ -193,19 +206,6 @@ def copy_audit_script
FileUtils.cp("#{@home}/#{@script_filename}", "#{@path}/evaluated/#{@time.year}-#{@time.month}-#{@time.day}_#{@time.hour}-#{@time.min}-#{@time.sec}-#{@owner}-#{@time.to_f}.#{@extension}")
end

# Internal: Checks to make sure all needed binaries to perform an evaluation
# (@binaries_must_exist) exist and are located in a directory that
# is in $PATH.
#
# Returns false if a needed binary doesn't exist, and true if they all do.
def binaries_all_exist?
@binaries_must_exist.each do |binary|
next if File.exists? binary
return false unless ENV['PATH'].split(':').any? { |path| File.exists? File.join(path, '/', binary) }
end
true
end

# Internal: Takes the code that we are about to evaluate, and actually puts it
# in the file, so that we can...evaluate it.
#
Expand Down

0 comments on commit 6572586

Please sign in to comment.