FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 06-30-2011, 03:52 AM
Dave Reisner
 
Default contrib/paclist: rewrite in bash

The original concept for this script was a bash implementation, but
turned out to be unreasonable at the time due to the efficiencies of the
database format. Since those have been resolved, we can rewrite this in
bash as a much simpler script.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
Restore this script it its original intended glory in beautiful bash. I opted
for the gettext bindings to preserve pacman error messages.

contrib/paclist.in | 83 +++++++++++----------------------------------------
1 files changed, 18 insertions(+), 65 deletions(-)

diff --git a/contrib/paclist.in b/contrib/paclist.in
index 0379a4c..f6629e6 100755
--- a/contrib/paclist.in
+++ b/contrib/paclist.in
@@ -1,7 +1,8 @@
-#!/usr/bin/perl
+#!@BASH_SHELL@
# paclist - List all packages installed from a given repo
#
# Copyright (C) 2008 Dan McGee <dpmcgee@gmail.com>
+# Copyright (C) 2011 Dave Reisner <dreisner@archlinux.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -16,73 +17,25 @@
# 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;
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='/usr/share/locale'

-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
";
- print "Usage: $progname <repo>
";
- print "Example: $progname testing
";
- if ($#ARGV != 0) {
- exit 1;
+# determine whether we have gettext; make it a no-op if we do not
+if ! type gettext &>/dev/null; then
+ gettext() {
+ echo "$@"
}
- exit 0;
-}
-
-if ( $ARGV[0] eq "--version" || $ARGV[0] eq "-v") {
- print "$progname version $version
";
- print "Copyright (C) 2008 Dan McGee
";
- 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;
+fi

-$output = `pacman -Sl $ARGV[0]`;
-if ($? != 0) {
- exit 1;
-}
-my @sync = split(/
/, $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}++;
-}
+if [[ -z $1 ]]; then
+ printf 'usage: %s <repo>
' "${0##*/}"
+ exit 1
+fi

-$output = `pacman -Q`;
-if ($? != 0) {
- exit 1;
-}
-# sample output from pacman -Q:
-# foobar 1.0-1
-my @local = split(/
/, $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 }, $_;
- }
-}
+printf -v installed '[%s]' "$(gettext installed)"
+pacman -Sl $1 | awk -v i="$installed" '$NF == i { print $2 }'

-# print our intersection, and bask in the glory and speed of perl
-@intersection = sort @intersection;
-foreach $_ (@intersection) {
- print $_ . "
";
-}
+# exit with pacman's return value, not awk's
+exit ${PIPESTATUS[0]}

-#vim: set noet:
+# vim: set ts=2 sw=2 noet:
--
1.7.6
 
Old 06-30-2011, 09:32 AM
Allan McRae
 
Default contrib/paclist: rewrite in bash

On 30/06/11 13:52, Dave Reisner wrote:

The original concept for this script was a bash implementation, but
turned out to be unreasonable at the time due to the efficiencies of the
database format. Since those have been resolved, we can rewrite this in
bash as a much simpler script.

Signed-off-by: Dave Reisner<dreisner@archlinux.org>
---
Restore this script it its original intended glory in beautiful bash. I opted
for the gettext bindings to preserve pacman error messages.


Add the gettext part in the commit message as it is a good feature to
mention.


Also, can we get the version numbers back? I find them quite useful.

> paclist testing
avahi 0.6.30-4
cronie 1.4.8-1
...

> ./contrib/paclist testing
avahi
cronie
...

Allan
 
Old 06-30-2011, 01:10 PM
Dave Reisner
 
Default contrib/paclist: rewrite in bash

The original concept for this script was a bash implementation, but
turned out to be unreasonable at the time due to the efficiencies of the
database format. Since those have been resolved, we can rewrite this in
bash as a much simpler script.

All the action happens in a single line, but we add extend this a
little, binding to gettext to keep our pacman translations intact.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
Resend with Allan's suggestions addressed. I get to redeem myself and use the
right diff flags as well.

contrib/paclist.in | 129 ++++++++++++++++-----------------------------------
1 files changed, 41 insertions(+), 88 deletions(-)
rewrite contrib/paclist.in (69%)

diff --git a/contrib/paclist.in b/contrib/paclist.in
dissimilarity index 69%
index 0379a4c..f80fdce 100755
--- a/contrib/paclist.in
+++ b/contrib/paclist.in
@@ -1,88 +1,41 @@
-#!/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
";
- print "Usage: $progname <repo>
";
- print "Example: $progname testing
";
- if ($#ARGV != 0) {
- exit 1;
- }
- exit 0;
-}
-
-if ( $ARGV[0] eq "--version" || $ARGV[0] eq "-v") {
- print "$progname version $version
";
- print "Copyright (C) 2008 Dan McGee
";
- 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(/
/, $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(/
/, $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 $_ . "
";
-}
-
-#vim: set noet:
+#!@BASH_SHELL@
+# paclist - List all packages installed from a given repo
+#
+# Copyright (C) 2008 Dan McGee <dpmcgee@gmail.com>
+# Copyright (C) 2011 Dave Reisner <dreisner@archlinux.org>
+#
+# 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/>.
+
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='/usr/share/locale'
+
+# determine whether we have gettext; make it a no-op if we do not
+if ! type gettext &>/dev/null; then
+ gettext() {
+ echo "$@"
+ }
+fi
+
+if [[ -z $1 ]]; then
+ printf 'usage: %s <repo>
' "${0##*/}"
+ exit 1
+fi
+
+printf -v installed '[%s]' "$(gettext installed)"
+pacman -Sl $1 | awk -v i="$installed" '$NF == i { print $2,$3 }'
+
+# exit with pacman's return value, not awk's
+exit ${PIPESTATUS[0]}
+
+# vim: set ts=2 sw=2 noet:
--
1.7.6
 
Old 06-30-2011, 01:29 PM
Allan McRae
 
Default contrib/paclist: rewrite in bash

On 30/06/11 23:10, Dave Reisner wrote:

The original concept for this script was a bash implementation, but
turned out to be unreasonable at the time due to the efficiencies of the
database format. Since those have been resolved, we can rewrite this in
bash as a much simpler script.

All the action happens in a single line, but we add extend this a
little, binding to gettext to keep our pacman translations intact.

Signed-off-by: Dave Reisner<dreisner@archlinux.org>


Almost signed-off-by: Allan

Can we keep the old usage message too? Or at least something close to it.

allan@mugen /home/arch/code/pacman (working)
> paclist
paclist - List all packages installed from a given repo
Usage: paclist <repo>
Example: paclist testing

allan@mugen /home/arch/code/pacman (working)
> ./contrib/paclist
usage: paclist <repo>
 
Old 06-30-2011, 01:40 PM
Dave Reisner
 
Default contrib/paclist: rewrite in bash

On Thu, Jun 30, 2011 at 11:29:50PM +1000, Allan McRae wrote:
> On 30/06/11 23:10, Dave Reisner wrote:
> >The original concept for this script was a bash implementation, but
> >turned out to be unreasonable at the time due to the efficiencies of the
> >database format. Since those have been resolved, we can rewrite this in
> >bash as a much simpler script.
> >
> >All the action happens in a single line, but we add extend this a
> >little, binding to gettext to keep our pacman translations intact.
> >
> >Signed-off-by: Dave Reisner<dreisner@archlinux.org>
>
> Almost signed-off-by: Allan
>
> Can we keep the old usage message too? Or at least something close to it.
>
> allan@mugen /home/arch/code/pacman (working)
> > paclist
> paclist - List all packages installed from a given repo
> Usage: paclist <repo>
> Example: paclist testing
>
> allan@mugen /home/arch/code/pacman (working)
> > ./contrib/paclist
> usage: paclist <repo>
>

And spoil all the magic? What hidden treasures might be unearthed by
this wonderous tool of mischief and mayhem? WHO KNOWS?! There's only one
way to find out!

$ paclist gold!
error: repository "gold!" was not found.

Yeah, yeah. It's added.

d
 

Thread Tools




All times are GMT. The time now is 05:09 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org