-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
183 lines (158 loc) · 5.88 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# encoding: utf-8
# always recording metadata allows us to show the task list from within
# the default task, speeding up "rake" which is used more often than
# the actual rake tasks.
Rake::TaskManager.record_task_metadata = true
require './web/config/environment.rb'
Bundler.setup(:rakefiles)
require 'rake/clean'
CLEAN.include('tmp/**/*.log', 'tmp/**/*.out', 'tmp/**/*.aux',
'tmp/**/*.toc', 'tmp/blame.tex', 'tmp/forms/**/*.tex')
# Capture ctrl+c and stop all currently running jobs in the work queue.
# needs current work_queue gem.
if work_queue.respond_to?("kill")
trap("INT") { work_queue.kill; exit 99 }
else
trap("INT") { exit 99 }
end
RT = ResultTools.instance unless defined?(RT)
SCap = Seee::Config.application_paths unless defined?(SCap)
SCc = Seee::Config.commands unless defined?(SCc)
SCfp = Seee::Config.file_paths unless defined?(SCfp)
# 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
generate_barcode("0"*8, dir + "barcode00000000.pdf")
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
# load external rakefiles
require './rakefiles/export.rb'
require './rakefiles/forms.rb'
require './rakefiles/images.rb'
require './rakefiles/import.rb'
require './rakefiles/mail.rb'
require './rakefiles/omr-test-helper.rb'
require './rakefiles/results.rb'
require './custom_build/build.rb'
# automatically calls rake -T when no task is given
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
namespace :misc do
desc "Generate how tos in all available languagess in tmp/howtos"
task :howtos do
saveto = File.join(GNT_ROOT, "tmp", "howtos")
create_howtos(saveto)
Rake::Task["clean".to_sym].invoke
end
desc "Export data from LSF in various ways helpful for our cause."
task :lsfparse do
# if you change stuff here, also adjust rakefiles/import.rb
require "#{GNT_ROOT}/tools/lsf_parser_base.rb"
puts "Finding IDs…"
search = ["Mathematik und Informatik", "Physik und Astronomie"]
mathe, physik = LSF.find_certain_roots(search)
@dir = "tmp/lsfparse/"
FileUtils.makedirs(@dir)
def run(name, url)
cmd = "cd '#{@dir}' && "
cmd << "#{ruby_interpreter_path} ../../tools/lsf_parser_api.rb #{name} '#{url}' "
cmd << "> #{name}.log"
`#{cmd}`
end
puts "Gathering data…"
work_queue.enqueue_b { run("mathe", mathe[:url]) }
work_queue.enqueue_b { run("physik", physik[:url]) }
work_queue.join
puts
puts "All Done. Have a look in #{@dir}"
end
desc "Generate lovely HTML output for our static website"
task :static_output do
courses = Term.currently_active.map { |t| t.courses }.flatten
puts courses.sort { |x,y| y.updated_at <=> x.updated_at }[0].updated_at
# Sort by faculty first, then by course title
sorted = courses.sort do |x,y|
if x.faculty_id == y.faculty_id
x.title <=> y.title
else
x.faculty_id <=> y.faculty_id
end
end
facs = Faculty.find(:all)
fac_id = -1
def printTD(stuff, join = ", ", extra = "")
s = "<td>" if extra.empty?
s = "<td style=\"#{extra}\">" unless extra.empty?
if stuff.is_a? Array
s << stuff.join(join) unless stuff.empty?
elsif stuff.is_a? String
s << stuff
end
s << "</td>"
s
end
odd = true
sorted.each do |c|
# faculty changed, so print header
if fac_id != c.faculty_id
fname = facs.find { |f| f.id == c.faculty_id }.longname
puts "</table>" unless fac_id == -1
puts "<h2>#{fname}</h2>"
puts "<table class=\"aligntop\" summary=\"Veranstaltungen der Fakultät für #{fname}\">"
puts "<tr class=\"odd\">"
puts "<th></th>"
puts "<th>Veranstaltung</th>"
puts "<th>DozentInnen</th>"
puts "<th>Wann?</th>"
puts "<th>Tutoren</th></tr>"
end
puts "<tr>" if odd
puts "<tr class=\"odd\">" if !odd
tuts = c.tutors.collect{ |t| t.abbr_name }
profs = c.profs.collect{ |t| t.fullname }
hasEval = c.fs_contact_addresses.empty? ? " " : "✓"
puts printTD(hasEval)
puts printTD(c.title.gsub("&", "&"))
puts printTD(profs, "<br/>", "white-space: nowrap")
puts printTD(c.description)
puts printTD(tuts)
puts "</tr>"
fac_id = c.faculty_id
odd = !odd
end
puts "</table>"
end
end
rule '.pdf' => '.tex' do |t|
warn "Rakefile pdf→tex rule is deprecated. Use tex_to_pdf(filename) directly."
tex_to_pdf(t.source)
end