Show More
Commit Description:
testdata import now looks for *1*.in when finding raw dir...
Commit Description:
testdata import now looks for *1*.in when finding raw dir git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@437 6386c4cd-e34a-4fa8-8920-d93eb39b512e
File last commit:
Show/Diff file:
Action:
lib/testdata_importer.rb | 76 lines | 2.0 KiB | text/x-ruby | RubyLexer |
jittat
added problem import...
r204 require 'tmpdir'
class TestdataImporter
attr :log_msg
def import_from_file(problem_name,
tempfile,
time_limit,
memory_limit)
dirname = TestdataImporter.extract(problem_name, tempfile)
return false if not dirname
@log_msg = GraderScript.call_import_problem(problem_name,
dirname,
time_limit,
memory_limit)
return true
end
protected
def self.long_ext(filename)
i = filename.index('.')
len = filename.length
return filename.slice(i..len)
end
def self.extract(problem_name, tempfile)
testdata_filename = TestdataImporter.save_testdata_file(problem_name,
tempfile)
ext = TestdataImporter.long_ext(tempfile.original_filename)
extract_dir = File.join(GraderScript.raw_dir, problem_name)
begin
Dir.mkdir extract_dir
rescue Errno::EEXIST
end
if ext=='.tar.gz' or ext=='.tgz'
cmd = "tar -zxvf #{testdata_filename} -C #{extract_dir}"
elsif ext=='.tar'
cmd = "tar -xvf #{testdata_filename} -C #{extract_dir}"
elsif ext=='.zip'
jittat
import problem replaced old one, fixed small problems...
r205 cmd = "unzip -o #{testdata_filename} -d #{extract_dir}"
jittat
added problem import...
r204 else
return nil
end
system(cmd)
jittat
testdata import now looks for *1*.in when finding raw dir...
r206 files = Dir["#{extract_dir}/**/*1*.in"]
jittat
added problem import...
r204 return nil if files.length==0
return File.dirname(files[0])
end
def self.save_testdata_file(problem_name, tempfile)
ext = TestdataImporter.long_ext(tempfile.original_filename)
testdata_filename = File.join(Dir.tmpdir,"#{problem_name}#{ext}")
return nil if tempfile==""
if tempfile.instance_of?(Tempfile)
tempfile.close
FileUtils.move(tempfile.path,testdata_filename)
else
File.open(testdata_filename, "wb") do |f|
f.write(tempfile.read)
end
end
return testdata_filename
end
end