aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2026-10-19 04:02:06 -0400
committerB. Watson <urchlay@slackware.uk>2026-10-19 05:07:00 -0400
commit1dcc0ee0e95e52ab149f45bccf3fba3dc00e8f95 (patch)
treeba467b86716e4fec9796f342cd3c907b7182759a
parent04d230f61b8bcb95558ad78e294bd0b560bb24c9 (diff)
downloadgreypool-1dcc0ee0e95e52ab149f45bccf3fba3dc00e8f95.tar.gz
Use external style.css instead of colors in the config file; add transform directive to config file.
-rwxr-xr-xgreypool101
1 files changed, 65 insertions, 36 deletions
diff --git a/greypool b/greypool
index 8aa0a75..5929e13 100755
--- a/greypool
+++ b/greypool
@@ -31,12 +31,6 @@ $force_download = $html = 0;
$verbose = 1; # 0 = silent, 1 = info messages, 2 = debug
$stamp = strftime("%Y%m%d", localtime);
-# defaults for HTML colors
-$fg_color = 'ffffff';
-$bg_color = '000000';
-$old_color = 'ff0000';
-$new_color = '00ff00';
-
# all the parsed data gets shoved in here.
# keys are visiblename of each project.
# values are another hash, with keys projname (repology's name for
@@ -101,6 +95,7 @@ sub parse_opts {
$color_output = -t STDOUT unless defined $color_output;
$privdir = $ENV{HOME} . "/.greypool" unless defined $privdir;
$config_file = $privdir . "/config";
+ $css_file = $privdir . "/style.css";
$wgetrc = $privdir . "/wgetrc";
}
@@ -292,12 +287,6 @@ repo $repo
# If this is not set, the package names won't by clickable links.
# NOTE: For SlackBuilds.org, the URL *must* end in a trailing slash!
$pfmt
-
-# Optional: Colors for the HTML output. 4 of them, in order:
-# background text new-version old-version
-# These are hex RGB triplets, but *don't* precede them with a #
-# because that would be taken as a comment.
-htmlcolors $bg_color $fg_color $new_color $old_color
EOF
close $f;
@@ -305,12 +294,20 @@ EOF
exit 0;
}
-sub parse_html_colors {
- my @colors = split /\s+/, $_[0];
- if(@colors != 4) {
- fatal "$config_file:$.: htmlcolors needs exactly 4 color values";
+sub parse_transform {
+ my $pkg;
+ my $subst;
+ my $junk;
+ ($pkg, $subst, $junk) = split /\s+/, $_[0];
+
+ fatal "$config_file:$.: trailing junk on transform line" if $junk;
+
+ eval 'my $i = ""; $i =~ ' . $subst . ';';
+ if($@) {
+ fatal "$config_file:$.: invalid transform: $@";
}
- ($bg_color, $fg_color, $new_color, $old_color) = @colors;
+
+ $transforms{$pkg} = $subst;
}
sub parse_mask {
@@ -344,7 +341,7 @@ sub read_config_file {
/pkgurl/ && do { $ok++; $pkgurl = $val; };
/ignore/ && do { $ok++; $ignore{$_}++ for split /\s+/, $val; };
/mask/ && do { $ok++; parse_mask($val); };
- /htmlcolors/ && do { $ok++; parse_html_colors($val) };
+ /transform/ && do { $ok++; parse_transform($val) };
fatal "$config_file line $. malformed (unknown key '$_')" unless $ok;
}
}
@@ -433,7 +430,9 @@ sub parse_file {
# or "foo" and "foo-legacy"
# repology considers these the same project.
if(@$maint[0] eq $email) {
- $report{$name} = $item unless ignored_or_masked($item);
+ next if ignored_or_masked($item);
+ next if transformed_versions_eq($item);
+ $report{$name} = $item;
last;
}
}
@@ -444,6 +443,18 @@ sub parse_file {
return $lastpkg eq $firstpkg ? undef : $lastpkg;
}
+sub transformed_versions_eq {
+ my $i = shift;
+
+ my $t = $transforms{$i->{name}};
+ $t = $transforms{$i->{projname}} unless $t;
+ return unless $t;
+
+ my $v = $i->{oldver};
+ eval '$v =~ ' . $t . ';';
+ return $i->{newver} eq $v;
+}
+
sub ignored_or_masked {
my $i = shift;
@@ -556,13 +567,12 @@ sub generate_report {
}
print_report_header();
- my $count = 0;
- if(!keys %report) {
+ my $count = keys %report;
+ if(!$count) {
print_empty_report();
} else {
- print_table_start();
+ print_table_start($count);
for(sort keys %report) {
- $count++;
print_report_line($_);
}
print_table_end();
@@ -572,6 +582,29 @@ sub generate_report {
####### report printing stuff
+sub create_default_css {
+ open my $f, ">$css_file" or fatal "$css_file: $!";
+ print $f <<EOF;
+body { color: #ffffff; background-color: #000000; }
+a { text-decoration: none;}
+a:link { color: #ffffff; }
+a:visited { color: #ffffff; }
+a:hover { color: #00ff00; }
+.name { color: #ffffff; }
+.oldver { color: #ff0000; }
+.newver { color: #00ff00; }
+.caption { color: #ffff00; }
+EOF
+ close $f;
+}
+
+sub print_css {
+ if(! -e $css_file) {
+ create_default_css();
+ }
+ print read_file($css_file);
+}
+
sub print_report_header {
return if $csv_output;
return if $html_frag;
@@ -581,14 +614,9 @@ sub print_report_header {
<head>
<meta name="Generator" content="$SELF/$VERSION">
<style>
-body { color: #$fg_color; background-color: #$bg_color; }
-a { text-decoration: none;}
-a:link { color: #$fg_color }
-a:visited { color: #$fg_color }
-a:hover { color: #$new_color }
-.name { color: #$fg_color; }
-.oldver { color: #$old_color; }
-.newver { color: #$new_color; }
+EOF
+ print_css();
+ print <<EOF;
</style>
<title>
EOF
@@ -603,9 +631,12 @@ sub print_empty_report {
}
sub print_table_start {
+ my $count = shift;
if($html) {
- print "Repology status report for $email ($repo repository)<p />\n";
- print "<table><tr><th>Package</th><th>Repology Link</th><th>Version</th><th>Newest Version</th></tr>\n";
+ print "<span class=\"caption\">Repology status report for $email ($repo repository)<p />\n";
+ print $count . " package" . ($count == 1 ? "" : "s") . " out of date.<p />" if $html;
+ print "</span>\n";
+ print "<table><tr><th class=\"caption\">Package</th><th class=\"caption\">Repology Link</th><th class=\"caption\">Version</th><th class=\"caption\">Newest Version</th></tr>\n";
} elsif($csv_output) {
print "Package,RepologyName,Version,Newest\n";
} else {
@@ -656,10 +687,8 @@ sub print_table_end {
sub print_report_footer {
return if $csv_output;
my $count = shift;
- if($count) {
- print "<br />" if $html;
+ if($count && !$html) {
print $count . " package" . ($count == 1 ? "" : "s") . " out of date.\n";
- print "<p />" if $html;
}
print "</body></html>" if $html && (!$html_frag);
}