Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Compile now writes response to output directory for future reference

  • Loading branch information...
commit 09d7e5cdecc16a61e19666a24e332decc0f8353a 1 parent 87e52a5
@jpallen jpallen authored
Showing with 41 additions and 13 deletions.
  1. +1 −1  LICENSE
  2. +28 −12 app/models/compile.rb
  3. +12 −0 spec/models/compile_spec.rb
View
2  LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2010 James Allen
+Copyright (c) 2010 James Allen <james@scribtex.com>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
View
40 app/models/compile.rb
@@ -41,6 +41,7 @@ def compile
@error_message = e.message
ensure
move_log_files_to_public_dir
+ write_response_to_public_dir
remove_compile_directory
end
@@ -139,23 +140,23 @@ def convert_to_output_format
def move_compiled_files_to_public_dir
FileUtils.mkdir_p(File.join(SERVER_PUBLIC_DIR, 'output', self.unique_id))
- for output_file in find_output_files_of_type(self.output_format)
- output_path = File.join(compile_directory, output_file)
- rel_dest_path = File.join('output', self.unique_id, output_file)
- dest_path = File.join(SERVER_PUBLIC_DIR, rel_dest_path)
- FileUtils.mv(output_path, dest_path)
- @output_files << OutputFile.new(:path => rel_dest_path)
+ for existing_file in find_output_files_of_type(self.output_format)
+ existing_path = File.join(compile_directory, existing_file)
+ relative_output_path = File.join(relative_output_dir, existing_file)
+ output_path = File.join(SERVER_PUBLIC_DIR, relative_output_path)
+ FileUtils.mv(existing_path, output_path)
+ @output_files << OutputFile.new(:path => relative_output_path)
end
end
def move_log_files_to_public_dir
- FileUtils.mkdir_p(File.join(SERVER_PUBLIC_DIR, 'output', self.unique_id))
+ FileUtils.mkdir_p(output_dir)
- output_log_path = File.join(compile_directory, 'output.log')
- rel_dest_log_path = File.join('output', self.unique_id, 'output.log')
- if File.exist?(output_log_path)
- FileUtils.mv(output_log_path, File.join(SERVER_PUBLIC_DIR, rel_dest_log_path))
- @log_files << OutputFile.new(:path => rel_dest_log_path)
+ existing_log_path = File.join(compile_directory, 'output.log')
+ relative_output_log_path = File.join(relative_output_dir, 'output.log')
+ if File.exist?(existing_log_path)
+ FileUtils.mv(existing_log_path, File.join(SERVER_PUBLIC_DIR, relative_output_log_path))
+ @log_files << OutputFile.new(:path => relative_output_log_path)
end
end
@@ -163,6 +164,13 @@ def remove_compile_directory
FileUtils.rm_rf(self.compile_directory)
end
+ def write_response_to_public_dir
+ FileUtils.mkdir_p(output_dir)
+ File.open(File.join(output_dir, 'response.xml'), 'w') do |f|
+ f.write(self.to_xml)
+ end
+ end
+
def tex_env_variables
@tex_env_variables ||= "TEXMFOUTPUT=\"#{compile_directory_rel_to_chroot}\" " +
"TEXINPUTS=\"$TEXINPUTS:#{compile_directory_rel_to_chroot}\" " +
@@ -170,6 +178,14 @@ def tex_env_variables
"BSTINPUTS=\"#{compile_directory_rel_to_chroot}:$BSTINPUTS\" "
end
+ def output_dir
+ File.join(SERVER_PUBLIC_DIR, relative_output_dir)
+ end
+
+ def relative_output_dir
+ File.join('output', self.unique_id)
+ end
+
def compile_directory_rel_to_chroot
@compile_directory_rel_to_chroot ||= File.join(LATEX_COMPILE_DIR_RELATIVE_TO_CHROOT, self.unique_id)
end
View
12 spec/models/compile_spec.rb
@@ -96,6 +96,12 @@
it 'should set the compile status to success' do
@compile.status.should eql :success
end
+
+ it 'should write the xml response to disk for future reference' do
+ response_path = File.join(SERVER_PUBLIC_DIR, 'output', @compile.unique_id, 'response.xml')
+ File.exist?(response_path).should be_true
+ File.read(response_path).should eql @compile.to_xml
+ end
end
it 'should validate the compile' do
@@ -172,6 +178,12 @@
@compile.log_files.should include(OutputFile.new(:path => rel_log_path))
File.exist?(File.join(SERVER_PUBLIC_DIR, rel_log_path)).should be_true
end
+
+ it 'should write the xml response to disk for future reference' do
+ response_path = File.join(SERVER_PUBLIC_DIR, 'output', @compile.unique_id, 'response.xml')
+ File.exist?(response_path).should be_true
+ File.read(response_path).should eql @compile.to_xml
+ end
end
describe "timedout compile" do
Please sign in to comment.
Something went wrong with that request. Please try again.