[lintian] 03/09: r/html_reports: Move remaining code into a main sub
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch master
in repository lintian.
commit 12ff4b2c1e543064450826be2fb1195aa86c6d97
Author: Niels Thykier <niels@thykier.net>
Date: Sun Apr 24 20:14:43 2016 +0000
r/html_reports: Move remaining code into a main sub
Signed-off-by: Niels Thykier <niels@thykier.net>
---
reporting/html_reports | 126 ++++++++++++++++++++++++++-----------------------
1 file changed, 66 insertions(+), 60 deletions(-)
diff --git a/reporting/html_reports b/reporting/html_reports
index b36c4c3..3f5007c 100755
--- a/reporting/html_reports
+++ b/reporting/html_reports
@@ -89,50 +89,6 @@ our $TEMPLATES = "$LINTIAN_ROOT/reporting/templates";
# This only has to be done once, so do it at the start and then reuse the same
# templates throughout.
our %templates;
-for my $template (
- qw/head foot clean index maintainer maintainers packages tag
- tags tags-severity tag-not-seen tags-all/
- ) {
- open(my $fd, '<:encoding(UTF-8)', "$TEMPLATES/$template.tmpl");
- my %options = (TYPE => 'FILEHANDLE', SOURCE => $fd);
- $templates{$template} = Text::Template->new(%options)
- or die "cannot load template $template: $Text::Template::ERROR\n";
- close($fd);
-}
-
-{
- open(my $fd, '<:encoding(UTF-8)', "$TEMPLATES/lintian.css.tmpl");
- $templates{'lintian.css'} = Text::Template->new(
- TYPE => 'FILEHANDLE',
- SOURCE => $fd,
- DELIMITERS => ['{{{', '}}}'],
- )
- or die("cannot load template for lintian.css: $Text::Template::ERROR\n");
- close($fd);
-}
-
-# ------------------------------
-# Main routine
-
-setup_output_dir(
- 'output_dir' => $HTML_TMP_DIR,
- 'lintian_manual' => "${LINTIAN_ROOT}/doc/lintian.html",
- 'lintian_api_docs' => "${LINTIAN_ROOT}/doc/api.html",
- 'lintian_log_file' => $ARGV[0],
- 'resource_dirs' =>
- [map { "${LINTIAN_ROOT}/reporting/$_"} qw(images resources)],
-);
-
-# Create lintian.css from a template, install the output file as a resource
-# and discard the original output file. We do this after installing all
-# resources, so the .css file can refer to resources.
-output_template(
- 'lintian.css',
- $templates{'lintian.css'},
- { 'path_prefix' => '../' });
-$RESOURCE_MANAGER->install_resource("$HTML_TMP_DIR/lintian.css");
-
-my $STATE_CACHE = load_state_cache($HARNESS_STATE_DIR);
# %statistics accumulates global statistics. For tags: errors, warnings,
# experimental, overridden, and info are the keys holding the count of tags of
@@ -187,18 +143,67 @@ my @attrs = qw(maintainers source-packages binary-packages udeb-packages
errors warnings info experimental pedantic overridden groups-known
groups-backlog classifications);
-print "Parsing lintian log...\n";
-parse_lintian_log();
+# ------------------------------
+# Main routine
-process_data();
+main();
+
+sub main {
+ for my $template (
+ qw/head foot clean index maintainer maintainers packages tag
+ tags tags-severity tag-not-seen tags-all/
+ ) {
+ open(my $fd, '<:encoding(UTF-8)', "$TEMPLATES/$template.tmpl");
+ my %options = (TYPE => 'FILEHANDLE', SOURCE => $fd);
+ $templates{$template} = Text::Template->new(%options)
+ or die "cannot load template $template: $Text::Template::ERROR\n";
+ close($fd);
+ }
-exit 0;
+ {
+ open(my $fd, '<:encoding(UTF-8)', "$TEMPLATES/lintian.css.tmpl");
+ $templates{'lintian.css'} = Text::Template->new(
+ TYPE => 'FILEHANDLE',
+ SOURCE => $fd,
+ DELIMITERS => ['{{{', '}}}'],
+ )
+ or die(
+ "cannot load template for lintian.css: $Text::Template::ERROR\n");
+ close($fd);
+ }
+
+ setup_output_dir(
+ 'output_dir' => $HTML_TMP_DIR,
+ 'lintian_manual' => "${LINTIAN_ROOT}/doc/lintian.html",
+ 'lintian_api_docs' => "${LINTIAN_ROOT}/doc/api.html",
+ 'lintian_log_file' => $ARGV[0],
+ 'resource_dirs' =>
+ [map { "${LINTIAN_ROOT}/reporting/$_"} qw(images resources)],
+ );
+
+ # Create lintian.css from a template, install the output file as a resource
+ # and discard the original output file. We do this after installing all
+ # resources, so the .css file can refer to resources.
+ output_template(
+ 'lintian.css',
+ $templates{'lintian.css'},
+ { 'path_prefix' => '../' });
+ $RESOURCE_MANAGER->install_resource("$HTML_TMP_DIR/lintian.css");
+
+ my $state_cache = load_state_cache($HARNESS_STATE_DIR);
+
+ print "Parsing lintian log...\n";
+ parse_lintian_log($state_cache);
+
+ process_data($state_cache);
+ exit(0);
+}
# ------------------------------
# Utility functions
-
sub process_data {
+ my ($state_cache) = @_;
my @maintainers = sort(uniq(keys(%by_maint), keys(%by_uploader)));
{
@@ -206,7 +211,7 @@ sub process_data {
# structures are only used for a very few isolated items.
my (%qa, %sources);
print "Collecting statistics...\n";
- collect_statistics(\@maintainers, \%sources, \%qa);
+ collect_statistics($state_cache, \@maintainers, \%sources, \%qa);
generate_lookup_tables(\%sources);
@@ -224,10 +229,10 @@ sub process_data {
# use this later to generate stub pages for maintainers whose packages are
# all Lintian-clean.
my %clean;
- for my $group_id (sort(keys(%{$STATE_CACHE->{'groups'}}))) {
+ for my $group_id (sort(keys(%{$state_cache->{'groups'}}))) {
my $maintainer
- = $STATE_CACHE->{'groups'}{$group_id}{'mirror-metadata'}
- {'maintainer'};
+ = $state_cache->{'groups'}{$group_id}{'mirror-metadata'}
+ {'maintainer'};
my $id;
next if not $maintainer;
$id = maintainer_url($maintainer);
@@ -253,12 +258,12 @@ sub process_data {
for my $source (
keys %{ $by_maint{$maintainer} },
keys %{ $by_uploader{$maintainer} }
- ) {
+ ) {
my $versions = $by_maint{$maintainer}{$source}
- || $by_uploader{$maintainer}{$source};
+ || $by_uploader{$maintainer}{$source};
for my $version (keys %$versions) {
$versions->{$version}
- = [sort by_tag @{ $versions->{$version} }];
+ = [sort by_tag @{ $versions->{$version} }];
next if not $error_clean;
my $tags = $versions->{$version};
for my $tag (@$tags) {
@@ -435,7 +440,7 @@ sub setup_output_dir {
}
sub collect_statistics {
- my ($maintainers_ref, $sources_ref, $qa_list_ref) = @_;
+ my ($state_cache, $maintainers_ref, $sources_ref, $qa_list_ref) = @_;
# For each of this maintainer's packages, add statistical information
# about the number of each type of tag to the QA data and build the
@@ -484,9 +489,9 @@ sub collect_statistics {
if (-f $statistics_file) {
($old_statistics) = read_dpkg_control($statistics_file);
}
- $statistics{'groups-known'} = scalar(keys(%{$STATE_CACHE->{'groups'}}));
+ $statistics{'groups-known'} = scalar(keys(%{$state_cache->{'groups'}}));
$statistics{'groups-backlog'}
- = scalar(find_backlog($LINTIAN_VERSION,$STATE_CACHE));
+ = scalar(find_backlog($LINTIAN_VERSION,$state_cache));
for my $attr (@attrs) {
my $old = $old_statistics->{$attr} || 0;
@@ -702,6 +707,7 @@ sub maintainer_url {
}
sub parse_lintian_log {
+ my ($state_cache) = @_;
# We take a lintian log file on either standard input or as the
# first argument. This log file contains all the tags lintian
# found, plus N: tags with informational messages. Ignore all the
@@ -758,7 +764,7 @@ sub parse_lintian_log {
my $member_id
= "${type}:${package}/${version}"
. ($type ne 'source' ? "/$arch" : q{});
- my $state_data = $STATE_CACHE->{'members-to-groups'}{$member_id};
+ my $state_data = $state_cache->{'members-to-groups'}{$member_id};
next if exists($unknown_member_id{$member_id});
if ($type eq 'source') {
$source = $package;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git
Reply to: