pf-tools/pf-tools: 3 new changesets

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Mon Sep 13 15:17:38 UTC 2010


changeset 72280e337025 in /srv/hg.debian.org/hg/pf-tools/pf-tools
details: http://hg.debian.org/hg/pf-tools/pf-tools?cmd=changeset;node=72280e337025
summary: correctly handle an undefined pf-tools configuration when checking out

changeset 92328962369e in /srv/hg.debian.org/hg/pf-tools/pf-tools
details: http://hg.debian.org/hg/pf-tools/pf-tools?cmd=changeset;node=92328962369e
summary: Style for handling options

changeset 7eb4c2c22b1a in /srv/hg.debian.org/hg/pf-tools/pf-tools
details: http://hg.debian.org/hg/pf-tools/pf-tools?cmd=changeset;node=7eb4c2c22b1a
summary: Style for handling options in sbin/mk_dhcp

diffstat:

4 files changed, 3 insertions(+), 5 deletions(-)
debian/changelog   |    1 +
lib/PFTools/VCS.pm |    2 ++
sbin/fix_hosts     |    3 ---
sbin/mk_dhcp       |    2 --

diffs (truncated from 351 to 300 lines):

diff -r dc0dd324c5d9 -r 7eb4c2c22b1a debian/changelog
--- a/debian/changelog	Fri Sep 10 23:50:11 2010 +0200
+++ b/debian/changelog	Mon Sep 13 12:02:07 2010 +0200
@@ -22,8 +22,9 @@
   * 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 
 
- -- Christophe Caillet <quadchris at free.fr>  Fri, 10 Sep 2010 23:48:28 +0200
+ -- Christophe Caillet <quadchris at free.fr>  Mon, 13 Sep 2010 11:19:49 +0200
 
 pf-tools (1.0-1) unstable; urgency=low
 
diff -r dc0dd324c5d9 -r 7eb4c2c22b1a lib/PFTools/VCS.pm
--- a/lib/PFTools/VCS.pm	Fri Sep 10 23:50:11 2010 +0200
+++ b/lib/PFTools/VCS.pm	Mon Sep 13 12:02:07 2010 +0200
@@ -36,6 +36,11 @@
 sub VCS_checkout ($$$) {
     my ( $hostname, $pf_config, $options ) = @_;
 
+    unless( $pf_config ) {
+        Warn ( $CODE->{'UNDEF_KEY'},
+            "Unable to access to pf-tools configuration for VCS checkout" );
+        return;
+    }
     my $module_name = 'PFTools::VCS::'.uc($pf_config->{'vcs'}->{'type'});
     my $module;
     
diff -r dc0dd324c5d9 -r 7eb4c2c22b1a sbin/fix_hosts
--- a/sbin/fix_hosts	Fri Sep 10 23:50:11 2010 +0200
+++ b/sbin/fix_hosts	Mon Sep 13 12:02:07 2010 +0200
@@ -1,10 +1,6 @@
 #!/usr/bin/perl
 ##
-##  $Id$
-##
-##  Copyright (C) 2007-2008 Christophe Caillet <quadchris at free.fr>
-##  Copyright (C) 2003-2005 Damien Clermonte <damien at sitadelle.com>
-##  Copyright (C) 2001-2003 Olivier Molteni <olivier at molteni.net>
+##  Copyright (C) 2007-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
@@ -18,7 +14,8 @@
 ##
 ##  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
+##  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+##  USA
 ##
 
 use strict;
@@ -36,28 +33,40 @@
 
 #################################
 # VARS
-my $HELP              = 0;
-my $HOSTNAME          = hostname;
-my $SITE              = '';
-my $GLOBAL_STORE_FILE = '';
-my $PF_CONFIG_FILE    = '';
+
+my @options_specs = (
+    'help',
+    'host|h=s',
+    'site|s=s',
+    'config|c=s',
+    'stote=s',
+    'type|t=s',
+    'input|i=s',
+    'output|o=s',
+);
+
+# Options default values
+my $options = {
+    'help'      => 0,
+    'host'      => hostname,
+    'type'      => 'ipv4',
+    'input'     => '/etc/hosts',
+    'output'    => '/etc/hosts',
+};
+
 my $PF_CONFIG         = {};
-my $IP_TYPE           = 'ipv4';
-my $INPUT_FILE        = '/etc/hosts';
-my $OUTPUT_FILE       = '/etc/hosts';
 my $GLOBAL_STRUCT     = {};
 
 my $program = $0;
 $program =~ s%.*/%%;    # cheap basename
 
-my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
+#my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
 
 ###################################
 # Funtions
 
 sub Do_help {
     print STDERR << "# ENDHELP";
-    $program - version $version
 
 Usage:	$program [options]
 	--help		: print help and exit
@@ -76,72 +85,73 @@
 ### MAIN
 
 GetOptions(
-    'help'       => \$HELP,
-    'host|h=s'   => \$HOSTNAME,
-    'site|s=s'   => \$SITE,
-    'config|c=s' => \$PF_CONFIG_FILE,
-    'store=s'    => \$GLOBAL_STORE_FILE,
-    'type|t=s'   => \$IP_TYPE,
-    'input|i=s'  => \$INPUT_FILE,
-    'output|o=s' => \$OUTPUT_FILE
+    $options,
+    @options_specs
 ) or die "Didn't grok options (see --help).\n";
 
-if ($HELP) {
+if ($options->{'help'}) {
     Do_help();
     exit 0;
 }
 
-( $PF_CONFIG, $GLOBAL_STRUCT )
-    = Init_TOOLS( $HOSTNAME, $PF_CONFIG_FILE, $GLOBAL_STORE_FILE );
+( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS(
+    $options->{'host'},
+    $options->{'config'},
+    $options->{'store'}
+);
 
-if ( !$PF_CONFIG->{'features'}->{$IP_TYPE} ) {
+if ( !$PF_CONFIG->{'features'}->{$options->{'type'}} ) {
     print Dumper $PF_CONFIG;
     Abort( $CODE->{'UNDEF_KEY'},
-        "Aborting because " . $IP_TYPE . " is not activated inot PF-Tools" );
+        "Aborting because $options->{'type'} is not activated in PF-Tools" );
 }
 
-if ( $SITE eq '' ) {
+if ( $options->{'site'} eq '' ) {
     if ( !defined $PF_CONFIG->{'location'}->{'site'} ) {
-        my $site_list = Get_site_from_hostname( $HOSTNAME, $GLOBAL_STRUCT );
+        my $site_list = Get_site_from_hostname(
+            $options->{'host'},
+            $GLOBAL_STRUCT
+        );
         if ( !defined $site_list ) {
             Abort( $CODE->{'UNDEF_KEY'},
-                      "Unable to retrieve site for hostname "
-                    . $HOSTNAME
-                    . " : hostname not defined" );
+                "Unable to retrieve site for undefined hostname "
+                . $options->{'host'}
+            );
         }
         elsif ( scalar @{$site_list} > 1 ) {
             Abort( $CODE->{'DUPLICATE_VALUE'},
-                      "Unable to retrieve site for hostname "
-                    . $HOSTNAME
-                    . " : hostname appeared in multiple sites : "
-                    . join( ",", @{$site_list} ) . ".\n"
-                    . "Please relaunch this command with the right site" );
+                "Unable to retrieve site for hostname "
+                . $options->{'host'}
+                . " : hostname appeared in multiple sites : "
+                . join( ",", @{$site_list} ) . ".\n"
+                . "Please relaunch this command with the right site" );
         }
         else {
-            ($SITE) = @{$site_list};
+            ($options->{'site'}) = @{$site_list};
         }
     }
     else {
-        $SITE = $PF_CONFIG->{'location'}->{'site'};
+        $options->{'site'} = $PF_CONFIG->{'location'}->{'site'};
     }
 }
 
-my $fixed_input
-    = Fix_hosts( $HOSTNAME, $INPUT_FILE, $SITE, $IP_TYPE, $GLOBAL_STRUCT,
+my $fixed_input = Fix_hosts(
+    $options->{'host'}, $options->{'input'},
+    $options->{'site'}, $options->{'type'}, $GLOBAL_STRUCT,
     $PF_CONFIG );
 if ( !defined $fixed_input ) {
     Abort( $CODE->{'EXEC'},
-        "An error occured during fixing file " . $OUTPUT_FILE );
+        "An error occured during fixing file " . $options->{'output'} );
 }
 
-my $output_fh = IO::File->new("> $OUTPUT_FILE")
+my $output_fh = IO::File->new(">$options->{'output'}")
     or Abort( $CODE->{'OPEN'},
-        "Unable to open destination file $OUTPUT_FILE: $OS_ERROR" );
+        "Unable to open destination $options->{'output'} : $OS_ERROR" );
 $output_fh->print ( join '', @{$fixed_input} )
     or Abort ( $CODE->{'OPEN'},
-        "Unable to write to destination file $OUTPUT_FILE: $OS_ERROR" );
+        "Unable to write to destination $options->{'output'} : $OS_ERROR" );
 $output_fh->close()
     or Abort( $CODE->{'OPEN'},
-        "Unable to close destination file $OUTPUT_FILE: $OS_ERROR" );
+        "Unable to close destination $options->{'output'} : $OS_ERROR" );
 
 exit 0;
diff -r dc0dd324c5d9 -r 7eb4c2c22b1a sbin/mk_dhcp
--- a/sbin/mk_dhcp	Fri Sep 10 23:50:11 2010 +0200
+++ b/sbin/mk_dhcp	Mon Sep 13 12:02:07 2010 +0200
@@ -1,6 +1,4 @@
 #!/usr/bin/perl
-##
-##  $Id$
 ##
 ##  Copyright (C) 2007-2008 Christophe Caillet <quadchris at free.fr>
 ##  Copyright (C) 2003-2005 Damien Clermonte <damien at sitadelle.com>
@@ -18,7 +16,8 @@
 ##
 ##  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
+##  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+##  USA
 ##
 
 use strict;
@@ -27,32 +26,46 @@
 use English qw( -no_match_vars );    # Avoids regex performance penalty
 use Getopt::Long qw( :config ignore_case_always bundling );
 use IO::File;
+use Data::Dumper;
 
 use PFTools::Logger;
 use PFTools::Utils;
 
 #####################################
 # Vars
-my $HELP              = 0;
-my $HEADER            = '';
-my $SITE              = '';
-my $GLOBAL_STORE_FILE = '';
-my $PF_CONFIG_FILE    = '';
+
+my @options_specs = (
+    'help',
+    'header|H=s',
+    'site|s=s',
+    'store=s',
+    'config|c=s',
+    'output|o=s',
+);
+
+#########################
+# Default options value
+my $options = {
+    'help'      => 0,
+    'site'      => '',
+    'store'     => '',
+    'config'    => '',
+    'output'    => '-',
+};
+
 my $PF_CONFIG         = {};
-my $OUTPUT_FILE       = '';
 my $GLOBAL_STRUCT     = {};
 
 my $program = $0;
 $program =~ s%.*/%%;    # cheap basename
 
-my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
+#my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
 
 #####################################
 # Functions
 
 sub Do_help {
     print STDERR << "# ENDHELP";
-    $program - version $version
 
 Usage:	$program [options]
 	--help		: print help and exit
@@ -68,48 +81,46 @@
 ############################################
 ### MAIN
 
-GetOptions(
-    'help'       => \$HELP,
-    'H|header=s' => \$HEADER,
-    'site|s=s'   => \$SITE,
-    'config|c=s' => \$PF_CONFIG_FILE,
-    'store=s'    => \$GLOBAL_STORE_FILE,
-    'output|o=s' => \$OUTPUT_FILE
+GetOptions( 
+    $options, @options_specs
 ) or die "Didn't grok options (see --help).\n";



More information about the pf-tools-commits mailing list