Verified Commit 32444f0f authored by Luc Didry's avatar Luc Didry
Browse files

Remove promises

parent af8d03ac
Pipeline #448001 passed with stage
in 1 minute and 45 seconds
......@@ -78,160 +78,150 @@ unless @messages.elems {
print "{@messages.elems} messages to process… ";
# Parse messages
my Promise $promise .= start: {
for @messages -> $msg {
my ($name, @nonfree, @contrib);
my Spinner $spinner .= new: type => 'dots';
for @messages -> $msg {
$spinner.next;
my ($name, @nonfree, @contrib);
my $body = $msg.mime.body-str;
my $body = $msg.mime.body-str;
# Get datas
if $body ~~ /.* 'No non-free or contrib packages installed on ' (\N+) '! rms would be proud.' .*/ {
$name = $0.Str;
} else {
my $m = Vrms.parse($body);
# Get datas
if $body ~~ /.* 'No non-free or contrib packages installed on ' (\N+) '! rms would be proud.' .*/ {
$name = $0.Str;
} else {
my $m = Vrms.parse($body);
for $m<nfsection> -> $q {
$name = $q<nonfree><server>.Str;
for $m<nfsection> -> $q {
$name = $q<nonfree><server>.Str;
for $q<packages> -> $p {
@nonfree.push($p<package>.Str);
%nonfree{$p<package>.Str} += 1;
}
for $q<packages> -> $p {
@nonfree.push($p<package>.Str);
%nonfree{$p<package>.Str} += 1;
}
for $m<csection> -> $q {
$name ||= $q<contrib><server>.Str if $q<contrib><server>;
}
for $m<csection> -> $q {
$name ||= $q<contrib><server>.Str if $q<contrib><server>;
for $q<packages> -> $p {
@contrib.push($p<package>.Str);
%contrib{$p<package>.Str} += 1;
}
for $q<packages> -> $p {
@contrib.push($p<package>.Str);
%contrib{$p<package>.Str} += 1;
}
}
@servers.push(Server.new(:$name, :@nonfree, :@contrib));
}
}
my Spinner $spinner .= new: type => 'dots';
until $promise.status {
$spinner.next;
@servers.push(Server.new(:$name, :@nonfree, :@contrib));
}
$promise.then({
die "Messages processing failed" if $promise.status.match("Broken");
});
print "
Messages processed.
Generating HTML and JSON … ";
Generating HTML and JSON for {@servers.elems} servers … ";
# Choose template
$promise = Promise.start: {
@servers .= sort: *.name;
%nonfree .= sort: *.key;
%contrib .= sort: *.key;
my %temp = ( free => 0, nonfree => 0, contrib => 0 );
my @servers_tbody;
eager @servers.map: {
@servers_tbody.push([
(%*ENV<HIDENAMES>) ?? '[Filtered]' !! $_.name,
($_.nonfree.elems) ?? "({$_.nonfree.elems}) $_.nonfree.join(' ')" !! "∅",
($_.contrib.elems) ?? "({$_.contrib.elems}) $_.contrib.join(' ')" !! "∅"
]);
if ($_.nonfree.elems + $_.contrib.elems == 0) {
%temp<free>++;
} elsif ($_.nonfree.elems !== 0) {
%temp<nonfree>++;
} else {
%temp<contrib>++;
}
};
my %servers_freedom = (
label => "Servers freedom",
datasets => [{
data => [ %temp<free>, %temp<nonfree>, %temp<contrib> ]
}],
"labels" => [ "with only free packages", "with nonfree packages (and maybe contrib)", "with contrib packages (and no nonfree)" ]
);
my %nonfree_use = (
label => "Non-free packages use",
datasets => [{
data => []
}],
"labels" => []
);
my @nonfree_tbody;
for %nonfree.kv -> $k, $v {
@nonfree_tbody.push([$k, $v]);
%nonfree_use<datasets>[0]<data>.push($v);
%nonfree_use<labels>.push($k);
}
$spinner .= new: type => 'dots';
@servers .= sort: *.name;
%nonfree .= sort: *.key;
%contrib .= sort: *.key;
my %contrib_use = (
label => "Contrib packages use",
datasets => [{
data => []
}],
"labels" => []
);
my @contrib_tbody;
for %contrib.kv -> $k, $v {
@contrib_tbody.push([$k, $v]);
%contrib_use<datasets>[0]<data>.push($v);
%contrib_use<labels>.push($k);
my %temp = ( free => 0, nonfree => 0, contrib => 0 );
my @servers_tbody;
eager @servers.map: {
$spinner.next;
@servers_tbody.push([
(%*ENV<HIDENAMES>) ?? '[Filtered]' !! $_.name,
($_.nonfree.elems) ?? "({$_.nonfree.elems}) $_.nonfree.join(' ')" !! "∅",
($_.contrib.elems) ?? "({$_.contrib.elems}) $_.contrib.join(' ')" !! "∅"
]);
if ($_.nonfree.elems + $_.contrib.elems == 0) {
%temp<free>++;
} elsif ($_.nonfree.elems !== 0) {
%temp<nonfree>++;
} else {
%temp<contrib>++;
}
# Render the datas
my %params = (
servers => @servers_tbody,
nonfree => %nonfree,
contrib => %contrib
);
my Template::Mojo $tpl .= new($theme_dir.add("index.html.ep").slurp);
$theme_dir.add("front/public/index.html").spurt($tpl.render(%params));
$theme_dir.add("front/public/data.json").spurt(to-json({
servers => %servers_freedom,
nonfree => %nonfree_use,
contrib => %contrib_use
}));
$theme_dir.add("front/public/tabs.json").spurt(to-json([
{
name => "Charts",
table => False,
selected => True
},
{
name => "By server",
thead => ["Server", "Non-free packages", "Contrib packages"],
tbody => @servers_tbody
},
{
name => "Non-free packages",
thead => ["Packages", "Occurrence (for {@servers.elems} servers)"],
tbody => @nonfree_tbody
},
{
name => "Contrib packages",
thead => ["Packages", "Occurrence (for {@servers.elems} servers)"],
tbody => @contrib_tbody
}
]));
};
my %servers_freedom = (
label => "Servers freedom",
datasets => [{
data => [ %temp<free>, %temp<nonfree>, %temp<contrib> ]
}],
"labels" => [ "with only free packages", "with nonfree packages (and maybe contrib)", "with contrib packages (and no nonfree)" ]
);
my %nonfree_use = (
label => "Non-free packages use",
datasets => [{
data => []
}],
"labels" => []
);
my @nonfree_tbody;
for %nonfree.kv -> $k, $v {
@nonfree_tbody.push([$k, $v]);
%nonfree_use<datasets>[0]<data>.push($v);
%nonfree_use<labels>.push($k);
}
$spinner .= new: type => 'dots';
until $promise.status {
$spinner.next;
my %contrib_use = (
label => "Contrib packages use",
datasets => [{
data => []
}],
"labels" => []
);
my @contrib_tbody;
for %contrib.kv -> $k, $v {
@contrib_tbody.push([$k, $v]);
%contrib_use<datasets>[0]<data>.push($v);
%contrib_use<labels>.push($k);
}
# Render the datas
my %params = (
servers => @servers_tbody,
nonfree => %nonfree,
contrib => %contrib
);
my Template::Mojo $tpl .= new($theme_dir.add("index.html.ep").slurp);
$theme_dir.add("front/public/index.html").spurt($tpl.render(%params));
$theme_dir.add("front/public/data.json").spurt(to-json({
servers => %servers_freedom,
nonfree => %nonfree_use,
contrib => %contrib_use
}));
$theme_dir.add("front/public/tabs.json").spurt(to-json([
{
name => "Charts",
table => False,
selected => True
},
{
name => "By server",
thead => ["Server", "Non-free packages", "Contrib packages"],
tbody => @servers_tbody
},
{
name => "Non-free packages",
thead => ["Packages", "Occurrence (for {@servers.elems} servers)"],
tbody => @nonfree_tbody
},
{
name => "Contrib packages",
thead => ["Packages", "Occurrence (for {@servers.elems} servers)"],
tbody => @contrib_tbody
}
]));
say "
HTML and JSON generation successfully ended.
Building frontend…";
&*chdir($theme_dir.add("front"));
run <yarn build>;
indir($theme_dir.add("front"), {
my $proc = run <yarn build>, :out, :err;
$proc.out.slurp(:close).say;
$proc.err.slurp(:close).say;
say "Frontend buildt."
say "Frontend built."
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment