Verified Commit e695c458 authored by Luc Didry's avatar Luc Didry
Browse files

Some rewrite on vrms-web.pl6 according to J.Forget's advices

parent ace3fa1f
......@@ -37,7 +37,7 @@
<thead>
<tr>
<td>Packages</td>
<td>Occurence (for <%= $servers.elems %> servers)</td>
<td>Occurrence (for <%= $servers.elems %> servers)</td>
</tr>
</thead>
<tbody>
......
......@@ -7,6 +7,7 @@ use lib 'P6-Net-IMAP/lib/';
use Template::Mojo;
use File::Directory::Tree;
use Net::IMAP;
use Terminal::Spinners;
grammar Vrms {
token TOP {
......@@ -39,22 +40,22 @@ class Server {
has Str @.contrib;
}
my $user = %*ENV<USER>;
my $pwd = %*ENV<PASSWORD>;
my $server = %*ENV<SERVER>;
my $theme = %*ENV<THEME> || 'default';
my Str $user = %*ENV<USER>;
my Str $pwd = %*ENV<PASSWORD>;
my Str $server = %*ENV<SERVER>;
my Str $theme = %*ENV<THEME> || 'default';
my (@servers, %nonfree, %contrib);
unless ($user && $pwd && $server) {
"Please set USER env variable".say unless $user;
"Please set PASSWORD env variable".say unless $pwd;
"Please set SERVER env variable".say unless $server;
"Exiting".say;
say "Please set USER env variable" unless $user;
say "Please set PASSWORD env variable" unless $pwd;
say "Please set SERVER env variable" unless $server;
say "Exiting";
exit;
}
# Connect to IMAP server
my $i = Net::IMAP.new(:$server);
my Net::IMAP::Simple $i = Net::IMAP.new(:$server);
$i.authenticate($user, $pwd);
$i.select('INBOX');
......@@ -67,74 +68,90 @@ if (%*ENV<DEV> ) {
}
unless @messages.elems {
"No new messages.".say;
say "No new messages.";
exit;
}
"{@messages.elems} messages to process…".say;
print "{@messages.elems} messages to process… ";
# Parse messages
for @messages -> $msg {
my ($name, @nonfree, @contrib);
my Promise $promise .= start: {
for @messages -> $msg {
my ($name, @nonfree, @contrib);
'.'.print;
#print '.';
#$progress.update(++$j);
#$progress.update(++$j);
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));
}
}
@servers.push(Server.new(:$name, :@nonfree, :@contrib));
my Spinner $spinner .= new: type => 'dots';
until $promise.status {
$spinner.next;
}
"\nMessages processed!".say;
"Generating HTML".say;
print "
Messages processed.
Generating HTML… ";
# Choose template
my $tpl = Template::Mojo.new("themes".IO.add($theme).add("index.html.ep").slurp);
# Create the public dir
my $public = "public".IO;
empty-directory $public if $public.e;
$public.mkdir;
# Copy the assets
copy_dir("themes".IO.add($theme).add("assets"), $public.add("assets"));
@servers = @servers.sort: *.name;
%nonfree = %nonfree.sort: *.key;
%contrib = %contrib.sort: *.key;
# Render the datas
my %params = (
servers => @servers,
nonfree => %nonfree,
contrib => %contrib
);
$public.add("index.html").spurt($tpl.render(%params));
"HTML generation successfully ended".say;
$promise = Promise.start: {
my Template::Mojo $tpl .= new("themes".IO.add($theme).add("index.html.ep").slurp);
# Create the public dir
my $public = "public".IO;
empty-directory $public if $public.e;
$public.mkdir;
# Copy the assets
copy_dir("themes".IO.add($theme).add("assets"), $public.add("assets"));
@servers .= sort: *.name;
%nonfree .= sort: *.key;
%contrib .= sort: *.key;
# Render the datas
my %params = (
servers => @servers,
nonfree => %nonfree,
contrib => %contrib
);
$public.add("index.html").spurt($tpl.render(%params));
}
$spinner .= new: type => 'dots';
until $promise.status {
$spinner.next;
}
say "
HTML generation successfully ended.";
# Recursive dir copy function
sub copy_dir(IO::Path $source, IO::Path $target) {
......
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