Re: [gentoo-dev] RFC: postgresql.eselect

2011-03-29 Thread Ulrich Mueller
 On Mon, 28 Mar 2011, Aaron W Swenson wrote:

 This module is to replace the existing one that is shipped with
 app-admin/eselect-postgresql-1.0.3. It is an entire rewrite.

Some remarks:

- Global scope code is a no-no in eselect modules, especially if it
  calls external programs or accesses external files. Your module
  will be sourced for commands like eselect modules list and there
  shouldn't be any global scope code being run on such occasions.

- Don't use eval. It's almost always an indication that you're doing
  something wrong.

- For tests, please use [[ ]] rather than [ ] throughout.

- output and path-manipulation libraries are always loaded, so you
  need not (and in fact, you shouldn't) inherit them.

- Don't hardcode terminal specific escape sequences (like \033[1m).
  Use the highlighting functions of the output library instead (which
  in turn use tput).

- Suppressing stdout of commands like do_action env update is fine,
  but why suppress stderr?

- Please avoid lines wider than 79 positions.

See also eselect's README and the developer guide:
http://sources.gentoo.org/cgi-bin/viewvc.cgi/eselect/trunk/README
http://www.gentoo.org/proj/en/eselect/dev-guide.xml

Ulrich



Re: [gentoo-dev] RFC: postgresql.eselect

2011-03-29 Thread Aaron W. Swenson
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

On 03/29/2011 05:06 AM, Ulrich Mueller wrote:
 On Mon, 28 Mar 2011, Aaron W Swenson wrote:
 
 This module is to replace the existing one that is shipped with
 app-admin/eselect-postgresql-1.0.3. It is an entire rewrite.
 
 Some remarks:
 
 - Global scope code is a no-no in eselect modules, especially if it
   calls external programs or accesses external files. Your module
   will be sourced for commands like eselect modules list and there
   shouldn't be any global scope code being run on such occasions.
 
Fixed.

 - Don't use eval. It's almost always an indication that you're doing
   something wrong.
 
Yeah, I should have used 'find' as fewer tricks are needed. Wonder why
I didn't do that in the first place

 - For tests, please use [[ ]] rather than [ ] throughout.
 
Done.

 - output and path-manipulation libraries are always loaded, so you
   need not (and in fact, you shouldn't) inherit them.
 
The dev guide could be clearer on that. Removed them from the inherit line.

 - Don't hardcode terminal specific escape sequences (like \033[1m).
   Use the highlighting functions of the output library instead (which
   in turn use tput).
 
Except $(highlight ...) doesn't work in plain echo. So, I just stripped
it out.

 - Suppressing stdout of commands like do_action env update is fine,
   but why suppress stderr?
 
Because 'ls' would complain that files didn't exist, such as lib*.dylib
when on a Linux system. It doesn't matter. But, using 'find' avoids this
mess.

 - Please avoid lines wider than 79 positions.
 
Did where I could.

 See also eselect's README and the developer guide:
 http://sources.gentoo.org/cgi-bin/viewvc.cgi/eselect/trunk/README
Never knew that existed. Thanks for pointing that out.

 http://www.gentoo.org/proj/en/eselect/dev-guide.xml
 
That's where I got all of my information.

 Ulrich
 

Thank you for the feedback. It was quite helpful.

Now, I'm a bit sketchy on the handling of choosing which bitness for the
executables. (psql and friends.)

Sincerely,
  Mr. Aaron W. Swenson
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.17 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iF4EAREIAAYFAk2SSX0ACgkQCOhwUhu5AEk4xQD9E6jabiGSNYycJSU871p82H1O
0iIU1kBV2HMhfJId/NgA/0Zoq2O3Pcy9O2OcthsQb6e8ZipJZ+dpffMCaC0zOqrs
=L/aO
-END PGP SIGNATURE-



[gentoo-dev] RFC: postgresql.eselect

2011-03-28 Thread Aaron W. Swenson
Dear List,

This module is to replace the existing one that is shipped with
app-admin/eselect-postgresql-1.0.3. It is an entire rewrite.

Changes can be tracked at:
http://git.overlays.gentoo.org/gitweb/?p=proj/pgsql-patches.git;a=shortlog;h=refs/heads/eselect

Before you start reading the attached module, please bear in mind that I
am a novice at writing BASH scripts, and am not intimately familiar with
all the nuances of the language.

There is some duplication of work within the module when compared with
the current postgresql-{base,server}-*.ebuilds in the tree. The plan is
to move that work being handled in the ebuilds to the module.

Setting a service slot has been dropped from the module as it is no
longer necessary.

Features:
* Supports --brief output
* Prefix compatible
* Slot specific application links (e.g., psql90, createdb84)
* Automatically sets the highest slot available as the default unless a
  valid slot is already set
* Properly orders LDPATH giving preference to the set slot and then
  lists the other slots in descending order

Thank you.

Sincerely,
  Mr. Aaron W. Swenson (TitanOfOld)
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id: $

inherit config multilib output package-manager path-manipulation

DESCRIPTION=Manage active PostgreSQL client applications and libraries
MAINTAINER=pgsql-b...@gentoo.org
SVN_DATE='$Date: $'
VERSION=1.0.4

# Global Data
B_PATH=${EROOT%/}/usr
E_PATH=${EROOT%/}/etc/eselect/postgresql
ENV_FILE=${EROOT%/}/etc/env.d/50postgresql
if [ -r ${E_PATH}/active -a -n ${E_PATH}/active ] ; then
ACTIVE_SLOT=$(${E_PATH}/active)
else
ACTIVE_SLOT=(none)
fi
LIB_LIST=$(list_libdirs)
if [[ ${LIB_LIST} =~ .*lib64.*  $(ls -d ${B_PATH}/lib64/postgresql-*/lib) 
!=  ]] ; then
LIBDIR=lib64
elif [[ ${LIB_LIST} =~ .*lib32.*  $(ls -d ${B_PATH}/lib32/postgresql-*/lib) 
!=  ]] ; then
LIBDIR=lib32
else
LIBDIR=lib
fi

### Linker Function ###
# Takes three arguments:
#   - Full source path (e.g. /usr/lib/postgresql-9.0/lib/lib*.{a,so})
#   - Full target directory path (e.g. /usr/bin)
#   - Suffix (Optional) (e.g 84 to make /usr/bin/psql84)
linker() {
local source_dir=$1
local target_dir=$2
local suffix=$3
local link_source

for link_source in $(eval ls ${source_dir} 2 /dev/null) ; do
local link_target=${target_dir%/}/$(basename 
${link_source})${suffix}

# For good measure, remove target before creating the symlink
[ -h ${link_target} ]  rm -f ${link_target}
[ -e ${link_target} ]  die -q The target '${link_target}' 
still exists and could not be removed!

ln -s ${link_source} ${link_target} || die -q Unable to create 
link!
echo ${link_target}  ${E_PATH}/active.links${suffix}
done
}

### Unlinker Function ###
# Takes one argument:
#   - Full path to active links file (e.g. /etc/eselect/postgresql/active.links)
unlinker() {
local active_link_file=$1
if [ -r ${active_link_file} ] ; then
local active_links=($(${active_link_file}))
for (( i=0; $i  ${#active_links[@]}; i++ )) ; do
[ -h ${active_links[$i]} ]  rm -f ${active_links[$i]}
[ -e ${active_links[$i]} ]  die -q The target 
'${active_links[$i]}' still exists and could not be removed!
done

rm -f ${active_link_file}
fi
}

### Get Slots Function ###
# Find all available slots in the preferred LIBDIR and return them.
get_slots() {
echo $(ls -dv ${B_PATH}/${LIBDIR}/postgresql-* 2 /dev/null | sed -re 
's#^.+-##')
}

### List Action ###
describe_list() {
echo List available PostgreSQL slots.
}

do_list() {
write_list_start Available PostgreSQL Slots

if $(is_output_mode brief) ; then
echo $(get_slots)
else
local slot
for slot in $(get_slots) ; do
local postgres_ebuilds=
local src
for src in 
${E_PATH}/slots/${slot}/{server,service,base,docs} ; do
[ -r ${src} ]  source ${src}
done

case ${slot} in
${ACTIVE_SLOT} ) write_kv_list_entry 
$(highlight_marker ${slot}) ${postgres_ebuilds//postgresql-/};;
*) write_kv_list_entry 
${slot} ${postgres_ebuilds//postgresql-/};;
esac
done

[ -z ${postgres_ebuilds} ]  write_warning_msg No slots 
available.
fi
}

### Show Action ###
describe_show() {
echo Show which slot is currently active.
}

do_show() {
echo ${ACTIVE_SLOT}
}

### Show Service Action ###
# Here for backwards compatibility with ebuilds
describe_show-service()  {