๐Ÿ“ฆ felixonmars / archlinux-futils

๐Ÿ“„ arch-compare ยท 70 lines
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#!/usr/bin/ruby

require 'pycall/import'
require 'tmpdir'

include PyCall::Import
pyimport :pyalpm

ARCHS = ["i486", "i686", "pentium4", "aarch64", "armv7h", "riscv64", "loong64"]
DBS = ["core", "extra"]

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">
<table class="table is-hoverable">
<thead><tr><th rowspan=2>Arch</th>
<th colspan=3>[core]</th><th colspan=3>[extra]</th>
<tr>
<th>Up-to-date (Ratio%)</th><th>Outdated</th><th>Missing</th>
<th>Up-to-date (Ratio%)</th><th>Outdated</th><th>Missing</th>
</tr></thead><tbody>'

pkgdata = {}
pkgcount = {}

`pacman -Sy`
# x86_64 as baseline
File.open('/var/www/archlinuxriscv/.status/compare.html', 'w') do |f|
    f.puts common_header + "<tr><td>x86_64</td>"
    handle = pyalpm.Handle.new(".", "/var/lib/pacman")
    DBS.each do |repo|
        db_handle = handle.register_syncdb(repo, 0)
        pkgcount[repo] = 0
        db_handle.search("").each do |package|
            pkgdata[package.name] = package.version
            pkgcount[repo] += 1
        end
        f.puts "<td>#{pkgcount[repo]}</td><td>0</td><td>0</td>"
    end
    f.puts "</tr>"

    # compare all other arches
    ARCHS.each do |arch, path|
        f.puts "<tr><td>#{arch}</td>"
        DBS.each do |repo|
            db_handle = handle.register_syncdb(arch + "-" + repo, 0)
            uptodate = 0
            outdated = 0
            db_handle.search("").each do |package|
                if pkgdata.has_key? package.name
                    version = package.version.split("-")
                    version[1] = version[1].split(".")[0]
                    version = version.join("-")
                    if pkgdata[package.name] == version
                        uptodate += 1
                    else
                        outdated += 1
                    end
                end
            end
            percent = (uptodate * 100.0 / pkgcount[repo]).round(2)
            f.puts "<td><font color=green>#{uptodate} (#{percent}%)</font></td>
                    <td><font color=orange>#{outdated}</font></td>
                    <td><font color=red>#{pkgcount[repo] - uptodate - outdated}</font></td>"
        end
        f.puts "</tr>"
    end
    f.puts "</tbody></table></div>"
end