-
Notifications
You must be signed in to change notification settings - Fork 5
/
aosc-compare
executable file
·60 lines (52 loc) · 2.38 KB
/
aosc-compare
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
#!/usr/bin/ruby
`cd /var/www/aosc-os-abbs && git pull`
`treevsrepo --tree /var/www/aosc-os-abbs > /tmp/treevsrepo.txt`
common_header = '
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://lib.baomitu.com/bulma/0.9.4/css/bulma.min.css">
<style>tr:hover { background-color: #ddd !important; }</style>
<table class="table is-hoverable">'
arch_data = Hash.new{|h,k| h[k] = []}
File.open('/var/www/aosc/treevsrepo/index.html.tmp', 'w') do |f|
f.puts common_header + '
<thead><tr><th>Package</th><th>Arch</th><th>Tree Version</th>
<th>Repo Version</th></thead><tbody>'
File.open('/tmp/treevsrepo.txt').each do |line|
case line.split("|").map(&:strip)
in [name, arch, tree_version, repo_version]
next if tree_version == "tree_version" or name == "" # skip header or broken lines
`dpkg --compare-versions #{tree_version} gt #{repo_version}`
if $?.success?
tree_color = "green"
repo_color = "red"
else
tree_color = "red"
repo_color = "green"
end
f.puts "<tr><td>#{name}</td><td>#{arch}</td>
<td><font color=#{tree_color}>#{tree_version}</font></td>
<td><font color=#{repo_color}>#{repo_version}</font></td></tr>"
arch_data[arch] << [name, tree_version, tree_color, repo_version, repo_color]
else
next
end
end
f.puts '</tbody></table>'
end
File.rename('/var/www/aosc/treevsrepo/index.html.tmp', '/var/www/aosc/treevsrepo/index.html')
arch_data.each do |arch, data|
puts "Generating #{arch} with #{data.length} entries..."
arch_dir = "/var/www/aosc/treevsrepo/#{arch}"
Dir.mkdir(arch_dir) unless File.exist?(arch_dir)
File.open("#{arch_dir}/index.html.tmp", 'w') do |f|
f.puts common_header + '<thead><tr><th>Package</th><th>Tree Version</th>
<th>Repo Version</th></thead><tbody>'
data.each do |name, tree_version, tree_color, repo_version, repo_color|
f.puts "<tr><td>#{name}</td>
<td><font color=#{tree_color}>#{tree_version}</font></td>
<td><font color=#{repo_color}>#{repo_version}</font></td></tr>"
end
f.puts '</tbody></table>'
end
File.rename("#{arch_dir}/index.html.tmp", "#{arch_dir}/index.html")
end