hets.rb revision 435547b6b5df0f76cd04b09532341b07d0defeb1
require 'date'
VERSION_RE = %r{v\d+\.\d+,\s*(\d+)$}
# Set hets environment variables
end
end
"v#{minimum_version}, #{minimum_revision}"
end
yaml['version_minimum_version']
end
yaml['version_minimum_revision']
end
# Checks Hets installation compatibility by its version date
#
# * *Args* :
# * - +minimum_revision+ -> Minimum working hets version revision
# * *Returns* :
# * - true if hets version minimum revision smaller than or equal to actual hets version revision
# * - false otherwise
# Read Hets version minimum revision
raise ConfigDateFormatError, 'Could not read hets version minimum revision in YAML' unless minimum_revision
# Read Hets version date
# revision starts with r-char and ends with revision number.
version_revision = if version =~ VERSION_RE
$1 # the version number (unix timestamp)
else
raise InvalidHetsVersionFormatError, "format is not valid: <#{version}>"
end
# Return true if minimum date is prior or equal to version date
return minimum_revision.to_i <= version_revision.to_i
end
end
end
raise VersionOutdatedError, 'The installed version of Hets is too old'
end
message = <<-MSG
HETS PROBLEM:
The Hets Version identifier was not recognized
(#{e.message}),
we expected it to be matchable by this regular expression:
#{VERSION_RE}.
MSG
Rails.logger.warn message
STDERR.puts message
end
end
def self.minimal_version_string
Hets::Config.new.minimal_version_string
end
# Runs hets with input_file and returns XML output file path.
def self.parse(input_file, url_catalog = [], output_path = nil, structure_only: false)
# Arguments to run the subprocess
args = [config.path, *%w( -o pp.xml -o xml --full-signatures -a none -v2 --full-theories )]
if output_path
FileUtils.mkdir_p output_path
args += ['-O', output_path]
end
args += ['-s'] if structure_only
args += ['-C', url_catalog.join(',')] unless url_catalog.empty?
# Configure stack size
args += ['+RTS', "-K#{config.stack_size}", '-RTS']
# add the path to the input file as last argument
args << input_file
# Executes command with low priority
Rails.logger.debug "Running hets with: #{args.inspect}"
output = Subprocess.run :nice, *args, config.env
if output.starts_with? '*** Error'
# some error occured
raise ExecutionError, output
elsif (files = written_files(output.lines)).any?
# successful execution
files
else
# we can not handle this response
raise ExecutionError, "Unexpected output:\n#{output}"
end
rescue Subprocess::Error => e
output = e.output
# Exclude usage message if exit status equals 2
if e.status == 2 and output.include? 'Usage:'
raise ExecutionError, output.split("Usage:").first
else
raise ExecutionError, e.message
end
end
def self.config
@@config ||= Config.new
end
def self.written_files(lines)
lines.reduce([]) do |lines, line|
file = written_file(line)
lines << file if file
lines
end
end
def self.written_file(line)
match = line.match(/Writing file: (?<file>.+)/)
match[:file] if match
end
end