summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChantry Xavier <shiningxc@gmail.com>2008-05-10 12:33:15 +0200
committerDan McGee <dan@archlinux.org>2008-05-10 11:13:24 -0500
commit0bfc8adf377e7c0d4870fd79999b359a00bc96e2 (patch)
tree4659e0f767d41fc74f9cac3a2baf37f0446bc48d
parent1ba0d84da29d436f2b82c8961886ea2d021194d0 (diff)
contrib/paclist: list packages installed from given repo.
The paclist script provides a simple method for monitoring which packages are installed from a given repo. This is particularly useful when using a testing or unstable repository. Thanks to Allan McRae for the idea and an initial bash script. As suggested by Dan, I tried to rewrite in perl, and this resulted in much better performance. Then Dan further cleaned up the script. Signed-off-by: Chantry Xavier <shiningxc@gmail.com> [Dan: add to Makefile & README, minor script cleanups] Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--contrib/Makefile.am1
-rw-r--r--contrib/README4
-rwxr-xr-xcontrib/paclist88
3 files changed, 93 insertions, 0 deletions
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index 7eee91a1..c68ef51c 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -3,6 +3,7 @@ EXTRA_DIST = \
bash_completion \
gensync \
pacdiff \
+ paclist \
pacsearch \
re-pacman \
updatesync \
diff --git a/contrib/README b/contrib/README
index 1a1b6a9c..73dbade0 100644
--- a/contrib/README
+++ b/contrib/README
@@ -12,6 +12,10 @@ zsh_completion - a zsh completion script, install (with a rename) to
pacdiff - a simple pacnew/pacorig/pacsave updater for /etc/.
+paclist - list all packages installed from a given repository. Useful for
+seeing which packages you may have installed from the testing repository,
+for instance.
+
pacsearch - a colorized search combining both -Ss and -Qs output. Installed
packages are easily identified with a *** and local-only packages are also
listed.
diff --git a/contrib/paclist b/contrib/paclist
new file mode 100755
index 00000000..0379a4c5
--- /dev/null
+++ b/contrib/paclist
@@ -0,0 +1,88 @@
+#!/usr/bin/perl
+# paclist - List all packages installed from a given repo
+#
+# Copyright (C) 2008 Dan McGee <dpmcgee@gmail.com>
+#
+# 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, see <http://www.gnu.org/licenses/>.
+
+use strict;
+use warnings;
+
+my $progname = "paclist";
+my $version = "1.0";
+
+if ($#ARGV != 0 || $ARGV[0] eq "--help" || $ARGV[0] eq "-h") {
+ print "$progname - List all packages installed from a given repo\n";
+ print "Usage: $progname <repo>\n";
+ print "Example: $progname testing\n";
+ if ($#ARGV != 0) {
+ exit 1;
+ }
+ exit 0;
+}
+
+if ( $ARGV[0] eq "--version" || $ARGV[0] eq "-v") {
+ print "$progname version $version\n";
+ print "Copyright (C) 2008 Dan McGee\n";
+ exit 0;
+}
+
+# This hash table will be used to store pairs of ('name version', count) from
+# the return of both pacman -Sl <repo> and pacman -Q output. We then check to
+# see if a value was added twice (count = 2)- if so, we will print that package
+# as it is both in the repo we queried and installed on our local system.
+my %packages = ();
+my $output;
+
+$output = `pacman -Sl $ARGV[0]`;
+if ($? != 0) {
+ exit 1;
+}
+my @sync = split(/\n/, $output);
+# sample output from pacman -Sl:
+# testing foobar 1.0-1
+foreach $_ (@sync) {
+ my @info = split(/ /);
+ # we only want to store 'foobar 1.0-1' in our hash table
+ my $pkg = $info[1] . " " . $info[2];
+ $packages{$pkg}++;
+}
+
+$output = `pacman -Q`;
+if ($? != 0) {
+ exit 1;
+}
+# sample output from pacman -Q:
+# foobar 1.0-1
+my @local = split(/\n/, $output);
+foreach $_ (@local) {
+ # store 'foobar 1.0-1' in our hash table
+ $packages{$_}++;
+}
+
+# run comparison check- if value was added twice, it was in the intersection
+my @intersection;
+foreach $_ (keys %packages) {
+ if ($packages{$_} == 2) {
+ push @{ \@intersection }, $_;
+ }
+}
+
+# print our intersection, and bask in the glory and speed of perl
+@intersection = sort @intersection;
+foreach $_ (@intersection) {
+ print $_ . "\n";
+}
+
+#vim: set noet: