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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
|
# Copyright (C) 2020-2021 Felix Lechner
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, you can find it on the World Wide
# Web at https://www.gnu.org/copyleft/gpl.html, or write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA.
package Lintian::Output::HTML;
use v5.20;
use warnings;
use utf8;
use Const::Fast;
use Path::Tiny;
use Text::Markdown::Discount qw(markdown);
use Text::Xslate qw(mark_raw);
use Time::Duration;
use Time::Moment;
use Unicode::UTF8 qw(encode_utf8);
use Lintian::Output::Markdown qw(markdown_citation);
const my $EMPTY => q{};
const my $SPACE => q{ };
const my $NEWLINE => qq{\n};
const my $PARAGRAPH_BREAK => $NEWLINE x 2;
const my %CODE_PRIORITY => (
'E' => 30,
'W' => 40,
'I' => 50,
'P' => 60,
'X' => 70,
'C' => 80,
'O' => 90,
'M' => 100,
);
use Moo;
use namespace::clean;
with 'Lintian::Output::Grammar';
=head1 NAME
Lintian::Output::HTML - standalone HTML hint output
=head1 SYNOPSIS
use Lintian::Output::HTML;
=head1 DESCRIPTION
Provides standalone HTML hint output.
=head1 INSTANCE METHODS
=over 4
=item issue_hints
Print all hints passed in array. A separate arguments with processables
is necessary to report in case no hints were found.
=cut
sub issue_hints {
my ($self, $profile, $groups, $option) = @_;
$groups //= [];
my %output;
my $lintian_version = $ENV{LINTIAN_VERSION};
$output{'lintian-version'} = $lintian_version;
my @allgroups_output;
$output{groups} = \@allgroups_output;
for my $group (sort { $a->name cmp $b->name } @{$groups}) {
my %group_output;
$group_output{'group-id'} = $group->name;
$group_output{name} = $group->source_name;
$group_output{version} = $group->source_version;
my $start = Time::Moment->from_string($group->processing_start);
my $end = Time::Moment->from_string($group->processing_end);
$group_output{start} = $start->strftime('%c');
$group_output{end} = $end->strftime('%c');
$group_output{duration} = duration($start->delta_seconds($end));
my @processables = $group->get_processables;
my $any_processable = shift @processables;
$group_output{'maintainer'}
= $any_processable->fields->value('Maintainer');
push(@allgroups_output, \%group_output);
my @allfiles_output;
$group_output{'input-files'} = \@allfiles_output;
for my $processable (sort {$a->path cmp $b->path}
$group->get_processables) {
my %file_output;
$file_output{filename} = path($processable->path)->basename;
$file_output{hints}
= $self->hintlist($profile, $option, $processable->hints);
push(@allfiles_output, \%file_output);
}
}
my @tag_infos;
$output{tag_infos} = \@tag_infos;
for my $tag_name (sort { $a cmp $b } keys %{$self->issuedtags}) {
my $tag = %{$self->issuedtags}{$tag_name};
my %data;
$data{tag} = $tag;
$data{description}
= markdown($self->markdown_description($profile->data, $tag));
push(@tag_infos, \%data);
}
my $style_sheet = $profile->data->style_sheet->css;
my $templatedir = "$ENV{LINTIAN_BASE}/templates";
my $tx = Text::Xslate->new(path => [$templatedir]);
my $page = $tx->render(
'standalone-html.tx',
{
title => 'Lintian Tags',
style_sheet => mark_raw($style_sheet),
output => \%output,
}
);
print encode_utf8($page);
return;
}
=item C<hintlist>
=cut
sub hintlist {
my ($self, $profile, $option, $arrayref) = @_;
my %sorter;
for my $hint (@{$arrayref // []}) {
my $tag = $profile->get_tag($hint->tag_name);
my $override_status = 0;
$override_status = 1
if defined $hint->override || @{$hint->masks};
my $ranking_code = $tag->code;
$ranking_code = 'X'
if $tag->experimental;
$ranking_code = 'O'
if defined $hint->override;
$ranking_code = 'M'
if @{$hint->masks};
my $code_priority = $CODE_PRIORITY{$ranking_code};
if ($option->{info}) {
$self->issue_tag($tag);
}
push(
@{
$sorter{$override_status}{$code_priority}{$tag->name}
{$hint->context}
},
$hint
);
}
my @sorted;
for my $override_status (sort keys %sorter) {
my %by_code_priority = %{$sorter{$override_status}};
for my $code_priority (sort { $a <=> $b } keys %by_code_priority) {
my %by_tag_name = %{$by_code_priority{$code_priority}};
for my $tag_name (sort keys %by_tag_name) {
my %by_context = %{$by_tag_name{$tag_name}};
for my $context (sort keys %by_context) {
my $hints
= $sorter{$override_status}{$code_priority}{$tag_name}
{$context};
push(@sorted, $_)for @{$hints};
}
}
}
}
my @html_hints;
for my $hint (@sorted) {
my $tag = $profile->get_tag($hint->tag_name);
my %html_hint;
push(@html_hints, \%html_hint);
$html_hint{tag_name} = $hint->tag_name;
if ($option->{info}) {
# Link to explanation generated on this page.
$html_hint{url} = q{#} . $hint->tag_name;
} else {
# Link to the (now defunct) lintian.debian.org page.
$html_hint{url}
= 'https://lintian.debian.org/tags/' . $hint->tag_name;
}
$html_hint{context} = $hint->context
if length $hint->context;
$html_hint{visibility} = $tag->visibility;
$html_hint{visibility} = 'experimental'
if $tag->experimental;
my @comments;
if ($hint->override) {
$html_hint{visibility} = 'override';
push(@comments, $hint->override->justification)
if length $hint->override->justification;
}
# order matters
$html_hint{visibility} = 'mask'
if @{ $hint->masks };
for my $mask (@{$hint->masks}) {
push(@comments, 'masked by screen ' . $mask->screen);
push(@comments, $mask->excuse)
if length $mask->excuse;
}
$html_hint{comments} = \@comments
if @comments;
}
return \@html_hints;
}
=item describe_tags
=cut
sub describe_tags {
my ($self, $data, $tags) = @_;
for my $tag (@{$tags}) {
say encode_utf8('<p>Name: ' . $tag->name . '</p>');
say encode_utf8($EMPTY);
print encode_utf8(markdown($self->markdown_description($data, $tag)));
}
return;
}
=item issuedtags
Hash containing the tags which have been issued.
=cut
has issuedtags => (is => 'rw', default => sub { {} });
=item C<issue_tag($tag)>
Register a tag to have its description included in the output.
=cut
sub issue_tag {
my ($self, $tag) = @_;
$self->issuedtags->{$tag->name} = $tag;
return;
}
=item markdown_description
=cut
sub markdown_description {
my ($self, $data, $tag) = @_;
my $description = $tag->explanation;
my @extras;
if (@{$tag->see_also}) {
my @markdown
= map { markdown_citation($data, $_) } @{$tag->see_also};
my $references
= 'Please refer to '
. $self->oxford_enumeration('and', @markdown)
. ' for details.';
push(@extras, $references);
}
push(@extras, 'Visibility: '. $tag->visibility);
push(@extras, 'Check: ' . $tag->check)
if length $tag->check;
push(@extras, 'Renamed from: ' . join($SPACE, @{$tag->renamed_from}))
if @{$tag->renamed_from};
push(@extras, 'This tag is experimental.')
if $tag->experimental;
push(@extras,
'This tag is a classification. There is no issue in your package.')
if $tag->visibility eq 'classification';
for my $screen (@{$tag->screens}) {
my $screen_description = 'Screen: ' . $screen->name . $NEWLINE;
$screen_description
.= 'Advocates: ' . join(', ', @{$screen->advocates}) . $NEWLINE;
$screen_description .= 'Reason: ' . $screen->reason . $NEWLINE;
$screen_description .= 'See-Also: ' . $NEWLINE;
push(@extras, $screen_description);
}
$description .= $PARAGRAPH_BREAK . $_ for @extras;
return $description;
}
=back
=cut
1;
# Local Variables:
# indent-tabs-mode: nil
# cperl-indent-level: 4
# End:
# vim: syntax=perl sw=4 sts=4 sr et
|