pf-tools/pf-tools: 7 new changesets

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Tue Sep 14 08:42:19 UTC 2010


changeset e9656dfd66b7 in /srv/hg.debian.org/hg/pf-tools/pf-tools
details: http://hg.debian.org/hg/pf-tools/pf-tools?cmd=changeset;node=e9656dfd66b7
summary: Properly test PFTools::Parser

changeset a974073dabe4 in /srv/hg.debian.org/hg/pf-tools/pf-tools
details: http://hg.debian.org/hg/pf-tools/pf-tools?cmd=changeset;node=a974073dabe4
summary: PFTools::Parser passes both perlcritic -3 and make test

changeset c1eac3544cb5 in /srv/hg.debian.org/hg/pf-tools/pf-tools
details: http://hg.debian.org/hg/pf-tools/pf-tools?cmd=changeset;node=c1eac3544cb5
summary: Tests PFTools::Conf::Subst_vars()

changeset 34de5db0b923 in /srv/hg.debian.org/hg/pf-tools/pf-tools
details: http://hg.debian.org/hg/pf-tools/pf-tools?cmd=changeset;node=34de5db0b923
summary: Coding Style update

changeset 944d2d74171a in /srv/hg.debian.org/hg/pf-tools/pf-tools
details: http://hg.debian.org/hg/pf-tools/pf-tools?cmd=changeset;node=944d2d74171a
summary: Tests for PFTools::Conf::Flush2disk_GLOBAL() and Retrieve_GLOBAL()

changeset b2f388328841 in /srv/hg.debian.org/hg/pf-tools/pf-tools
details: http://hg.debian.org/hg/pf-tools/pf-tools?cmd=changeset;node=b2f388328841
summary: With the test script

changeset f0075a070f36 in /srv/hg.debian.org/hg/pf-tools/pf-tools
details: http://hg.debian.org/hg/pf-tools/pf-tools?cmd=changeset;node=f0075a070f36
summary: merge from default

diffstat:

16 files changed, 238 insertions(+), 54 deletions(-)
README.coding.style         |    2 
debian/changelog            |    2 
lib/PFTools/Conf.pm         |   25 +--------
lib/PFTools/Packages.pm     |    2 
lib/PFTools/Packages/DEB.pm |  117 +++++++++++++++++++++++++++++++++++++++++++
lib/PFTools/Parser.pm       |   40 +++++++-------
lib/PFTools/Utils.pm        |    2 
lib/PFTools/VCS.pm          |    2 
sbin/fix_hosts              |    3 -
sbin/mk_dhcp                |    2 
sbin/mk_grubopt             |    3 -
t/10.parse.cfg1             |    1 
t/10.parse.cfg2             |    7 ++
t/10.parse.t                |   26 +++++++++
t/11.vars.t                 |   17 ++++++
t/12.storable.t             |   41 +++++++++++++++

diffs (truncated from 1602 to 300 lines):

diff -r 38223b4691e9 -r f0075a070f36 README.coding.style
--- a/README.coding.style	Fri Sep 10 13:41:35 2010 +0200
+++ b/README.coding.style	Tue Sep 14 10:33:15 2010 +0200
@@ -25,7 +25,12 @@
 
 * Return early on known error cases (no "else" needed).
 
+* "use Carp;" and always croak() on fatal errors in packages.
 
+* Always add tests in the t/ directory _before_ correcting a bug or adding a
+  new feature.
+
+-- 
 The following line is only here to tell Vim my preferences when editing this
 file :
 * vim: set tw=78 sw=2 comments=fb\:*,fb\:-,fb\:+,fb\:=>:
diff -r 38223b4691e9 -r f0075a070f36 debian/changelog
--- a/debian/changelog	Fri Sep 10 13:41:35 2010 +0200
+++ b/debian/changelog	Tue Sep 14 10:33:15 2010 +0200
@@ -21,8 +21,11 @@
   * adding PFTools::VCS::CVS and PFTools::VCS::SVN
   * fix depends on debian/control with libmodule-runtime-perl
   * IO::File on Addmount (see README.coding.style) 
+  * using Module::Runtime in Packages.pm and creating Packages::DEB
+  * correctly handle an undefined pf-tools configuration when checking out 
+  * style for handling options for sbin/*
 
- -- Thomas Parmelan <tom at sitadelle.com>  Fri, 10 Sep 2010 09:16:02 +0200
+ -- Christophe Caillet <quadchris at free.fr>  Mon, 13 Sep 2010 12:00:47 +0200
 
 pf-tools (1.0-1) unstable; urgency=low
 
diff -r 38223b4691e9 -r f0075a070f36 debian/control
--- a/debian/control	Fri Sep 10 13:41:35 2010 +0200
+++ b/debian/control	Tue Sep 14 10:33:15 2010 +0200
@@ -3,7 +3,7 @@
 Priority: optional
 Maintainer: Christophe Caillet <quadchris at free.fr>
 Uploaders: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>, Christophe Caillet <quadchris at free.fr>
-Build-Depends-Indep: perl
+Build-Depends-Indep: perl, libtest-exception-perl, libtest-more-perl
 Standards-Version: 3.0.1
 
 Package: pf-tools
diff -r 38223b4691e9 -r f0075a070f36 lib/PFTools/Conf.pm
--- a/lib/PFTools/Conf.pm	Fri Sep 10 13:41:35 2010 +0200
+++ b/lib/PFTools/Conf.pm	Tue Sep 14 10:33:15 2010 +0200
@@ -1,32 +1,31 @@
 package PFTools::Conf;
-##
-##  $Id$
-##
-##  Copyright (C) 2007-2010 Christophe Caillet <quadchris at free.fr>
-##  Copyright (C) 2005-2007 Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
-##  Copyright (C) 2003-2005 Damien Clermonte <damien at sitadelle.com>
-##  Copyright (C) 2001-2003 Olivier Molteni <olivier at molteni.net>
-##
-##  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, write to the Free Software
-##  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-##
+#
+#  Copyright (C) 2007-2010 Christophe Caillet <quadchris at free.fr>
+#  Copyright (C) 2005-2007 Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
+#  Copyright (C) 2003-2005 Damien Clermonte <damien at sitadelle.com>
+#  Copyright (C) 2001-2003 Olivier Molteni <olivier at molteni.net>
+#
+#  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, write to the Free Software
+#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+#
 
 use strict;
 use warnings;
 
+use base qw( Exporter);
+use Carp;
 use English qw( -no_match_vars );    # Avoids regex performance penalty
-use Exporter;
 use Fcntl ':mode';
 use Storable;
 use Sys::Hostname;
@@ -36,10 +35,8 @@
 use PFTools::Conf::Syntax;
 use PFTools::Logger;
 use PFTools::Net;
-use PFTools::Parser;
+use PFTools::Parser qw( Parser_ini );
 use PFTools::Structqueries;
-
-our @ISA = ('Exporter');
 
 our @EXPORT = qw(
     Subst_vars
@@ -54,11 +51,6 @@
 );
 
 our @EXPORT_OK = qw();
-
-#################################
-### Constants
-
-my $DEBUG = 0;
 
 #############################################################
 ### Default value for configuration with new method
@@ -125,14 +117,15 @@
     },
 };
 
-# Subst_vars
+# Subst_vars( $test, $variables_ref)
+# returns $text after replacing %FOO% by the value of $variables_ref->{'FOO'}
 sub Subst_vars {
-    my ( $str, $hash_subst ) = @_;
+    my ( $text, $variables_ref ) = @_;
 
-    return unless $str and $hash_subst;
+    return unless $text and $variables_ref;
 
-    $str =~ s/%([^\%]+)%/$hash_subst->{$1}/gm;
-    return $str;
+    $text =~ s{ % ([^%]+) % }{$variables_ref->{$1}}xmsg;
+    return $text;
 }
 
 sub Init_PF_CONFIG {
@@ -178,7 +171,11 @@
 
     unless ($host) {
         Abort( $CODE->{'UNDEF_KEY'},
-            "Unable to init substitution hash (undefined hostname).\n" );
+            "Unable to init substitution hash (undefined hostname)." );
+    }
+    unless (ref $hosttype ne 'SCALAR') {
+        Abort ( $CODE->{'INVALID_VALUE'},
+            "Hosttype parameter must be a string" );
     }
     unless ($pf_config) {
         $pf_config = Init_PF_CONFIG();
@@ -538,17 +535,18 @@
 }
 
 sub Flush2disk_GLOBAL {
-    my ( $global_config, $pf_config, $path_global_file ) = @_;
+    my ( $global_config, $pf_config, $flush_file ) = @_;
 
     return unless $global_config and $pf_config;
 
-    my $flush_file = $path_global_file
-        || $pf_config->{'path'}->{'global_struct'};
-    if ( !store( $global_config, $flush_file ) ) {
-        Warn( $CODE->{'STORABLE'},
-            "An error occured when trying to flush global structure to file $flush_file"
-        );
-        return;
+    $flush_file ||= $pf_config->{'path'}->{'global_struct'};
+
+    my $ret = eval { store( $global_config, $flush_file ); };
+    if ($EVAL_ERROR) {
+        croak "ERROR: $EVAL_ERROR";
+    }
+    if ( !$ret ) {
+        croak "ERROR: unable to flush global structure to $flush_file";
     }
 
     return 1;
@@ -559,13 +557,15 @@
 
     return unless $path_global_file;
 
-    if ( !-e $path_global_file ) {
-        Abort( $CODE->{'OPEN'},
-            "Unable to open global configuration storable file $path_global_file: no such file or directory"
-        );
+    my $ret = eval { retrieve($path_global_file); };
+    if ($EVAL_ERROR) {
+        croak "ERROR: $EVAL_ERROR";
+    }
+    if ( !$ret ) {
+        croak "ERROR: unable to retrieve global structure from $path_global_file";
     }
 
-    return retrieve($path_global_file);
+    return $ret;
 }
 
 sub Get_config_for_hostname_on_site {
diff -r 38223b4691e9 -r f0075a070f36 lib/PFTools/Packages.pm
--- a/lib/PFTools/Packages.pm	Fri Sep 10 13:41:35 2010 +0200
+++ b/lib/PFTools/Packages.pm	Tue Sep 14 10:33:15 2010 +0200
@@ -1,8 +1,6 @@
 package PFTools::Packages;
 ##
-##  $Id$
-##
-##  Copyright (C) 2009 Christophe Caillet <quadchris at free.fr>
+##  Copyright (C) 2009-2010 Christophe Caillet <quadchris at free.fr>
 ##
 ##  This program is free software; you can redistribute it and/or
 ##  modify it under the terms of the GNU General Public License
@@ -24,8 +22,10 @@
 
 use English qw( -no_match_vars );    # Avoids regex performance penalty
 use Exporter;
+use Module::Runtime qw( use_module );
 
 use PFTools::Logger;
+use PFTools::Packages::DEB;
 
 our @ISA = ('Exporter');
 
@@ -41,301 +41,111 @@
 
 our @EXPORT_OK = qw();
 
-my $PKG_CMD = {};
-$PKG_CMD->{'deb'}->{'status'} = 'LANG=C LC_ALL=C /usr/bin/dpkg -s';
-$PKG_CMD->{'deb'}->{'update'}
-    = 'LANG=C LC_ALL=C /usr/bin/apt-get -y --force-yes update';
-$PKG_CMD->{'deb'}->{'depends'} = 'LANG=C LC_ALL=C /usr/bin/apt-cache show';
-$PKG_CMD->{'deb'}->{'install'}
-    = 'LANG=C LC_ALL=C /usr/bin/apt-get -y --force-yes install';
-$PKG_CMD->{'deb'}->{'purge'}  = 'LANG=C LC_ALL=C /usr/bin/dpkg --purge';
-$PKG_CMD->{'deb'}->{'policy'} = 'LANG=C LC_ALL=C /usr/bin/apt-cache policy';
-$PKG_CMD->{'deb'}->{'compare'}
-    = 'LANG=C LC_ALL=C /usr/bin/dpkg --compare-versions';
-$PKG_CMD->{'rpm'} = 'TODO';
-
 my $VERBOSE = 0;
 
-sub Get_pkg_status ($$) {
+sub Init_pkgtype_module {
+    my ( $pkg_type, $pf_config ) = @_;
+
+    return unless $pkg_type;
+
+    my $module_name = "PFTools::Packages::".uc( $pkg_type );
+    my $module;
+    eval { $module = use_module($module_name); };
+    $module->import();
+    return 1;
+}
+
+sub Get_pkg_status {
     my ( $pkg_type, $pkg_name ) = @_;
 
+    return unless $pkg_type or $pkg_name;
     my $result = {};
-    if ( !defined $PKG_CMD->{$pkg_type} ) {
-        Warn( $CODE->{'OPEN'}, "Unknown package type " . $pkg_type )
-            if ($VERBOSE);
-        return undef;
+
+    if( ! Init_pkgtype_module ( $pkg_type ) ) {
+        Warn ($CODE->{'OPEN'},
+            "Unable to init package engine" );
+        return;
     }
-    elsif ( $pkg_type eq 'rpm' ) {
-
-        #TODO
-        Warn( $CODE->{'OPEN'}, "Need to implement the RPM handler" )
-            if ($VERBOSE);
-        return undef;
-    }
-    elsif ( $pkg_type eq 'deb' ) {
-        unless (
-            open( PKG,
-                      $PKG_CMD->{$pkg_type}->{'status'} . ' '
-                    . $pkg_name
-                    . ' 2>/dev/null |'
-            )
-            )
-        {
-            Warn( $CODE->{'OPEN'},
-                "Unable to retrieve status for package " . $pkg_name )
-                if ($VERBOSE);
-            return undef;
-        }



More information about the pf-tools-commits mailing list