[lintian] 01/01: c/r-html-reports: Use scour if available to minimize SVG files
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch master
in repository lintian.
commit cd6396ecf8f4cc58780e1f5990ed75748ab5be1e
Author: Niels Thykier <niels@thykier.net>
Date: Mon Feb 12 21:33:40 2018 +0000
c/r-html-reports: Use scour if available to minimize SVG files
Signed-off-by: Niels Thykier <niels@thykier.net>
---
commands/reporting-html-reports.pm | 47 ++++++++++++++++++++++++++++++++++++--
debian/changelog | 4 ++++
2 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/commands/reporting-html-reports.pm b/commands/reporting-html-reports.pm
index c355687..1eaaa49 100644
--- a/commands/reporting-html-reports.pm
+++ b/commands/reporting-html-reports.pm
@@ -56,7 +56,7 @@ my (
$RESOURCE_MANAGER, $LINTIAN_VERSION, $timestamp,
$TEMPLATE_CONFIG_VARS,$HARNESS_STATE_DIR, $HISTORY_DIR,
$HISTORY, $GRAPHS, $LINTIAN_ROOT,
- $HTML_TMP_DIR,
+ $HTML_TMP_DIR, $SCOUR_ENABLED,
);
# FIXME: Should become obsolete if gnuplot is replaced by R like piuparts.d.o /
# reproducible.d.n is using
@@ -208,6 +208,16 @@ sub init_globals {
$GRAPHS = 0;
print "No graphs as \"gnuplot\" is not in PATH\n";
}
+ if ($GRAPHS) {
+ if (check_path('scour')) {
+ $SCOUR_ENABLED = 1;
+ print "Minimizing generated SVG files (scour is in PATH)\n";
+ } else {
+ $SCOUR_ENABLED = 0;
+ print 'No minimization of generated SVG files'
+ . " as \"scour\" is not in PATH\n";
+ }
+ }
} else {
$HISTORY = 0;
$GRAPHS = 0;
@@ -673,6 +683,14 @@ sub generate_package_index_packages {
return;
}
+sub run_scour {
+ my ($input_file, $output_file) = @_;
+ run_cmd('scour', '-i',$input_file, '-o',$output_file, '-q',
+ '--enable-id-stripping', '--enable-comment-stripping',
+ '--shorten-ids', '--indent=none');
+ return 1;
+}
+
sub update_history_and_make_graphs {
my ($attrs_ref, $statistics_ref, $tag_statistics_ref) = @_;
# Update history.
@@ -743,6 +761,19 @@ sub update_history_and_make_graphs {
run_cmd({ 'chdir' => $graph_dir},
'gnuplot',"$LINTIAN_ROOT/reporting/graphs/statistics.gpi");
+ if ($SCOUR_ENABLED) {
+ # Do a little "rename" dance to ensure that we keep the
+ # "statistics.svg"-basename without having to use a
+ # subdirectory.
+ rename(
+ "${graph_dir}/statistics.svg",
+ "${graph_dir}/_statistics-orig.svg"
+ );
+ run_scour(
+ "${graph_dir}/_statistics-orig.svg",
+ "${graph_dir}/statistics.svg"
+ );
+ }
$RESOURCE_MANAGER->install_resource("${graph_dir}/statistics.svg");
}
@@ -767,11 +798,23 @@ sub update_history_and_make_graphs {
}
if ($GRAPHS) {
+ my $svg_dir = "${graph_dir}/tags";
close($gnuplot_fd);
run_cmd({'chdir' => $graph_dir}, 'gnuplot', 'call.gpi');
unlink($commonf);
+ if ($SCOUR_ENABLED) {
+ # Obvious optimization potential; run scour in parallel
+ my $optimized_dir = "${graph_dir}/tags-optimized";
+ mkdir($optimized_dir);
+ print "Minimizing tag graphs; this may take a while ...\n";
+ for my $tag (sort(keys(%{$tag_statistics_ref}))) {
+ run_scour("${svg_dir}/${tag}.svg",
+ "${optimized_dir}/${tag}.svg");
+ }
+ $svg_dir = $optimized_dir;
+ }
for my $tag (sort(keys(%{$tag_statistics_ref}))) {
- my $graph_file = "${graph_dir}/tags/${tag}.svg";
+ my $graph_file = "${svg_dir}/${tag}.svg";
$RESOURCE_MANAGER->install_resource($graph_file);
}
delete_dir($graph_dir);
diff --git a/debian/changelog b/debian/changelog
index e614910..8fbfe8c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -17,6 +17,10 @@ lintian (2.5.75) UNRELEASED; urgency=medium
new-package-should-not-package-python2-module tag but rather leave a
comment in debian/changelog.
+ * commands/reporting-html-reports.html:
+ + [NT] Minimize generated SVG files if scour is installed and
+ available in PATH.
+
-- Chris Lamb <lamby@debian.org> Thu, 08 Feb 2018 18:00:44 +0000
lintian (2.5.74) unstable; urgency=medium
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git
Reply to: