-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_html.rb
116 lines (101 loc) · 3.16 KB
/
make_html.rb
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
# Generate an HTML website from a Coq bench database.
require 'erb'
require 'fileutils'
require_relative 'database'
include(ERB::Util)
class Numeric
# Pretty-print a duration in seconds.
def duration
secs = self.to_int
# Round the duration in minutes, to reduce the size of the diff
secs = ((secs / 60.0).ceil * 60).round
mins = secs / 60
hours = mins / 60
days = hours / 24
if days > 0
"#{days} d and #{hours % 24} h"
elsif hours > 0
"#{hours} h #{mins % 60} m"
elsif mins > 0
"#{mins} m #{secs % 60} s"
elsif secs >= 0
"#{secs} s"
end
end
# Pretty-print a file size in kilo-bytes.
def file_size
size = self.to_int
if size == 0 then
"0 K"
elsif size < 1024 then
"1 K"
elsif size < 1024 * 1024 then
"#{(size / 1024.0).round} K"
else
"#{(size / (1024.0 * 1024.0)).round} M"
end
end
end
unless ARGV.size == 2 then
puts "Usage: ruby make_html.rb database_path html_path"
exit(1)
end
database_path, install_path = ARGV[0], ARGV[1]
FileUtils.mkdir_p(install_path)
# Copy the CSS and JavaScript.
FileUtils.cp([
"bootstrap-custom.css",
"bootstrap.min.css",
"bootstrap.min.js",
"favicon.png",
"moment.min.js"
], install_path)
# Prepare the databases.
databases = {
clean: Database.new("#{database_path}/clean"),
tree: Database.new("#{database_path}/tree")}
# Number of generated HTML files.
$nb_generated = 0
def write_in_file(file_name, renderer)
content = renderer.result().gsub(/\n\s*\n/, "\n")
unless File.exists?(file_name) && File.read(file_name, encoding: "binary") == content then
File.open(file_name, "w") do |file|
file << content
end
puts file_name
$nb_generated += 1
end
end
# Generate the index.
renderer = ERB.new(File.read("index.html.erb", encoding: "binary"))
write_in_file("#{install_path}/index.html", renderer)
for mode in [:clean, :tree] do
database = databases[mode]
# Generate the tables of results.
renderer = ERB.new(File.read("table.html.erb", encoding: "binary"))
for architecture in database.architectures do
for repository in Database.repositories do
folder_name = "#{install_path}/#{mode}/#{architecture}/#{repository}"
FileUtils.mkdir_p(folder_name)
write_in_file("#{folder_name}/index.html", renderer)
end
end
# Generate the logs for each package.
for architecture in database.architectures do
for repository in Database.repositories do
for coq_version in database.coq_versions(architecture, repository) do
time = database.in_memory[architecture][repository][coq_version][:time]
results = database.in_memory[architecture][repository][coq_version][:results]
for name, results in results do
for version, result in results do
folder_name = "#{install_path}/#{mode}/#{architecture}/#{repository}/#{coq_version}/#{name}"
FileUtils.mkdir_p(folder_name)
renderer = ERB.new(File.read("logs.html.erb", encoding: "binary"))
write_in_file("#{folder_name}/#{version}.html", renderer)
end
end
end
end
end
end
puts "#{$nb_generated} generated or updated HTML files."