OpenPKG CVS Repository
http://cvs.openpkg.org/
____________________________________________________________________________
Server: cvs.openpkg.org Name: Thomas Lotterer
Root: /v/openpkg/cvs Email: [EMAIL PROTECTED]
Module: openpkg-registry Date: 03-Aug-2006 00:15:39
Branch: HEAD Handle: 2006080223153800
Added files:
openpkg-registry registry.pm
Modified files:
openpkg-registry Makefile registry-ui.pl
Log:
move common registry code to handle config and default configuration
text to a perl module
Summary:
Revision Changes Path
1.17 +8 -3 openpkg-registry/Makefile
1.88 +12 -153 openpkg-registry/registry-ui.pl
1.1 +204 -0 openpkg-registry/registry.pm
____________________________________________________________________________
patch -p0 <<'@@ .'
Index: openpkg-registry/Makefile
============================================================================
$ cvs diff -u -r1.16 -r1.17 Makefile
--- openpkg-registry/Makefile 2 Aug 2006 22:06:30 -0000 1.16
+++ openpkg-registry/Makefile 2 Aug 2006 22:15:38 -0000 1.17
@@ -4,6 +4,7 @@
VERSION_FILE = VERSION
TMP = tmp/
POD2MAN = pod2man
+PERL = /openpkg-reg/bin/perl
all:
@echo "$(MAKE) clean ....... delete temporary files"
@@ -51,13 +52,14 @@
shtool subst \
-e "s/^my \\\$$progvers=\"[^\"]*\";/my
\\\$$progvers=\"$${V}\";/" \
-e "s/^my \\\$$progdate=\"[^\"]*\";/my
\\\$$progdate=\"$${D}\";/" \
- registry-db.pl registry-ui.pl
+ registry-db.pl registry-ui.pl registry.pm
register.8: register.sh
@echo "++ generating register.8 manual page"; \
$(POD2MAN) --section=8 --center="OpenPKG" \
--release=\"$${V}\" --date=\"$${D}\" \
register.sh >register.8
+
tag:
@V=`shtool version -l txt -d short $(VERSION_FILE) | sed -e
's;\.;_;g'`; \
echo "++ tagging with OPENPKG_REGISTRY_$$V"; \
@@ -84,12 +86,13 @@
-e "s/^my \\\$$progvers=\"[^\"]*\";/my
\\\$$progvers=\"$${V}\";/" \
-e "s/^my \\\$$progdate=\"[^\"]*\";/my
\\\$$progdate=\"$${D}\";/" \
-e "s;@l_prefix@;/openpkg-reg;g" \
- registry-*-rm0.pl register-rm0.sh
+ -e "s;/registry.pm;/registry-dev.pm;g" \
$(TMP)rm0/*
( for i in `builtin cd $(TMP)rm0/ && echo *`; do diff -U 3 $$i
$(TMP)rm0/$$i; done ) | cvs-diff-colorize
scp $(TMP)rm0/register.sh [EMAIL
PROTECTED]:/openpkg-reg/libexec/openpkg-tools/register-dev.sh
scp $(TMP)rm0/registry-ui.pl [EMAIL
PROTECTED]:/openpkg-reg/cgi/openpkg-registry/registry-ui-dev.pl
scp $(TMP)rm0/registry-db.pl [EMAIL
PROTECTED]:/openpkg-reg/sbin/registry-db-dev
+ scp $(TMP)rm0/registry.pm [EMAIL
PROTECTED]:/openpkg-reg/libexec/openpkg-registry/registry-dev.pm
fieldtest:
@echo "++ deploy code directly for field testing"; \
@@ -97,14 +100,16 @@
D=`date '+%Y%m%d%H%M%S'`; \
echo V=$$V D=$$D; \
mkdir -p $(TMP)en2/; \
- cp registry-db.pl registry-ui.pl register.sh $(TMP)en2/; \
+ cp registry-db.pl registry-ui.pl registry.pm register.sh $(TMP)en2/; \
shtool subst \
-e "s/^my \\\$$progvers=\"[^\"]*\";/my
\\\$$progvers=\"$${V}\";/" \
-e "s/^my \\\$$progdate=\"[^\"]*\";/my
\\\$$progdate=\"$${D}\";/" \
-e "s;@l_prefix@;/v/openpkg/sw;g" \
+ -e "s;/registry.pm;/registry-dev.pm;g" \
$(TMP)en2/*
( for i in `builtin cd $(TMP)en2/ && echo *`; do diff -U 3 $$i
$(TMP)en2/$$i; done ) | cvs-diff-colorize
scp $(TMP)en2/register.sh [EMAIL
PROTECTED]:/v/openpkg/sw/libexec/openpkg-tools/register-dev.sh
scp $(TMP)en2/registry-ui.pl [EMAIL
PROTECTED]:/v/openpkg/sw/cgi/openpkg-registry/registry-ui-dev.pl
scp $(TMP)en2/registry-db.pl [EMAIL
PROTECTED]:/v/openpkg/sw/sbin/registry-db-dev
+ scp $(TMP)en2/registry.pm [EMAIL
PROTECTED]:/v/openpkg/sw/libexec/openpkg-registry/registry-dev.pm
@@ .
patch -p0 <<'@@ .'
Index: openpkg-registry/registry-ui.pl
============================================================================
$ cvs diff -u -r1.87 -r1.88 registry-ui.pl
--- openpkg-registry/registry-ui.pl 2 Aug 2006 21:37:14 -0000 1.87
+++ openpkg-registry/registry-ui.pl 2 Aug 2006 22:15:38 -0000 1.88
@@ -37,7 +37,6 @@
use MIME::Base64;
use XML::Simple;
use String::Divert;
-use Clone qw(clone);
# program name, version and date
my $progname="registry-ui.pl";
@@ -53,6 +52,18 @@
my $PREFIX='@l_prefix@';
$PREFIX=$ENV{OPENPKG_PREFIX} if ($ENV{OPENPKG_PREFIX} ne "");
+# registry common code
+my $pm = "registry.pm";
+$pm = "$PREFIX/libexec/openpkg-registry/registry.pm" unless($PREFIX =~
m/[EMAIL PROTECTED]@$/);
+require $pm; import registry;
+
+# handle configuration
+my $defcfgtxt = ®istry::getdefcfgtxt($PREFIX);
+my $defcfg = ®istry::parsecfgtxt($defcfgtxt);
+my $usecfgtxt =
®istry::readcfgtxtfile(®istry::getcfgfilename($PREFIX));
+my $usecfg = ®istry::parsecfgtxt($usecfgtxt);
+my $cfg = ®istry::mergecfg($defcfg, $usecfg);
+
# configure optional debugging
CGI::GuruMeditation::configure(-debug => $cfg->{debug}->{ui});
@@ -62,158 +73,6 @@
$response->{message} = new String::Divert;
$response->{message}->fold("message");
-# default configuration text
-#
-my $defcfgtxt = qq{
- ##
- ## registry-ui.cfg - OpenPKG Registry User Interface Configuration
- ##
-
- # user identification
- #
- identification {
- mode constant; /* constant, naive, basicauth, ase */
- ase {
- server "http://my.example.com/ase";
- };
- default anonymous;
- };
-
- # databases for registry and session
- #
- db {
- registry {
- username registry;
- password registry;
- tablespace registry;
- host 127.0.0.1;
- };
- session {
- dbfile "$PREFIX/var/openpkg-registry/ui/session.db";
- };
- };
-
- # processing more than minimum request
- request {
- package 1;
- };
-
- # canvas integration
- #
- canvas {
- url ""; /* "http://my.example.com/canvas" */
- urlcache;
- mark_head "<!-- CANVAS: HEAD -->";
- mark_body "<!-- CANVAS: BODY -->";
- };
-
- # entry page
- #
- page {
- default "main"; /* "", main, dropxml, login, association, logout */
- main q{
- <h3>Welcome to the OpenPKG Registry main entrance.</h3>
- The registry collects information about instances and
packages.<br>
- <b>NOTICE:</b> Version 0.6 introduced uploading package
information by default.<br>
- Read details in the manpage
<code>openpkg man register</code><br>
- Find more information in the manpage under <code>--data</code>
option and <code>OPENPKG_PREP</code> file.
- <p/>
- Use the following software to get the <code>openpkg
register</code> command.
- <p/>
- <ul>
- <li>OpenPKG CURRENT<br>
- <i>embedded in bootstrap</i></li>
- <li>OpenPKG 2-STABLE<br>
- <i>embedded in bootstrap</i></li>
- <li>OpenPKG 2-STABLE-20060622 SNAPSHOT<br>
- <i>embedded in bootstrap</i></li>
- <li>OpenPKG 2.5 RELEASE<br>
- <i>embedded in bootstrap</i></li>
- <li>OpenPKG 2.4, 2.3, 2.2, 2.1, 2.0 RELEASE<br>
- <a href="http://www.openpkg.org/download/">Download</a>
and install the CURRENT openpkg-registry package.</li>
- <li>OpenPKG 1.x<br>
- <i>unsupported</i></li>
- </ul>
- };
- };
-
- ## status line
- #
- status {
- showuser 1;
- showversion 0;
- showsid 0;
- };
-
- ## debugging
- #
- debug {
- ui 0;
- };
-};
-$defcfgtxt =~ s/^[ ]{4}//mg;
-$defcfgtxt =~ s/^\n//s;
-
-# outside CGI environment just print default config (useful during
installation)
-if ($ENV{GATEWAY_INTERFACE} !~ m/^CGI/) {
- print $defcfgtxt;
- exit 0;
-}
-
-# merges two hashes. First argument is a hash working as accumulator and
the
-# second argument is the hash to be added to it. Either argument can be
-# empty. A typical application is the accumulator being prefilled with
-# defaults and the adder comes with overrides. The function recursively
-# processes nested hashes. Values with dissimilar keys will be merged,
-# missing data on either side will be accumulated and identical keys on
both
-# sides will be overwritten with the added data. Returns a new hash with
-# cloned data. The original accumulator and adder passed in remain
untouched.
-# If the first element in an array is a hash it is assumed a pseudo-hash as
-# described in perlref(1) encountered and hash merging is attempted.
-#
-sub mergehashes ($$) {
- my ($acc, $add) = @_;
- $acc = clone($acc);
- $add = clone($add);
- foreach my $k (sort keys %{$add}) {
- if ( (ref($acc->{$k}) eq "HASH" || (ref($acc->{$k}) eq "ARRAY"
and ref($acc->{$k}[0]) eq "HASH"))
- and (ref($add->{$k}) eq "HASH" || (ref($add->{$k}) eq "ARRAY"
and ref($add->{$k}[0]) eq "HASH"))
- ) {
- $acc->{$k} = &mergehashes($acc->{$k}, $add->{$k});
- }
- else {
- $acc->{$k} = $add->{$k};
- }
- }
- return $acc;
-}
-
-sub parsecfgtxt ($)
-{
- my ($text) = @_;
- my $parse = {};
- my $osspcfg = new OSSP::cfg::simple;
- $osspcfg->parse($text) || die "error parsing config file";
- $parse = $osspcfg->unpack(-index => '.*', -strip => '.*', -flatten => 1)
|| die "error unpacking config file";
- return $parse;
-}
-
-sub readcfgtxt ($)
-{
- my ($cfgfile) = @_;
-
- die "no config file specified" unless (defined $cfgfile);
- my $io = new IO::File "<$cfgfile";
- die "cannot open \"$cfgfile\" for reading ($!)" if(not defined $io);
- my $txt = ''; $txt .= $_ while (<$io>);
- $io->close();
- return $txt;
-}
-
-my $defcfg = &parsecfgtxt($defcfgtxt);
-my $usecfg =
&parsecfgtxt(&readcfgtxt("$PREFIX/etc/openpkg-registry/registry-ui.cfg"));
-my $cfg = &mergehashes($defcfg, $usecfg);
-
# optional OSSP::ase integration
my $ase;
$ase = undef;
@@ .
patch -p0 <<'@@ .'
Index: openpkg-registry/registry.pm
============================================================================
$ cvs diff -u -r0 -r1.1 registry.pm
--- /dev/null 2006-08-03 00:15:39 +0200
+++ registry.pm 2006-08-03 00:15:39 +0200
@@ -0,0 +1,204 @@
[EMAIL PROTECTED]@/bin/perl
+##
+## registry.pm - OpenPKG Registry Common Code Perl Module
+## Copyright (c) 2006-2006 OpenPKG Foundation e.V. <http://openpkg.net/>
+## Copyright (c) 2006-2006 Ralf S. Engelschall <http://engelschall.com/>
+##
+## Permission to use, copy, modify, and distribute this software for
+## any purpose with or without fee is hereby granted, provided that
+## the above copyright notice and this permission notice appear in all
+## copies.
+##
+## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
+## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+## SUCH DAMAGE.
+##
+
+package registry;
+use strict;
+
+use Clone qw(clone);
+
+# program name, version and date
+my $progname="registry.pm";
+my $progvers="0.6.902";
+my $progdate="02-Aug-2006";
+
+# get configuration file name
+#
+sub getcfgfilename ($)
+{
+ my ($prefix) = @_;
+ my $cfgfile = "";
+ $cfgfile = "$prefix/etc/openpkg-registry/registry.cfg" unless ($prefix
=~ m/[EMAIL PROTECTED]@$/);
+ return $cfgfile;
+}
+
+# get default configuration text
+#
+sub getdefcfgtxt ($)
+{
+ my ($prefix) = @_;
+ my $txt = qq{
+ ##
+ ## registry.cfg - OpenPKG Registry Configuration
+ ##
+
+ # user identification
+ #
+ identification {
+ mode constant; /* constant, naive, basicauth, ase */
+ ase {
+ server "http://my.example.com/ase";
+ };
+ default anonymous;
+ };
+
+ # databases for registry and session
+ #
+ db {
+ registry {
+ username registry;
+ password registry;
+ tablespace registry;
+ host 127.0.0.1;
+ };
+ session {
+ dbfile "$prefix/var/openpkg-registry/ui/session.db";
+ };
+ };
+
+ # enable processing of additional data
+ request {
+ package 1;
+ };
+
+ # canvas integration
+ #
+ canvas {
+ url ""; /* "http://my.example.com/canvas" */
+ urlcache;
+ mark_head "<!-- CANVAS: HEAD -->";
+ mark_body "<!-- CANVAS: BODY -->";
+ };
+
+ # entry page
+ #
+ page {
+ default "main"; /* "", main, dropxml, login, association, logout
*/
+ main q{
+ <h3>Welcome to the OpenPKG Registry main entrance.</h3>
+ The registry collects information about instances and
packages.<br>
+ <b>NOTICE:</b> Version 0.6 introduced uploading package
information by default.<br>
+ Read details in the manpage
<code>openpkg man register</code><br>
+ Find more information in the manpage under
<code>--data</code> option and <code>OPENPKG_PREP</code> file.
+ <p/>
+ Use the following software to get the <code>openpkg
register</code> command.
+ <p/>
+ <ul>
+ <li>OpenPKG CURRENT<br>
+ <i>embedded in bootstrap</i></li>
+ <li>OpenPKG 2-STABLE<br>
+ <i>embedded in bootstrap</i></li>
+ <li>OpenPKG 2-STABLE-20060622 SNAPSHOT<br>
+ <i>embedded in bootstrap</i></li>
+ <li>OpenPKG 2.5 RELEASE<br>
+ <i>embedded in bootstrap</i></li>
+ <li>OpenPKG 2.4, 2.3, 2.2, 2.1, 2.0 RELEASE<br>
+ <a
href="http://www.openpkg.org/download/">Download</a> and install the CURRENT
openpkg-registry package.</li>
+ <li>OpenPKG 1.x<br>
+ <i>unsupported</i></li>
+ </ul>
+ };
+ };
+
+ ## status line
+ #
+ status {
+ showuser 1;
+ showversion 0;
+ showsid 0;
+ };
+
+ ## debugging
+ #
+ debug {
+ ui 0;
+ };
+ };
+ $txt =~ s/^\n//s; # remove leading newline
+ $txt =~ s/^[ ]{8}//mg; # clear fixed-width indentation
+ $txt =~ s/ *$//mg; # remove trailing spaces
+ $txt =~ s/^ *\n/\n/sg; # wipe out whitespace-only lines
+ $txt =~ s/\n{2,}/\n\n/sg; # consolidate excessive newlines
+ return $txt;
+}
+
+# read configuration text file
+#
+sub readcfgtxtfile ($)
+{
+ my ($cfgfile) = @_;
+ my $txt = '';
+ if ($cfgfile) {
+ my $io = new IO::File "<$cfgfile";
+ die "cannot open \"$cfgfile\" for reading ($!)" if(not defined $io);
+ $txt .= $_ while (<$io>);
+ $io->close();
+ }
+ return $txt;
+}
+
+# parse configuration text
+#
+sub parsecfgtxt ($)
+{
+ my ($text) = @_;
+ my $parse = {};
+ my $osspcfg = new OSSP::cfg::simple;
+ $osspcfg->parse($text) || die "error parsing config file";
+ $parse = $osspcfg->unpack(-index => '.*', -strip => '.*', -flatten => 1)
|| die "error unpacking config file";
+ return $parse;
+}
+
+# merge configuration
+#
+# merges two hashes. First argument is a hash working as accumulator and
the
+# second argument is the hash to be added to it. Either argument can be
+# empty. A typical application is the accumulator being prefilled with
+# defaults and the adder comes with overrides. The function recursively
+# processes nested hashes. Values with dissimilar keys will be merged,
+# missing data on either side will be accumulated and identical keys on
both
+# sides will be overwritten with the added data. Returns a new hash with
+# cloned data. The original accumulator and adder passed in remain
untouched.
+# If the first element in an array is a hash it is assumed a pseudo-hash as
+# described in perlref(1) encountered and hash merging is attempted.
+#
+sub mergecfg ($$) {
+ my ($acc, $add) = @_;
+ $acc = clone($acc);
+ $add = clone($add);
+ foreach my $k (sort keys %{$add}) {
+ if ( (ref($acc->{$k}) eq "HASH" || (ref($acc->{$k}) eq "ARRAY"
and ref($acc->{$k}[0]) eq "HASH"))
+ and (ref($add->{$k}) eq "HASH" || (ref($add->{$k}) eq "ARRAY"
and ref($add->{$k}[0]) eq "HASH"))
+ ) {
+ $acc->{$k} = &mergecfg($acc->{$k}, $add->{$k});
+ }
+ else {
+ $acc->{$k} = $add->{$k};
+ }
+ }
+ return $acc;
+}
+
+1;
+
@@ .
______________________________________________________________________
The OpenPKG Project www.openpkg.org
CVS Repository Commit List [email protected]