-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
61 lines (57 loc) · 2.27 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'json_api_client'
require 'yaml'
require "byebug"
require 'active_support'
Rake.add_rakelib 'config'
I18n.load_path += Dir.glob(File.join(File.dirname(__FILE__), 'config/locales/*.yml'))
Rake.add_rakelib 'lib'
Rake.add_rakelib 'lib/resources'
Rake.add_rakelib 'rakefiles'
require 'rake/clean'
CLEAN.include('tmp/**/*.log', 'tmp/**/*.out', 'tmp/**/*.aux',
'tmp/**/*.toc', 'tmp/blame.tex', 'tmp/forms/**/*.tex')
#require './app/resources/base.rb'
#require './app/resources/form.rb'
# automatically calls rake -T when no task is given
# Creates a sample sheet in tmp/sample_sheets for the given form (object)
# and language name. Returns the full filepath, but without the file
# extension. Does not re-create existing files.
def make_sample_sheet(form, lang)
# this is hardcoded throughout the project
dir = "tmp/sample_sheets/"
FileUtils.makedirs(dir)
filename = "#{dir}sample_#{form.id}#{lang.to_s.empty? ? "" : "_#{lang}"}"
form_misses_files = !File.exist?(filename+'.pdf') || !File.exist?(filename+'.yaml')
# see if the form is newer than any of the files
form_needs_regen = form_misses_files \
|| form.updated_at > File.mtime(filename+'.pdf') \
|| form.updated_at > File.mtime(filename+'.yaml')
# PDFs are required for result generation and the posouts for OMR
# parsing. Only skip if both files are present and newer than the
# form itself.
if !form_needs_regen && File.exists?(filename+'.pdf') && File.exists?(filename+'.yaml')
return filename
end
File.open(filename + ".tex", "w") do |h|
h << form.abstract_form.to_tex(lang, form.db_table)
end
puts "Wrote #{filename}.tex"
tex_to_pdf("#{filename}.tex", true)
lines_posout = %x{wc -l #{filename}.posout}.split.first.to_i
`./pest/latexfix.rb "#{filename}.posout" && rm "#{filename}.posout"`
lines_yaml = %x{wc -l #{filename}.yaml}.split.first.to_i
raise "Converting error: # lines of posout and yaml differ." if lines_yaml != lines_posout
filename
end
task :default do
puts "Choose your destiny:"
Rake::application.options.show_tasks = :tasks
Rake::application.options.show_task_pattern = //
Rake::application.display_tasks_and_comments
end
desc "Tests the connection to the server"
task :connect do
puts ENV["PEST_SERVER"]
p Form.all
byebug
end