[lintian] 01/03: Create a new "lab-tool" cmd
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch master
in repository lintian.
commit 1672cb12b350f7574d62e4ec13e7f674e6bf7863
Author: Niels Thykier <niels@thykier.net>
Date: Sun Jan 31 11:40:43 2016 +0000
Create a new "lab-tool" cmd
Signed-off-by: Niels Thykier <niels@thykier.net>
---
commands/lab-tool.pm | 208 ++++++++++++++++++++++++++++++++++++++++++++++
debian/changelog | 9 ++
debian/lintian.links | 1 +
debian/manpages | 5 +-
debian/rules | 13 ++-
frontend/lintian-lab-tool | 1 +
man/lintian-lab-tool.pod | 100 ++++++++++++++++++++++
7 files changed, 330 insertions(+), 7 deletions(-)
diff --git a/commands/lab-tool.pm b/commands/lab-tool.pm
new file mode 100644
index 0000000..ab0e33b
--- /dev/null
+++ b/commands/lab-tool.pm
@@ -0,0 +1,208 @@
+#!/usr/bin/perl
+
+# Lintian Lab Tool -- Various Laboratory related utilities
+#
+# Copyright (C) 2016 Niels Thykier
+#
+# Based on "frontend/lintian", which was:
+# Copyright (C) 1998 Christian Schwarz and Richard Braakman
+#
+# This program is free software. It is distributed 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 http://www.gnu.org/copyleft/gpl.html, or write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+use strict;
+use warnings;
+
+use List::Util qw(max);
+
+use Lintian::Lab;
+
+# turn file buffering off:
+STDOUT->autoflush;
+
+my %OPERATIONS = (
+ 'help' => \&help,
+ 'create-lab' => \&create_lab,
+ 'remove-lab' => \&remove_lab,
+ 'remove-pkgs' => \&remove_pkgs_from_lab,
+ 'scrub-lab' => \&scrub_lab,
+);
+
+my %CMD_LINE_SYNOPSIS = (
+ 'help' => '[operation]',
+ 'create-lab' => '<lab-directory>',
+ 'remove-lab' => '<lab-directory>',
+ 'remove-pkgs' => '<lab-directory> <lab-query> [... <lab-query>]',
+ 'scrub-lab' => '<lab-directory>',
+);
+
+my %HUMAN_SYNOPSIS = (
+ 'help' => 'Display help about this command or a given operation.',
+ 'create-lab' => 'Create a laboratory',
+ 'remove-lab' => 'Remove a laboratory',
+ 'remove-pkgs' =>
+ 'Remove packages matching a given query from the laboratory',
+ 'scrub-lab' =>
+ 'Attempt to fix simple metadata corruptions in the laboratory',
+);
+
+sub error {
+ my ($msg) = @_;
+ print "$msg\n";
+ exit(2);
+}
+
+sub main {
+ my ($cmd_name, @args) = @ARGV;
+ my $cmd;
+ $cmd_name //= 'help';
+ if ($cmd_name eq '-h' or $cmd_name eq '--help') {
+ print "(Please use \"help\" instead of \"${cmd_name}\"\n";
+ $cmd_name = 'help';
+ }
+ $cmd = $OPERATIONS{$cmd_name};
+ if (not $cmd) {
+ error("Unknown command \"${cmd_name}\" - try using \"help\" instead");
+ }
+ exit($cmd->($cmd_name, @args));
+}
+
+sub with_lab($&) {
+ my ($lab_dir, $closure) = @_;
+ my $lab = Lintian::Lab->new($lab_dir);
+ my ($act_err, $lab_close_err, $ret);
+ $lab->open;
+ eval {
+ $ret = $closure->($lab);
+ $ret //= 0;
+ };
+ $act_err = $@;
+ eval {$lab->close;};
+ $lab_close_err = $@;
+ die($act_err) if $act_err;
+ die($lab_close_err) if $lab_close_err;
+ return $ret;
+}
+
+sub validate_lab_dir_arg {
+ my ($dir) = @_;
+ if (not defined($dir)) {
+ error("Missing laboratory path");
+ }
+ return $dir;
+}
+
+sub help {
+ my (undef, $given_cmd) = @_;
+ my $me = $ENV{'LINTIAN_DPLINT_CALLED_AS'} // $0;
+
+ if (defined($given_cmd)) {
+ my $cmd_synopsis = $CMD_LINE_SYNOPSIS{$given_cmd} // '';
+ my $synopsis = $HUMAN_SYNOPSIS{$given_cmd} // 'No synopsis available';
+ if (not exists($OPERATIONS{$given_cmd})) {
+ print "Unknown command $given_cmd\n";
+ return 1;
+ }
+ print <<EOF;
+Usage: ${me} ${given_cmd} ${cmd_synopsis}
+
+${synopsis}
+EOF
+
+ } else {
+ my @cmds = sort(keys(%OPERATIONS));
+ my $cmd_length = max(map { length } @cmds);
+
+ print <<EOF;
+Usage: ${me} <cmd> [args ...]
+
+Perform some common operations on (or related to) permanent Lintian laboratories.
+
+Available operations:
+EOF
+
+ for my $cmd (@cmds) {
+ my $synopsis = $HUMAN_SYNOPSIS{$cmd} // 'No synopsis available';
+ printf " %-*s %s\n", $cmd_length, $cmd, $synopsis;
+ }
+ }
+ return 0;
+}
+
+sub create_lab {
+ my (undef, $lab_dir) = @_;
+ my $lab;
+ validate_lab_dir_arg($lab_dir);
+ $lab = Lintian::Lab->new($lab_dir);
+ $lab->create;
+ return 0;
+}
+
+sub remove_lab {
+ my (undef, $lab_dir) = @_;
+ my $lab;
+ validate_lab_dir_arg($lab_dir);
+ $lab = Lintian::Lab->new($lab_dir);
+ $lab->remove;
+ return 0;
+}
+
+sub scrub_lab {
+ my (undef, $lab_dir) = @_;
+ validate_lab_dir_arg($lab_dir);
+ return with_lab $lab_dir, sub {
+ my ($lab) = @_;
+ $lab->repair;
+ return 0;
+ };
+}
+
+sub remove_pkgs_from_lab {
+ my (undef, $lab_dir, @queries) = @_;
+ validate_lab_dir_arg($lab_dir);
+ if (not @queries) {
+ error("Please specify a \"lab query\" to delete items from the lab");
+ }
+ return with_lab $lab_dir, sub {
+ my ($lab) = @_;
+ my $had_match = 0;
+ for my $query (@queries) {
+ my @res = $lab->lab_query($query);
+ if (not @res) {
+ print "No matches for $query\n";
+ }
+ $had_match = 1;
+ for my $entry (@res) {
+ my $identifier = $entry->identifier;
+ print "Removing $identifier (matched by $query)\n";
+ $entry->remove;
+ }
+ }
+ if (not $had_match) {
+ print "Nothing matched any of the queries given";
+ return 1;
+ }
+ return 0;
+ };
+}
+
+1;
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et
diff --git a/debian/changelog b/debian/changelog
index beb11da..06df66a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -11,10 +11,16 @@ lintian (2.5.41) UNRELEASED; urgency=medium
+ [JW] Treat packages without Multi-Arch field as if they had
"Multi-Arch: no". Thanks to Bas Couwenberg for the bug report.
+ * commands/lab-tool.pm:
+ + [NT] New utility to handle most laboratory operations.
+
* data/spelling/corrections:
+ [JW] Fix some corrections.
+ [JW] Add more corrections.
+ * debian/{lintian.links,manpages,rules}:
+ + [NT] Update to install the new lab-tool command.
+
* helper/coll/objdump-info-helper:
+ [NT] Avoid collecting unused information.
@@ -29,6 +35,9 @@ lintian (2.5.41) UNRELEASED; urgency=medium
* lib/Lintian/Tag/Override.pm:
+ [JW] Fix typo.
+ * man/lintian-lab-tool.pod:
+ + [NT] New file.
+
-- Niels Thykier <niels@thykier.net> Sun, 24 Jan 2016 12:58:06 +0000
lintian (2.5.40.2) unstable; urgency=medium
diff --git a/debian/lintian.links b/debian/lintian.links
index af82eef..2f81e92 100644
--- a/debian/lintian.links
+++ b/debian/lintian.links
@@ -1,2 +1,3 @@
usr/share/lintian/frontend/dplint usr/bin/lintian-info
+usr/share/lintian/frontend/dplint usr/bin/lintian-lab-tool
usr/share/lintian/frontend/dplint usr/bin/spellintian
diff --git a/debian/manpages b/debian/manpages
index df798c5..c45f27d 100644
--- a/debian/manpages
+++ b/debian/manpages
@@ -1,3 +1,2 @@
-man/man1/lintian.1
-man/man1/lintian-info.1
-man/man1/spellintian.1
+man/man1/*.1
+
diff --git a/debian/rules b/debian/rules
index 9d8bcc8..923f426 100755
--- a/debian/rules
+++ b/debian/rules
@@ -6,9 +6,11 @@ VER := $(shell head -1 debian/changelog | sed -e 's/^.*(//' -e 's/).*$$//')
tmp := $(CURDIR)/debian/lintian
profiles := profiles/debian/main.profile \
profiles/debian/ftp-master-auto-reject.profile
-neededfiles := debian/rules frontend/lintian $(profiles)
+neededfiles := debian/rules frontend/lintian $(profiles) \
+ $(wildcard commands/*)
+pod2mansources := $(wildcard man/*.pod)
docsource := doc/lintian.xml README man/lintian.pod.in \
- man/lintian-info.pod man/spellintian.pod
+ $(pod2mansources)
allchecks := $(wildcard checks/*)
allcollect := $(wildcard collection/*)
tagfiles := $(wildcard t/changes/*.changes t/*/*/tags)
@@ -75,8 +77,11 @@ generate-docs-stamp: $(docsource)
mkdir -p man/man1/
private/generate-lintian-pod | \
pod2man --name lintian --center "Debian Package Checker" --section=1 > man/man1/lintian.1
- pod2man --section=1 man/lintian-info.pod > man/man1/lintian-info.1
- pod2man --section=1 man/spellintian.pod > man/man1/spellintian.1
+ set -e ; for POD in $(pod2mansources) ; do \
+ DIR=$$(dirname "$$POD") ; \
+ BASENAME=$$(basename "$$POD" .pod) ; \
+ pod2man --section=1 "$$POD" > "$$DIR/man1/$$BASENAME".1 ; \
+ done
private/generate-html-docs doc/api.html > /dev/null
touch $@
diff --git a/frontend/lintian-lab-tool b/frontend/lintian-lab-tool
new file mode 120000
index 0000000..47fbfa6
--- /dev/null
+++ b/frontend/lintian-lab-tool
@@ -0,0 +1 @@
+dplint
\ No newline at end of file
diff --git a/man/lintian-lab-tool.pod b/man/lintian-lab-tool.pod
new file mode 100644
index 0000000..956950e
--- /dev/null
+++ b/man/lintian-lab-tool.pod
@@ -0,0 +1,100 @@
+# Copyright 2016 Niels Thykier
+#
+# This manual page is free software. It is distributed 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 manual page 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 manual page; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+# USA
+#
+
+=head1 NAME
+
+lintian-lab-tool - perform common operations on/involving laboratories
+
+=head1 SYNOPSIS
+
+B<lintian-lab-tool> <cmd> <lab> [...]
+
+B<lintian-lab-tool> help
+
+=head1 DESCRIPTION
+
+The B<lintian-lab-tool> ...
+
+
+=head1 OPERATIONS
+
+=over 4
+
+=item B<create-lab> F<laboratory-dir>
+
+Creates a new permanent Lintian laboratory in the directory denoted by B<laboratory-dir>.
+
+=item B<help> [I<cmd>]
+
+Display the synopsis of this tool or one of its operations.
+
+=item B<remove-lab> F<laboratory-dir>
+
+Removes a permanent Lintian laboratory in the directory denoted by B<laboratory-dir>.
+
+=item B<remove-pkgs> F<laboratory-dir> I<query> [... I<query>]
+
+Removes all packages matching the given I<queries> from the permanent Lintian laboratory
+denoted by B<laboratory-dir>.
+
+=item B<scrub-lab> F<laboratory-dir>
+
+Attempt to fix common metadata issues in an existing laboratory.
+
+This command can correct I<some> corruptions caused by programs that failed to synchronize
+the laboratory metadata with the actual contents. Almost all corrections involve discarding
+corrupted entries.
+
+These issues usually occur because:
+
+=over 4
+
+=item *
+
+Two proceses update the laboratory concurrently.
+
+=item *
+
+A process updated the laboratory but was killed / crashed before it properly close the
+laboratory.
+
+=back
+
+Note that Lintian tools will fix these issues automatically as the tools happen to run into
+the issues.
+
+=back
+
+=head1 CAVEAT
+
+Laboratories are not designed to have multiple processes working on them concurrently.
+
+=head1 SEE ALSO
+
+L<lintian(1)>
+
+=head1 AUTHORS
+
+Niels Thykier <niels@thykier.net>
+
+Richard Braakman <dark@xs4all.nl>
+
+Christian Schwarz <schwarz@monet.m.isar.de>
+
+=cut
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git
Reply to: