pf-tools commit: r766 [ccaillet-guest] - in /branches/next-gen: debian/changelog lib/PFTools/Conf.pm lib/PFTools/Logger.pm lib/PFTools/Net.pm lib/PFTools/Packages.pm lib/PFTools/Parser.pm lib/PFTools/Update.pm

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Fri Jul 2 08:12:44 UTC 2010


Author: ccaillet-guest
Date: Fri Jul  2 08:12:25 2010
New Revision: 766

URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=766
Log:
  ini parser and new syntax
  this function is also used for old syntax files
  - modifying Load_conf as a wrapper for old or new parsing method
  - using PFTools::Parser and PFTools::Logger
* lib/PFTools/Parser.pm
  - introducing this package from splitting Conf.pm function with old parser
  - adding parsing with ini standard parser based on Config::IniFiles
* lib/PFTools/Logger.pm
  - created by the functions extracted from Conf.pm and Update.pm
  - all logging functions are now defined here
* lib/PFTools/Net.pm
  - using new packages Parser.pm et Logger.pm
* lib/PFTools/Packages.pm
  - using new packages Parser.pm et Logger.pm
* lib/PFTools/Update.pm
  - using new packages Parser.pm et Logger.pm

Added:
    branches/next-gen/lib/PFTools/Logger.pm
    branches/next-gen/lib/PFTools/Parser.pm
Modified:
    branches/next-gen/debian/changelog
    branches/next-gen/lib/PFTools/Conf.pm
    branches/next-gen/lib/PFTools/Net.pm
    branches/next-gen/lib/PFTools/Packages.pm
    branches/next-gen/lib/PFTools/Update.pm

Modified: branches/next-gen/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/debian/changelog?rev=766&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Fri Jul  2 08:12:25 2010
@@ -4,15 +4,28 @@
   * doc/hostfile-syntax : adding file describing the new grammar for host
   definition
   * lib/PF-Tools/Conf.pm
-    - renaming Load_conf to __Load_conf_old
     - adding __Load_conf_new for parsing new configuration file with "standard"
-    ini parser
+    ini parser and new syntax
     - adding __Merge_conf_new for merging include part or model part from
     configuration files
     - adding __Chk_section_struct for checking the content of sections (basic checks)
-    - adding Load_conf as a wrapper for old or new parsing method
-
- -- Christophe Caillet <quadchris at free.fr>  Wed, 30 Jun 2010 15:42:51 +0200
+    this function is also used for old syntax files
+    - modifying Load_conf as a wrapper for old or new parsing method
+    - using PFTools::Parser and PFTools::Logger
+  * lib/PFTools/Parser.pm
+    - introducing this package from splitting Conf.pm function with old parser
+    - adding parsing with ini standard parser based on Config::IniFiles
+  * lib/PFTools/Logger.pm
+    - created by the functions extracted from Conf.pm and Update.pm
+    - all logging functions are now defined here
+  * lib/PFTools/Net.pm
+    - using new packages Parser.pm et Logger.pm
+  * lib/PFTools/Packages.pm
+    - using new packages Parser.pm et Logger.pm
+  * lib/PFTools/Update.pm
+    - using new packages Parser.pm et Logger.pm
+
+ -- Christophe Caillet <tof at sitadelle.com>  Fri, 02 Jul 2010 10:01:36 +0200
 
 pf-tools (0.34.0-0WIP) unstable; urgency=low
 

Modified: branches/next-gen/lib/PFTools/Conf.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Conf.pm?rev=766&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Conf.pm (original)
+++ branches/next-gen/lib/PFTools/Conf.pm Fri Jul  2 08:12:25 2010
@@ -26,44 +26,47 @@
 use warnings;
 
 use Exporter;
-use Config::Easy;
-use Hash::Merge;
+use PFTools::Parser;
+use PFTools::Logger;
+use Data::Dumper;
 
 our @ISA = ('Exporter');
 
 our @EXPORT = qw(
-    $ERR_OPEN
-    $ERR_SYNTAX
-    $PFTOOLS_VARS
-    $DEFERREDLOG
-    %SUBST
-
-    Init_SUBST
-    Subst_vars
-    Load_conf
-    deferredlogsystem
-    deferredlogpipe
-    FlushLog
-    DelLog
-    Abort
-    Warn
-    Debug
-    Log
+	%SUBST
+	$PF_STATUS_DIR
+	$PFTOOLSCONF
+	$CVS_WORKING_DIR
+	$CVS_TMP_DIR
+	$CVS_OLD_DIR
+	$GLOBAL_CONF
+	$TEMPLATES
+	$CVS_USER
+	$CVS_RSH
+	$CVS_SERVER
+	$CVS_ROOT
+	$CVS_REPOSITORY
+	$CVS_CONFIG
+	$CVS_COMMAND
+	$CVS_BRANCHE
+
+	Init_SUBST
+	Load_conf
 );
 
-# Prototypes
+##########################
+### Prototypes
+
 sub __Merge_conf_new ($$$);
 sub __Load_conf_new ($$$);
 
-# Error code and error messages
-my $CODE					= {};
-$CODE->{'SECTION_OK'}		= 1;
-$CODE->{'INVALID_CONTEXT'}	= 10;
-$CODE->{'INVALID_SECTNAME'}	= 11;
-$CODE->{'UNDEF_KEY'}		= 20;
+#################################
+### Constants
+
+my $CVS_CHECKOUT    = "/var/lib/cvsguest";
 
 # Syntax definitions
-my $ALLOWED_PARSING_CONTEXT = 'host|model|config|network';
+my $ALLOWED_PARSING_CONTEXT = '(host|model|config|network)';
 my $HOST_CONFIG_REGEX = qr{
 	\A
 	(				# HOSTTYPE
@@ -101,7 +104,7 @@
 	'MANDATORY_KEYS'	=> [ 'vlan','ipv4','slaves' ],
 	'mac'				=> '([0-9a-f]{2}:){5}[0-9a-f]{2}',
 	'vlan'				=> '[a-z][a-z0-9\-]+[a-z0-9]',
-	'ipv4'				=> '([\d]{1,3}\.){3}[\d]{1,3}',
+	'ipv4'				=> '([\d]{1,3})((\.[\d]{1,3}){1,3})?',
 	'ipv6'				=> 'undefined',
 	'iface_opt'			=> 'undefined',
 	'@route'			=> 'undefined',
@@ -110,8 +113,8 @@
 $DEF_SECTIONS->{'deployment'} = {
 	'MANDATORY_KEYS'	=> [ 'arch','mode','distrib' ],
 	'arch'				=> 'i386|amd64',
-	'mode'				=> '(debian|ubuntu)-installer',
-	'distrib'			=> '[a-z]+'
+	'mode'				=> '(debian|ubuntu)(-installer)?',
+	'distrib'			=> '[a-z]+',
 	'dhcp'				=> 'eth\d'
 };
 $DEF_SECTIONS->{'hostgroup'} = {
@@ -128,7 +131,7 @@
 	'kernel'			=> 'undefined',
 	'initrd'			=> 'undefined',
 	'cmdline'			=> 'undefined',
-	'console'			=> 'default|ttyS0,115200n8'
+	'console'			=> '(default|ttyS0,115200n8)'
 };
 $DEF_SECTIONS->{'dns'} = {
 	'MANDATORY_KEYS'	=> [ 'resolver' ],
@@ -159,29 +162,74 @@
 	'MANDATORY_KEYS'	=> [ 'source','fstype','options' ],
 	'depends'			=> 'undefined',
 	'source'			=> 'undefined',
-	'fstype'			=> 'nfs|ext[2-4]|btrfs|cifs',
+	'fstype'			=> '(nfs|ext[2-4]|btrfs|cifs)',
 	'options'			=> 'undefined',
 	'mode'				=> '0?[0-7]{3}'
 };
 
 our @EXPORT_OK = qw();
 
-# Error code
-our $ERR_OPEN   = 1;
-our $ERR_SYNTAX = 2;
 
 my $DEBUG	= 0 ;
 
-# Vars needed by pf-launch
-my $sortie;
-my $tmpfile = "/tmp/update-config.log";
-
-# Table de substitution globale
+# Global hash for substitution
 our %SUBST;
 
 my $FAKEHOSTNAME;
 my $FAKEDOMAINNAME;
 our $DEFERREDLOG = 0;
+
+#################################################
+### Default value for PF-TOOLS configuration
+our $PFTOOLSCONF	= "/etc/pf-tools.conf";
+
+our $PF_STATUS_DIR	= "/var/lib/pftools";
+
+our $CVS_USER		= "cvsguest";
+our $CVS_RSH		= "/usr/local/sbin/cvs_rsh";
+our $CVS_SERVER		= "cvs.private";
+our $CVS_ROOT		= "/var/lib/cvs";
+our $CVS_REPOSITORY	= $CVS_ROOT . "/repository";
+our $CVS_CONFIG		= "config";
+our $CVS_COMMAND	= "";
+our $CVS_BRANCHE	= "";
+
+if ( -r $PFTOOLSCONF ) {
+    my $newuid;
+    my $newgid;
+    my $dev;
+    my $ino;
+    my $mode;
+    my $nlink;
+    my $uid;
+    my $gid;
+    my $rdev;
+    my $size;
+    my $atime;
+    my $mtime;
+    my $ctime;
+    my $blksize;
+    my $blocks;
+
+    (   $dev,  $ino,   $mode,  $nlink, $uid,     $gid, $rdev,
+	$size, $atime, $mtime, $ctime, $blksize, $blocks
+    ) = lstat($PFTOOLSCONF);
+
+    if ( $uid == 0 && $gid == 0 && S_IMODE($mode) == 0600 && S_ISREG($mode) )
+    {
+
+	my $result;
+	my $return;
+	unless ( $result = do $PFTOOLSCONF ) {
+	    warn "couldn't parse $PFTOOLSCONF: $@" if $@;
+	    warn "couldn't do $PFTOOLSCONF: $!" unless defined $return;
+	    warn "couldn't run $PFTOOLSCONF"    unless $return;
+	}
+    }
+    else {
+		print STDERR "Ignoring weak config (check owner/group/mode)\n";
+    }
+}
 
 sub Init_SUBST ($;$$) {
 	my ( $ref_subst, $fakehost, $fakedomain ) = @_ ;
@@ -226,7 +274,7 @@
 	}xms;
 
 	unless ($ref_subst->{'HOSTNAME'} =~ m/$host_regex/) {
-	    Abort( $ERR_OPEN, "Init_SUBST failed: invalid hostname $ref_subst->{'HOSTNAME'}" );
+	    Abort( $CODE->{'OPEN'}, "Init_SUBST failed: invalid hostname $ref_subst->{'HOSTNAME'}" );
 	}
 	$ref_subst->{'HOSTTYPE'}	= $1 ;
 	$ref_subst->{'HOSTDIGITS'}	= $5 ;
@@ -244,477 +292,28 @@
 
 Init_SUBST ( \%SUBST ) ;
 
-# PFTools variables define in configuration files
-our $PFTOOLS_VARS = {} ;
-$PFTOOLS_VARS->{'VMWARE'}	= 0 ;
-$PFTOOLS_VARS->{'UML'}		= 0 ;
-
-
-# Subst_vars
-sub Subst_vars {
-    my ($str) = @_;
-
-#     while ( $str =~ s/%([^%\s]*)%/$SUBST{"$1"}/ ) { }
-    foreach my $elt ( split ( '%', $str ) ) {
-        next if ( $elt eq '' );
-        if ( defined $SUBST{$elt} ) {
-            $str =~ s/%$elt%/$SUBST{$elt}/;
-        }
-    }
-    return ($str);
-}
-
-my $deferbuffer;
-my $deferredlogbuffer    = '';
-my @rotatecursortemplate = ( '-', '\\', '|', '/' );
-my $rotatecursorcount    = 0;
-
-sub RotateCursor {
-    print STDERR $rotatecursortemplate[$rotatecursorcount], "\r";
-    $rotatecursorcount
-	= ( $rotatecursorcount + 1 ) % ( $#rotatecursortemplate + 1 );
-}
-
-sub DeferOutput {
-
-    local *REAL_STDOUT;
-    local *REAL_STDERR;
-
-    open( REAL_STDOUT, ">&STDOUT" );
-    open( REAL_STDERR, ">&STDERR" );
-
-    close STDOUT;
-    close STDERR;
-
-    $sortie->{'_stdout'} = *REAL_STDOUT;
-    $sortie->{'_stderr'} = *REAL_STDERR;
-
-    open( STDOUT, "+>$tmpfile" ) or warn "Can't open tmp file for stdout";
-    open( STDERR, ">&STDOUT" )   or warn "Can't open tmp file for stderr";
-    unlink $tmpfile;
-
-    select STDERR;
-    $| = 1;
-    select STDOUT;
-    $| = 1;
-
-}
-
-sub UndeferOutput {
-
-    seek( STDOUT, 0, 0 );
-    local $/;
-    $deferbuffer = <STDOUT>;
-
-    if ( defined( $sortie->{'_stdout'} ) ) {
-	local *REAL_STDOUT;
-	*REAL_STDOUT = $sortie->{'_stdout'};
-	open( STDOUT, ">&REAL_STDOUT" ) or warn "Can't restore STDOUT: $!
-    +";
-	undef( $sortie->{'_stdout'} );
-    }
-    if ( defined( $sortie->{'_stderr'} ) ) {
-	local *REAL_STDERR;
-	*REAL_STDERR = $sortie->{'_stderr'};
-	open( STDERR, ">&REAL_STDERR" ) or warn "Can't restore STDERR: $!
-    +";
-	undef( $sortie->{'_stderr'} );
-    }
-    select STDERR;
-    $| = 1;
-    select STDOUT;
-    $| = 1;
-
-}
-
-# Returns undef on error
-sub deferredlogpipe {
-    my $ret = '';
-
-    DeferOutput() if $DEFERREDLOG;
-
-    unless ( open DEFERREDLOGPIPE, '-|', @_ ) {
-	Warn( $ERR_OPEN, "Unable to open pipe @_: $!" );
-	return;
-    }
-
-    while (<DEFERREDLOGPIPE>) {
-	chomp;
-	$ret .= $_;
-    }
-    close DEFERREDLOGPIPE;
-
-    UndeferOutput() if $DEFERREDLOG;
-
-    if ($deferbuffer) {
-	$deferredlogbuffer .= $deferbuffer;
-	$deferbuffer = undef;
-    }
-
-    RotateCursor() if $DEFERREDLOG;
-
-    return $ret;
-}
-
-sub deferredlogsystem {
-    my $ret;
-
-    DeferOutput() if ($DEFERREDLOG);
-
-    $ret = system(@_);
-
-    UndeferOutput() if ($DEFERREDLOG);
-
-    if ( defined $deferbuffer && $deferbuffer ne '' ) {
-	$deferredlogbuffer .= $deferbuffer;
-	$deferbuffer = undef;
-    }
-
-    RotateCursor() if ($DEFERREDLOG);
-
-    return $ret;
-}
-
-sub DelLog {
-    $deferredlogbuffer = '';
-}
-
-sub FlushLog {
-    print STDERR $deferredlogbuffer;
-    DelLog();
-}
-
-# Log
-sub Log {
-    my @words = split( /\s+/, join( '', @_ ) );
-    my $col   = 0;
-    my $sup   = "";
-    my $word;
-
-    foreach $word (@words) {
-	my $len = length($word);
-	if ( defined($word) && $len > 0 ) {
-	    if ( $col != 0 ) {
-		$sup = " ";
-	    }
-
-	    if ( $word eq "\n" || $word eq "\r" ) {
-		$deferredlogbuffer .= "\n";
-		$col = 0;
-	    }
-	    elsif ( $col + $len + length($sup) < 80 ) {
-		$deferredlogbuffer .= $sup . $word;
-		$col = $col + length($sup) + $len;
-	    }
-	    else {
-		$deferredlogbuffer .= "\n... " . $word;
-		$col = 4 + $len;
-	    }
-	}
-    }
-
-    $deferredlogbuffer .= "\n";
-
-    if ( !$DEFERREDLOG ) {
-	FlushLog();
-    }
-    else {
-	RotateCursor();
-    }
-}
-
-# Debug
-sub Debug ($) {
-    my (@msg) = @_;
-
-    # FIXME à faire une bonne fois pour toutes !
-    my $basename = ( split( '/', $0 ) )[-1];
-    Log( $basename . ": DEBUG: ", @msg );
-}
-
-# Warn
-sub Warn {
-    my ( $err, @msg ) = @_;
-    my $basename;
-
-    $basename = ( split( '/', $0 ) )[-1];
-
-    Log( $basename . ": WARN: ", @msg );
-}
-
-# Abort
-sub Abort {
-    my ( $err, @msg ) = @_;
-    my $basename;
-
-    $basename = ( split( '/', $0 ) )[-1];
-
-    Log( $basename . ": ERR: ", @msg );
-    FlushLog();
-    exit $err;
-}
-
-# Load_conf
-sub __Load_conf_old {
-    my ( $fic_conf, $substdestvars ) = @_;
-
-    my $CONF     = {};
-    my $LOCATION	= {} ;
-    my $current  = ']';
-    my @FIC_CONF = ();
-    my @ALL_CONF = ();
-    my @FH	= () ;
-    my @line     = ();
-    my @cond     = ();
-
-    unshift @FIC_CONF, $fic_conf;
-    unshift @ALL_CONF, $fic_conf;
-    unshift @line,     0;
-    print "Opening $FIC_CONF[0]\n" if ( $DEBUG );
-    open( $FH[0], $FIC_CONF[0] )
-	|| Abort( $ERR_OPEN, "Impossible d'ouvrir " . $FIC_CONF[0] );
-    print "Filehandles --> @FH\n"  if ( $DEBUG );
-    while ( $#FH >= 0 ) {
-	my $fh = $FH[0];    # Perl gruik, ne pas simplifier!!!
-    LOADCONFLINE: while (<$fh>) {
-# 		print "Using fh --> $fh\n" ;
-	    # Compter les lignes
-	    $line[0]++;
-
-	    # Eliminer les commentaires et les espaces inutiles
-	    chomp;
-	    s/^\s*//;
-	    s/\s*$//;
-	    s/\s*#.*$//;
-
-	    # Ne pas traiter les lignes vides
-	    next if (/^$/);
-
-	    # Traitement des directives IF (0 param)
-	    if (/^\@([^\s]+)$/) {
-		if ( $1 eq "else" ) {
-		    if ( $#cond < 0 ) {
-			Abort ( $ERR_SYNTAX,
-			          $FIC_CONF[0] . ":"
-				. $line[0]
-				. ": else sans if" );
-		    }
-		    $cond[0] = ( $#cond > 0 && !$cond[1] ) ? 0 : !$cond[0];
-		    next;
-		}
-		elsif ( $1 eq "endif" ) {
-		    if ( $#cond < 0 ) {
-			Abort( $ERR_SYNTAX,
-			          $FIC_CONF[0] . ":"
-				. $line[0]
-				. ": endif sans if" );
-		    }
-		    shift @cond;
-		    next;
-		}
-	    }
-
-	    # Traitement des directives IF (1 param)
-	    if (/^\@([^\s]+)\s+([^\s]+)$/) {
-		if ( $1 eq "ifdef" ) {
-		    if ( defined $PFTOOLS_VARS->{$2} ) {
-			unshift @cond, ( $#cond > 0 && !$cond[1] ) ? 0 : 1;
-		    }
-		    else {
-			unshift @cond, 0;
-		    }
-		    next;
-		}
-		elsif ( $1 eq "ifndef" ) {
-		    if ( not defined $PFTOOLS_VARS->{$2} ) {
-			unshift @cond, 0;
-		    }
-		    else {
-			unshift @cond, ( $#cond > 0 && !$cond[1] ) ? 0 : 1;
-		    }
-		    next;
-		}
-		elsif ( $1 eq "if" ) {
-		    if ( defined $PFTOOLS_VARS->{$2} && $PFTOOLS_VARS->{$2} ) {
-			unshift @cond, ( $#cond > 0 && !$cond[1] ) ? 0 : 1;
-		    }
-		    else {
-			unshift @cond, 0;
-		    }
-		    next;
-		}
-		elsif ( $1 eq "ifnot" ) {
-		    if ( defined $PFTOOLS_VARS->{$2} && ! $PFTOOLS_VARS->{$2} ) {
-			unshift @cond, 0;
-		    }
-		    else {
-			unshift @cond, ( $#cond > 0 && !$cond[1] ) ? 0 : 1;
-		    }
-		    next;
-		}
-	    }
-
-	    # Seulement les directives IF si condition fausse
-	    next if ( $#cond >= 0 && !$cond[0] );
-
-	    if (/^\@([^\s]+)\s+([^\s]+)$/) {
-		if ( $1 eq "include" ) {
-		    my $fic_conf = $2;
-		    my $oldficconf;
-
-		    if ( $fic_conf =~ m|/| ) {
-			Abort( $ERR_OPEN,
-			          $FIC_CONF[1] . ":"
-				. $line[1]
-				. ": Include avec chemin interdit" );
-		    }
-
-		    if ( $FIC_CONF[0] =~ m|^(.*)/[^/]*$| ) {
-			$fic_conf = $1 . '/include-' . $fic_conf;
-		    }
-		    else {
-			$fic_conf = "include-" . $fic_conf;
-		    }
-
-		    foreach $oldficconf (@ALL_CONF) {
-			if ( $fic_conf eq $oldficconf ) {
-			    Warn( $ERR_OPEN,
-				      $FIC_CONF[0] . ":"
-				    . $line[0] . ": "
-				    . $fic_conf
-				    . " deja inclus ligne "
-				    . $LOCATION->{'include'}->{$fic_conf}->{'line'}
-				    . " dans "
-				    . $LOCATION->{'include'}->{$fic_conf}->{'source'} );
-			    next LOADCONFLINE;
-			}
-		    }
-			$LOCATION->{'include'}->{$fic_conf}->{'line'} = $line[0] ;
-			$LOCATION->{'include'}->{$fic_conf}->{'source'} = $FIC_CONF[0] ;
-		    unshift @FIC_CONF, $fic_conf;
-		    unshift @ALL_CONF, $fic_conf;
-		    unshift @line,     0;
-		    print "Opening $FIC_CONF[0]\n"  if ( $DEBUG );
-		    my $newfh ;
-		    open( $newfh, $FIC_CONF[0] )
-			|| Abort( $ERR_OPEN,
-			      $FIC_CONF[1] . ":"
-			    . $line[1]
-			    . ": Impossible d'inclure "
-			    . $FIC_CONF[0] );
-		    ;    # Perl gruik, ne pas simplifier!!!
-		    print "File list after including $FIC_CONF[0] ".join ( " ", @ALL_CONF )."\n"  if ( $DEBUG );
-		    unshift @FH, $newfh ;
-		    $fh = $newfh ;
-		    print "Filehandles list after inclusion --> @FH\n" if ( $DEBUG );
-		}
-		elsif ( $1 eq "define" ) {
-		    if ( defined( $PFTOOLS_VARS->{$2} ) ) {
-			Warn( $ERR_OPEN,
-			          $FIC_CONF[0] . ":"
-				. $line[0] . ": "
-				. $2
-				. " deja defini" );
-		    }
-		    else {
-			$PFTOOLS_VARS->{$2} = 1;
-		    }
-		}
-		elsif ( $1 eq "undef" ) {
-		    if ( not defined( $PFTOOLS_VARS->{$2} ) ) {
-			Warn( $ERR_OPEN,
-			          $FIC_CONF[0] . ":"
-				. $line[0] . ": "
-				. $2
-				. " deja non defini" );
-		    }
-		    else {
-			undef $PFTOOLS_VARS->{$2};
-		    }
-		}
-		else {
-		    Abort( $ERR_SYNTAX,
-			      $FIC_CONF[0] . ":"
-			    . $line[0]
-			    . ": Directive "
-			    . $1
-			    . " inconnue" );
-		}
-		next;
-	    }
-
-	    # Detection des sections
-	    if (/^\[([^\]]+)\]$/) {
-		if ( defined $substdestvars && $substdestvars ) {
-		    $current = Subst_vars($1);
-		}
-		else {
-		    $current = $1;
-		}
-		if ( defined( $CONF->{$current} ) ) {
-		    Abort( $ERR_SYNTAX,
-			      $FIC_CONF[0] . ":"
-			    . $line[0] . ": ["
-			    . $current
-			    . "] dupliquee (precedente a "
-			    . $LOCATION->{$current}->{_location}
-			    . ")" );
-		}
-		else {
-		    $CONF->{$current} = {};
-		    $LOCATION->{$current}->{_location}
-			= $FIC_CONF[0] . ":" . $line[0];
-		}
-		next;
-	    }
-
-	    # Traitement des variables
-	    if (/^([^\s]+)\s*=\s*(.+)$/) {
-	    	my ( $var, $val ) = ( $1, $2 ) ;
-		if ( defined( $CONF->{$current}->{$var} ) ) {
-		    Abort( $ERR_SYNTAX,
-			      $FIC_CONF[0] . ":"
-			    . $line[0] . ": "
-			    . $var
-			    . " dupliquee (precedente a "
-			    . $LOCATION->{$current}->{$var}->{_location}
-			    . ")" );
-		}
-		else {
-
-		    if ( Add_var( $CONF->{$current}, $var, $val ) == $ERR_SYNTAX )
-		    {
-			Abort( $ERR_SYNTAX,
-			          $FIC_CONF[0] . ":"
-				. $line[0] . ": "
-				. $var
-				. " dupliquee (precedente a "
-				. $LOCATION->{$current}->{$var}->{_location}
-				. ")" );
-		    }
-		    $LOCATION->{$current}->{$var}->{_location}
-			= $FIC_CONF[0] . ":" . $line[0];
-		}
-	    }
-	    else {
-		Abort( $ERR_SYNTAX,
-		    $FIC_CONF[0] . ":" . $line[0] . ": Erreur de syntaxe" );
-	    }
-	}
-	close( $FH[0] ) ;
-	print "Closing $FIC_CONF[0] -- $FH[0]\n"  if ( $DEBUG );
-	shift @FH;
-	print "Filehandles after closing --> @FH\n"  if ( $DEBUG );
-	shift @line;
-	shift @FIC_CONF;
-    }
-
-    # Conditions non fermees
-    if ( $#cond >= 0 ) {
-	Abort( $ERR_SYNTAX, "EOC: endif manquant" );
-    }
-
-    return ($CONF);
+my $HOSTNAME			= $SUBST{'HOSTNAME'};
+our $CVS_WORKING_DIR	= $CVS_CHECKOUT . "/" . $HOSTNAME;
+our $CVS_TMP_DIR		= $CVS_CHECKOUT . "/" . $HOSTNAME . "/tmp";
+our $CVS_OLD_DIR		= $CVS_CHECKOUT . "/" . $HOSTNAME . "/old";
+our $GLOBAL_CONF		= $CVS_WORKING_DIR . "/" . $CVS_CONFIG . "/GLOBAL";
+our $TEMPLATES			= $CVS_WORKING_DIR . "/" . $CVS_CONFIG . "/TEMPLATES";
+
+sub Get_source ($;$) {
+    my ($source, $hash_subst) = @_;
+	my $hosttype;
+	
+	if ( ! defined $hash_subst ) {
+		$hosttype = $SUBST{'HOSTTYPE'};
+	}
+	else {
+		$hosttype = $hash_subst->{'HOSTTYPE'};
+	}
+	$source =~ s!^HOST:!$CVS_WORKING_DIR/$CVS_CONFIG/$hash_subst->{'HOSTTYPE'}!;
+	$source =~ s!^CONFIG:!$CVS_WORKING_DIR/$CVS_CONFIG/!;
+	$source =~ s!^CVS:!$CVS_WORKING_DIR/!;
+	$source =~ s!^GLOBAL:!$GLOBAL_CONF/!;
+	return $source;
 }
 
 sub __Chk_section_struct ($$$$) {
@@ -768,13 +367,13 @@
 			|| ! defined $sect_tmp->{$key} );
 		if ( $context ne 'config' && $sect_tmp->{$key}->{'VALUE'} !~ /^$definition->{$key}$/ ) {
 			return ( $CODE->{'INVALID_VALUE'}, 
-			"Invalid value ".$sect_tmp->{$key}->{'VALUE'}." for key ".$sect_tmp->{$key}->{'ORIG_NAME'}
-			." on section ".$sect_name." in context ".$context );
+			"Value ".$sect_tmp->{$key}->{'VALUE'}." for key ".$sect_tmp->{$key}->{'ORIG_NAME'}
+			." on section ".$sect_name." doesn't match ".$definition->{$key} );
 		}
 		elsif ( $context eq 'config' && $sect_tmp->{$key} !~ /^$definition->{$key}$/ ) {
 			return ( $CODE->{'INVALID_VALUE'}, 
 			"Invalid value ".$sect_tmp->{$key}." for key ".$key
-			." on section ".$sect_name." in context ".$context );
+			." on section ".$sect_name." doesn't match ".$definition->{$key} );
 		}
 	}
 	return ( $CODE->{'SECTION_OK'}, "" ) ;
@@ -786,7 +385,27 @@
 	my $global_parsed = {};
 
 	if ( $context ne 'config' ) {
-		
+		if ( defined $hash_to_merge->{'hostgroup'}->{'__model'} ) {
+			$global_parsed = $hash_to_merge->{'hostgroup'}->{'__model'};
+		}
+		foreach my $section ( @{$hash_to_merge->{'__sections_order'}} ) {
+			if ( defined $global_parsed->{$section} ) {
+				foreach my $key ( keys %{$hash_to_merge->{$section}} ) {
+					# Adding key if not defined into model else overriding it
+					if ( $key =~ /^\@/ ) {
+						push ( @{$global_parsed->{$section}->{$key}}, @{$hash_to_merge->{$section}->{$key}} );
+					}
+					else {
+						$global_parsed->{$section}->{$key} = $hash_to_merge->{$section}->{$key};
+					}
+				}
+			}
+			else {
+				push ( @{$global_parsed->{'__sections_order'}}, $section );
+				$global_parsed->{$section} = $hash_to_merge->{$section};
+			}
+		}
+		undef $global_parsed->{'hostgroup'}->{'__model'};
 	}
 	else {
 		foreach my $section ( @{$hash_to_merge->{'__sections_order'}} ) {
@@ -823,9 +442,9 @@
 	my ( $file, $hash_subst, $context ) = @_;
 	my $sect_type;
 
-	my $parsed = load_config ( $file, 'ini', [ 'ordered' ] );
+	my $parsed = Parser_ini ( $file );
 	if ( ! defined $parsed ) {
-		Abort ( $ERR_SYNTAX, "Parsing error for file ".$file );
+		Abort ( $CODE->{'PARSING'}, "Parsing error for file ".$file );
 	}
 
 	# Basic checks
@@ -834,11 +453,14 @@
 		if ( $context ne 'config' ) {
 			$section =~ /^([^:]+)(::.+)?$/;
 			$sect_type = $1;
+			if ( $sect_type eq 'hostgroup' && defined $parsed->{$section}->{'model'} ) {
+				my $model_parsed = __Load_conf_new ( $parsed->{$section}->{'model'}, $hash_subst, 'model' );
+				$parsed->{$section}->{'__model'} = $model_parsed;
+			}
 		}
 		else {
 			if ( ! defined $parsed->{$section}->{'action'} ) {
-				Abort ( $CODE->{'UNDEF_KEY'},
-					"Key action on section ".$section." from file ".$file." MUST BE defined" );
+				Abort ( $CODE->{'UNDEF_KEY'}, "Key action on section ".$section." from file ".$file." MUST BE defined" ); 
 			}
 			$sect_type = $parsed->{$section}->{'action'};
 			if ( $sect_type eq 'include' ) {
@@ -847,61 +469,51 @@
 				$parsed->{$section}->{'__content'} = $inc_parsed;
 			}
 		}
+	}
+	# Merging if needed
+	return __Merge_conf_new ( $parsed, $hash_subst, $context );
+}
+
+sub Load_conf ($$$;$) {
+	my ( $file, $hash_subst, $context, $syntax ) = @_;
+	my $sect_type;
+	my $parsed;
+
+	if ( $syntax eq 'nx' ) {
+		$parsed = __Load_conf_new ( $file, $hash_subst, $context );
+	}
+	else {
+		$parsed = Parser_pftools ( $file, $hash_subst );
+	}
+	if ( ! defined $parsed ) {
+		Abort ( $CODE->{'SYNTAX'}, "Parsing error for file ".$file );
+	}
+
+	print Dumper $CODE;
+	# Basic checks
+	foreach my $section ( keys %{$parsed} ) {
+		next if ( $section eq '__sections_order' );
+		if ( $context ne 'config' ) {
+			$section =~ /^([^:]+)(::.+)?$/;
+			$sect_type = $1;
+		}
+		else {
+			if ( ! defined $parsed->{$section}->{'action'} ) {
+				Abort ( $CODE->{'UNDEF_KEY'},
+					"Key action on section ".$section." from file ".$file." MUST BE defined" );
+			}
+			$sect_type = $parsed->{$section}->{'action'};
+		}
 		if ( $sect_type ne 'include' ) {
-			my ( $code, $msg ) = __Chk_section_struct ( $section, $sect_type, $parsed->{$section}, $context ) if ( $sect_type ne 'include' );
+			my ( $code, $msg ) = __Chk_section_struct ( $section, $sect_type, $parsed->{$section}, $context );
+			print "$section, $sect_type, HASH $section, $context --> $msg\n" if ( ! defined $code );
 			if ( $code > 1 ) {
 				Warn ( $code, "Errors occur during parsing model from file ". $file );
 				Abort ( $code, $msg );
 			}
 		}
 	}
-	# Merging if needed
-	return __Merge_conf_new ( $parsed, $hash_subst, $context ) ;
-}
-
-sub Load_conf ($$;$) {
-	my ( $fic_conf, $substdestvars, $type_conf ) = @_;
-
-	if ( defined $type_conf ) {
-		if ( $type_conf =~ /^$ALLOWED_PARSING_CONTEXT$/ ) {
-			# Using new parser with basic checks included
-			__Load_conf_new ( $fic_conf, $substdestvars, $type_conf );
-		}
-		else {
-			Abort ( $CODE->{'INVALID_CONTEXT'}, "Invalid parsing context ".$type_conf );
-		}
-	}
-	else {
-		# Assuming old parser is in use
-		__Load_conf_old ( $fic_conf, $substdestvars );
-	}
-}
-
-# Add_var
-sub Add_var {
-    my ( $V, $var, $val ) = @_;
-
-    if ( $var =~ /^((\\\.|[^.])*[^\\])\./ ) {
-	my $esc1  = $1;
-	my $quote = $';
-	$esc1 =~ s/\\\././g;
-	if ( !defined( $V->{$esc1} ) ) {
-	    $V->{$esc1} = {};
-	}
-	if ( !ref( $V->{$esc1} ) ) {
-	    return ($ERR_SYNTAX);
-	}
-	Add_var( $V->{$esc1}, $quote, $val );
-    }
-    else {
-	$var =~ s/\\\././g;
-	if ( defined( $V->{$var} ) ) {
-#		print "Syntax error\n" ;
-	    return ($ERR_SYNTAX);
-	}
-	$V->{$var} = $val;
-	return (0);
-    }
+	return $parsed;
 }
 
 # Print_conf
@@ -935,4 +547,3 @@
 #Print_conf (Load_conf ("/config/config/network")) ;
 
 1;
-

Added: branches/next-gen/lib/PFTools/Logger.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Logger.pm?rev=766&op=file
==============================================================================
--- branches/next-gen/lib/PFTools/Logger.pm (added)
+++ branches/next-gen/lib/PFTools/Logger.pm Fri Jul  2 08:12:25 2010
@@ -1,0 +1,212 @@
+package PFTools::Logger;
+##
+##  $Id: Conf.pm 765 2010-06-30 13:51:27Z ccaillet-guest $
+##
+##  Copyright (C) 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
+##  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 Exporter;
+
+our @ISA = ('Exporter');
+
+our @EXPORT = qw(
+	$DEFERREDLOG
+	$CODE
+
+	deferredlogsystem
+	deferredlogpipe
+
+	FlushLog
+	DelLog
+	Abort
+	Warn
+	Debug
+	Log
+
+);
+
+our @EXPORT_OK = qw();
+
+
+# Error code
+our $ERR_OPEN   = 1;
+our $ERR_SYNTAX = 2;
+# Error code and error messages
+our $CODE					= {};
+$CODE->{'WARNING'}			= 0;
+$CODE->{'SECTION_OK'}		= 1;
+$CODE->{'OPEN'}				= 2;
+$CODE->{'SYNTAX'}			= 3;
+
+$CODE->{'INVALID_CONTEXT'}	= 10;
+$CODE->{'INVALID_SECTNAME'}	= 11;
+$CODE->{'INVALID_VALUE'}	= 12;
+$CODE->{'UNDEF_KEY'}		= 20;
+
+our $DEFERREDLOG	= 0;
+
+# Vars needed by pf-launch
+my $sortie;
+my $tmpfile = "/tmp/update-config.log";
+
+my $deferbuffer;
+my $deferredlogbuffer    = '';
+my @rotatecursortemplate = ( '-', '\\', '|', '/' );
+my $rotatecursorcount    = 0;
+
+sub RotateCursor {
+    print STDERR $rotatecursortemplate[$rotatecursorcount], "\r";
+    $rotatecursorcount
+	= ( $rotatecursorcount + 1 ) % ( $#rotatecursortemplate + 1 );
+}
+
+sub DeferOutput {
+
+    local *REAL_STDOUT;
+    local *REAL_STDERR;
+
+    open( REAL_STDOUT, ">&STDOUT" );
+    open( REAL_STDERR, ">&STDERR" );
+
+    close STDOUT;
+    close STDERR;
+
+    $sortie->{'_stdout'} = *REAL_STDOUT;
+    $sortie->{'_stderr'} = *REAL_STDERR;
+
+    open( STDOUT, "+>$tmpfile" ) or warn "Can't open tmp file for stdout";
+    open( STDERR, ">&STDOUT" )   or warn "Can't open tmp file for stderr";
+    unlink $tmpfile;
+
+    select STDERR;
+    $| = 1;
+    select STDOUT;
+    $| = 1;
+
+}
+
+sub UndeferOutput {
+
+    seek( STDOUT, 0, 0 );
+    local $/;
+    $deferbuffer = <STDOUT>;
+
+    if ( defined( $sortie->{'_stdout'} ) ) {
+	local *REAL_STDOUT;
+	*REAL_STDOUT = $sortie->{'_stdout'};
+	open( STDOUT, ">&REAL_STDOUT" ) or warn "Can't restore STDOUT: $!
+    +";
+	undef( $sortie->{'_stdout'} );
+    }
+    if ( defined( $sortie->{'_stderr'} ) ) {
+	local *REAL_STDERR;
+	*REAL_STDERR = $sortie->{'_stderr'};
+	open( STDERR, ">&REAL_STDERR" ) or warn "Can't restore STDERR: $!
+    +";
+	undef( $sortie->{'_stderr'} );
+    }
+    select STDERR;
+    $| = 1;
+    select STDOUT;
+    $| = 1;
+
+}
+
+sub DelLog {
+    $deferredlogbuffer = '';
+}
+
+sub FlushLog {
+    print STDERR $deferredlogbuffer;
+    DelLog();
+}
+
+
+# Log
+sub Log {
+    my @words = split( /\s+/, join( '', @_ ) );
+    my $col   = 0;
+    my $sup   = "";
+    my $word;
+
+    foreach $word (@words) {
+	my $len = length($word);
+	if ( defined($word) && $len > 0 ) {
+	    if ( $col != 0 ) {
+		$sup = " ";
+	    }
+
+	    if ( $word eq "\n" || $word eq "\r" ) {
+		$deferredlogbuffer .= "\n";
+		$col = 0;
+	    }
+	    elsif ( $col + $len + length($sup) < 80 ) {
+		$deferredlogbuffer .= $sup . $word;
+		$col = $col + length($sup) + $len;
+	    }
+	    else {
+		$deferredlogbuffer .= "\n... " . $word;
+		$col = 4 + $len;
+	    }
+	}
+    }
+
+    $deferredlogbuffer .= "\n";
+
+    if ( !$DEFERREDLOG ) {
+	FlushLog();
+    }
+    else {
+	RotateCursor();
+    }
+}
+
+# Debug
+sub Debug ($) {
+    my (@msg) = @_;
+
+    # FIXME à faire une bonne fois pour toutes !
+    my $basename = ( split( '/', $0 ) )[-1];
+    Log( $basename . ": DEBUG: ", @msg );
+}
+
+# Warn
+sub Warn {
+    my ( $err, @msg ) = @_;
+    my $basename;
+
+    $basename = ( split( '/', $0 ) )[-1];
+
+    Log( $basename . ": WARN: ", @msg );
+}
+
+# Abort
+sub Abort {
+    my ( $err, @msg ) = @_;
+    my $basename;
+
+    $basename = ( split( '/', $0 ) )[-1];
+
+    Log( $basename . ": ERR: ", @msg );
+    FlushLog();
+    exit $err;
+}
+
+1;

Modified: branches/next-gen/lib/PFTools/Net.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Net.pm?rev=766&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Net.pm (original)
+++ branches/next-gen/lib/PFTools/Net.pm Fri Jul  2 08:12:25 2010
@@ -62,6 +62,8 @@
 use POSIX qw(ceil floor);
 
 use PFTools::Conf;
+use PFTools::Logger;
+use PFTools::Parser;
 
 #use Data::Dumper;
 #$Data::Dumper::Sortkeys = 1;
@@ -677,7 +679,7 @@
 #
 #=============================================================================================
 sub Init_lib_net {
-    my ($fic_conf) = @_;
+    my ( $fic_conf, $syntax ) = @_;
 
     my $C;
     my $Z;
@@ -693,7 +695,7 @@
     $Z->{'ALIAS'} = {};
 
     # Chargement du fichier de configuration reseau
-    $C = Load_conf( $fic_conf, 0 );
+    $C = Load_conf( $fic_conf, 'subst', 'network', $syntax );
 
     # Calcul de la conf reseau et de la zone
     foreach $s ( keys %$C ) {

Modified: branches/next-gen/lib/PFTools/Packages.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Packages.pm?rev=766&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Packages.pm (original)
+++ branches/next-gen/lib/PFTools/Packages.pm Fri Jul  2 08:12:25 2010
@@ -38,7 +38,7 @@
 
 our @EXPORT_OK = qw();
 
-use PFTools::Conf;
+use PFTools::Logger;
 
 my $PKG_CMD = {} ;
 $PKG_CMD->{'deb'}->{'status'}	= 'LANG=C LC_ALL=C /usr/bin/dpkg -s' ;
@@ -57,17 +57,17 @@
 
 	my $result = {} ;
 	if ( ! defined $PKG_CMD->{$pkg_type} ) {
-		Warn ( $ERR_OPEN, "Unknown package type ".$pkg_type ) if ( $VERBOSE );
-		return undef ;
-	}
-	elsif ( $pkg_type eq 'rpm' ) {
-		#TODO
-		Warn ( $ERR_OPEN, "Need to implement the RPM handler" ) if ( $VERBOSE );
+		Warn ( $CODE->{'OPEN'}, "Unknown package type ".$pkg_type ) if ( $VERBOSE );
+		return undef ;
+	}
+	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 ( $ERR_OPEN, "Unable to retrieve status for package ".$pkg_name ) if ( $VERBOSE );
+			Warn ( $CODE->{'OPEN'}, "Unable to retrieve status for package ".$pkg_name ) if ( $VERBOSE );
 			return undef ;
 		}
 		while ( <PKG>) {
@@ -93,17 +93,17 @@
 	my ( $pkg_type ) = @_ ;
 
 	if ( ! defined $PKG_CMD->{$pkg_type} ) {
-		Warn ( $ERR_OPEN, "Unknown package type ".$pkg_type ) if ( $VERBOSE );
-		return 0 ;
-	}
-	elsif ( $pkg_type eq 'rpm' ) {
-		#TODO
-		Warn ( $ERR_OPEN, "Need to implement the RPM handler" ) if ( $VERBOSE );
+		Warn ( $CODE->{'OPEN'}, "Unknown package type ".$pkg_type ) if ( $VERBOSE );
+		return 0 ;
+	}
+	elsif ( $pkg_type eq 'rpm' ) {
+		#TODO
+		Warn ( $CODE->{'OPEN'}, "Need to implement the RPM handler" ) if ( $VERBOSE );
 		return 0 ;
 	}
 	elsif ( $pkg_type eq 'deb' ) {
 		if ( deferredlogsystem( $PKG_CMD->{$pkg_type}->{'update'} ) ) {
-			Warn( $ERR_OPEN, "Updating repository failed !" ) if ( $VERBOSE );
+			Warn( $CODE->{'OPEN'}, "Updating repository failed !" ) if ( $VERBOSE );
 			return 0 ;
 		}
 	}
@@ -114,17 +114,17 @@
 	my ( $pkg_type, $pkg_name ) = @_ ;
 
 	if ( ! defined $PKG_CMD->{$pkg_type} ) {
-		Warn ( $ERR_OPEN, "Unknown package type ".$pkg_type ) if ( $VERBOSE );
-		return 0 ;
-	}
-	elsif ( $pkg_type eq 'rpm' ) {
-		#TODO
-		Warn ( $ERR_OPEN, "Need to implement the RPM handler" ) if ( $VERBOSE );
+		Warn ( $CODE->{'OPEN'}, "Unknown package type ".$pkg_type ) if ( $VERBOSE );
+		return 0 ;
+	}
+	elsif ( $pkg_type eq 'rpm' ) {
+		#TODO
+		Warn ( $CODE->{'OPEN'}, "Need to implement the RPM handler" ) if ( $VERBOSE );
 		return 0 ;
 	}
 	elsif ( $pkg_type eq 'deb' ) {
 		if ( deferredlogsystem ( $PKG_CMD->{$pkg_type}->{'purge'}." '".$pkg_name."'" ) ) {
-			Warn( $ERR_OPEN, "Unable to purge ".$pkg_name ) if ( $VERBOSE );
+			Warn( $CODE->{'OPEN'}, "Unable to purge ".$pkg_name ) if ( $VERBOSE );
 			return 0 ;
 		}
 	}
@@ -136,17 +136,17 @@
 	my $dep_list ;
 
 	if ( ! defined $PKG_CMD->{$pkg_type} ) {
-		Warn ( $ERR_OPEN, "Unknown package type ".$pkg_type ) if ( $VERBOSE );
-		return undef ;
-	}
-	elsif ( $pkg_type eq 'rpm' ) {
-		#TODO
-		Warn ( $ERR_OPEN, "Need to implement the RPM handler" ) if ( $VERBOSE );
+		Warn ( $CODE->{'OPEN'}, "Unknown package type ".$pkg_type ) if ( $VERBOSE );
+		return undef ;
+	}
+	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( APTDEP, $PKG_CMD->{$pkg_type}->{'depends'}.' '.$pkg_name.' 2>/dev/null |' ) ) {
-			Warn ( $ERR_OPEN, "Unable to get depends for package ".$pkg_name ) if ( $VERBOSE );
+			Warn ( $CODE->{'OPEN'}, "Unable to get depends for package ".$pkg_name ) if ( $VERBOSE );
 			return undef ;
 		}
 		while (<APTDEP>) {
@@ -179,17 +179,17 @@
 
 	$specified_version = 0 ;
 	if ( ! defined $PKG_CMD->{$pkg_type} ) {
-		Warn ( $ERR_OPEN, "Unknown package type ".$pkg_type ) if ( $VERBOSE );
-		return undef ;
-	}
-	elsif ( $pkg_type eq 'rpm' ) {
-		#TODO
-		Warn ( $ERR_OPEN, "Need to implement the RPM handler" ) if ( $VERBOSE );
+		Warn ( $CODE->{'OPEN'}, "Unknown package type ".$pkg_type ) if ( $VERBOSE );
+		return undef ;
+	}
+	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( APTPOLICY, $PKG_CMD->{$pkg_type}->{'policy'}.' '.$pkg_name.' 2>/dev/null |' ) ) {
-			Warn ( $ERR_OPEN, "Unable to get policy for package ".$pkg_name ) if ( $VERBOSE );
+			Warn ( $CODE->{'OPEN'}, "Unable to get policy for package ".$pkg_name ) if ( $VERBOSE );
 			return undef ;
 		}
 		while ( <APTPOLICY> ) {
@@ -213,12 +213,12 @@
 	my ( $pkg_type, $pkg_name, $version1, $version2 ) = @_ ;
 
 	if ( ! defined $PKG_CMD->{$pkg_type} ) {
-		Warn ( $ERR_OPEN, "Unknown package type ".$pkg_type ) if ( $VERBOSE );
-		return undef ;
-	}
-	elsif ( $pkg_type eq 'rpm' ) {
-		#TODO
-		Warn ( $ERR_OPEN, "Need to implement the RPM handler" ) if ( $VERBOSE );
+		Warn ( $CODE->{'OPEN'}, "Unknown package type ".$pkg_type ) if ( $VERBOSE );
+		return undef ;
+	}
+	elsif ( $pkg_type eq 'rpm' ) {
+		#TODO
+		Warn ( $CODE->{'OPEN'}, "Need to implement the RPM handler" ) if ( $VERBOSE );
 		return undef ;
 	}
 	else {
@@ -240,12 +240,12 @@
 	my ( $pkg_type, $pkg_name, $version ) = @_ ;
 
 	if ( ! defined $PKG_CMD->{$pkg_type} ) {
-		Warn ( $ERR_OPEN, "Unknown package type ".$pkg_type ) if ( $VERBOSE );
-		return undef ;
-	}
-	elsif ( $pkg_type eq 'rpm' ) {
-		#TODO
-		Warn ( $ERR_OPEN, "Need to implement the RPM handler" ) if ( $VERBOSE );
+		Warn ( $CODE->{'OPEN'}, "Unknown package type ".$pkg_type ) if ( $VERBOSE );
+		return undef ;
+	}
+	elsif ( $pkg_type eq 'rpm' ) {
+		#TODO
+		Warn ( $CODE->{'OPEN'}, "Need to implement the RPM handler" ) if ( $VERBOSE );
 		return undef ;
 	}
 	else {

Added: branches/next-gen/lib/PFTools/Parser.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Parser.pm?rev=766&op=file
==============================================================================
--- branches/next-gen/lib/PFTools/Parser.pm (added)
+++ branches/next-gen/lib/PFTools/Parser.pm Fri Jul  2 08:12:25 2010
@@ -1,0 +1,384 @@
+package PFTools::Parser;
+##
+##  $Id: Conf.pm 765 2010-06-30 13:51:27Z ccaillet-guest $
+##
+##  Copyright (C) 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
+##  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 Exporter;
+
+our @ISA = ('Exporter');
+
+our @EXPORT = qw(
+	$PFTOOLS_VARS
+
+	Subst_vars
+	Parser_pftools
+	Parser_ini
+);
+
+our @EXPORT_OK = qw();
+
+use PFTools::Logger;
+use Config::IniFiles;
+
+######################
+### Constants
+# PFTools variables define in configuration files
+our $PFTOOLS_VARS = {} ;
+$PFTOOLS_VARS->{'VMWARE'}	= 0 ;
+$PFTOOLS_VARS->{'UML'}		= 0 ;
+
+######################
+### Prototypes
+sub __Add_var ($$$);
+
+########################
+# Internal variables
+my $DEBUG = 0;
+
+sub __Add_var ($$$) {
+    my ( $V, $var, $val ) = @_;
+
+    if ( $var =~ /^((\\\.|[^.])*[^\\])\./ ) {
+	my $esc1  = $1;
+	my $quote = $';
+	$esc1 =~ s/\\\././g;
+	if ( !defined( $V->{$esc1} ) ) {
+	    $V->{$esc1} = {};
+	}
+	if ( !ref( $V->{$esc1} ) ) {
+	    return ($CODE->{'SYNTAX'});
+	}
+	__Add_var( $V->{$esc1}, $quote, $val );
+    }
+    else {
+	$var =~ s/\\\././g;
+	if ( defined( $V->{$var} ) ) {
+#		print "Syntax error\n" ;
+	    return ($CODE->{'SYNTAX'});
+	}
+	$V->{$var} = $val;
+	return (0);
+    }
+}
+
+# Subst_vars
+sub Subst_vars ($$) {
+    my ( $str, $hash_subst ) = @_;
+
+#     while ( $str =~ s/%([^%\s]*)%/$SUBST{"$1"}/ ) { }
+    foreach my $elt ( split ( '%', $str ) ) {
+        next if ( $elt eq '' );
+        if ( defined $hash_subst->{$elt} ) {
+            $str =~ s/%$elt%/$hash_subst->{$elt}/;
+        }
+    }
+    return ($str);
+}
+
+sub Parser_pftools ($$) {
+    my ( $fic_conf, $substdestvars ) = @_;
+
+    my $CONF     = {};
+    my $LOCATION	= {} ;
+    my $current  = ']';
+    my @FIC_CONF = ();
+    my @ALL_CONF = ();
+    my @FH	= () ;
+    my @line     = ();
+    my @cond     = ();
+
+    unshift @FIC_CONF, $fic_conf;
+    unshift @ALL_CONF, $fic_conf;
+    unshift @line,     0;
+    print "Opening $FIC_CONF[0]\n" if ( $DEBUG );
+    open( $FH[0], $FIC_CONF[0] )
+	|| Abort( $$CODE->{'OPEN'}, "Impossible d'ouvrir " . $FIC_CONF[0] );
+    print "Filehandles --> @FH\n"  if ( $DEBUG );
+    while ( $#FH >= 0 ) {
+	my $fh = $FH[0];    # Perl gruik, ne pas simplifier!!!
+    LOADCONFLINE: while (<$fh>) {
+# 		print "Using fh --> $fh\n" ;
+	    # Compter les lignes
+	    $line[0]++;
+
+	    # Eliminer les commentaires et les espaces inutiles
+	    chomp;
+	    s/^\s*//;
+	    s/\s*$//;
+	    s/\s*#.*$//;
+
+	    # Ne pas traiter les lignes vides
+	    next if (/^$/);
+
+	    # Traitement des directives IF (0 param)
+	    if (/^\@([^\s]+)$/) {
+		if ( $1 eq "else" ) {
+		    if ( $#cond < 0 ) {
+			Abort ( $CODE->{'SYNTAX'},
+			          $FIC_CONF[0] . ":"
+				. $line[0]
+				. ": else sans if" );
+		    }
+		    $cond[0] = ( $#cond > 0 && !$cond[1] ) ? 0 : !$cond[0];
+		    next;
+		}
+		elsif ( $1 eq "endif" ) {
+		    if ( $#cond < 0 ) {
+			Abort( $CODE->{'SYNTAX'},
+			          $FIC_CONF[0] . ":"
+				. $line[0]
+				. ": endif sans if" );
+		    }
+		    shift @cond;
+		    next;
+		}
+	    }
+
+	    # Traitement des directives IF (1 param)
+	    if (/^\@([^\s]+)\s+([^\s]+)$/) {
+		if ( $1 eq "ifdef" ) {
+		    if ( defined $PFTOOLS_VARS->{$2} ) {
+			unshift @cond, ( $#cond > 0 && !$cond[1] ) ? 0 : 1;
+		    }
+		    else {
+			unshift @cond, 0;
+		    }
+		    next;
+		}
+		elsif ( $1 eq "ifndef" ) {
+		    if ( not defined $PFTOOLS_VARS->{$2} ) {
+			unshift @cond, 0;
+		    }
+		    else {
+			unshift @cond, ( $#cond > 0 && !$cond[1] ) ? 0 : 1;
+		    }
+		    next;
+		}
+		elsif ( $1 eq "if" ) {
+		    if ( defined $PFTOOLS_VARS->{$2} && $PFTOOLS_VARS->{$2} ) {
+			unshift @cond, ( $#cond > 0 && !$cond[1] ) ? 0 : 1;
+		    }
+		    else {
+			unshift @cond, 0;
+		    }
+		    next;
+		}
+		elsif ( $1 eq "ifnot" ) {
+		    if ( defined $PFTOOLS_VARS->{$2} && ! $PFTOOLS_VARS->{$2} ) {
+			unshift @cond, 0;
+		    }
+		    else {
+			unshift @cond, ( $#cond > 0 && !$cond[1] ) ? 0 : 1;
+		    }
+		    next;
+		}
+	    }
+
+	    # Seulement les directives IF si condition fausse
+	    next if ( $#cond >= 0 && !$cond[0] );
+
+	    if (/^\@([^\s]+)\s+([^\s]+)$/) {
+		if ( $1 eq "include" ) {
+		    my $fic_conf = $2;
+		    my $oldficconf;
+
+		    if ( $fic_conf =~ m|/| ) {
+			Abort( $CODE->{'OPEN'},
+			          $FIC_CONF[1] . ":"
+				. $line[1]
+				. ": Include avec chemin interdit" );
+		    }
+
+		    if ( $FIC_CONF[0] =~ m|^(.*)/[^/]*$| ) {
+			$fic_conf = $1 . '/include-' . $fic_conf;
+		    }
+		    else {
+			$fic_conf = "include-" . $fic_conf;
+		    }
+
+		    foreach $oldficconf (@ALL_CONF) {
+			if ( $fic_conf eq $oldficconf ) {
+			    Warn( $CODE->{'OPEN'},
+				      $FIC_CONF[0] . ":"
+				    . $line[0] . ": "
+				    . $fic_conf
+				    . " deja inclus ligne "
+				    . $LOCATION->{'include'}->{$fic_conf}->{'line'}
+				    . " dans "
+				    . $LOCATION->{'include'}->{$fic_conf}->{'source'} );
+			    next LOADCONFLINE;
+			}
+		    }
+			$LOCATION->{'include'}->{$fic_conf}->{'line'} = $line[0] ;
+			$LOCATION->{'include'}->{$fic_conf}->{'source'} = $FIC_CONF[0] ;
+		    unshift @FIC_CONF, $fic_conf;
+		    unshift @ALL_CONF, $fic_conf;
+		    unshift @line,     0;
+		    print "Opening $FIC_CONF[0]\n"  if ( $DEBUG );
+		    my $newfh ;
+		    open( $newfh, $FIC_CONF[0] )
+			|| Abort( $CODE->{'OPEN'},
+			      $FIC_CONF[1] . ":"
+			    . $line[1]
+			    . ": Impossible d'inclure "
+			    . $FIC_CONF[0] );
+		    ;    # Perl gruik, ne pas simplifier!!!
+		    print "File list after including $FIC_CONF[0] ".join ( " ", @ALL_CONF )."\n"  if ( $DEBUG );
+		    unshift @FH, $newfh ;
+		    $fh = $newfh ;
+		    print "Filehandles list after inclusion --> @FH\n" if ( $DEBUG );
+		}
+		elsif ( $1 eq "define" ) {
+		    if ( defined( $PFTOOLS_VARS->{$2} ) ) {
+			Warn( $CODE->{'OPEN'},
+			          $FIC_CONF[0] . ":"
+				. $line[0] . ": "
+				. $2
+				. " deja defini" );
+		    }
+		    else {
+			$PFTOOLS_VARS->{$2} = 1;
+		    }
+		}
+		elsif ( $1 eq "undef" ) {
+		    if ( not defined( $PFTOOLS_VARS->{$2} ) ) {
+			Warn( $CODE->{'OPEN'},
+			          $FIC_CONF[0] . ":"
+				. $line[0] . ": "
+				. $2
+				. " deja non defini" );
+		    }
+		    else {
+			undef $PFTOOLS_VARS->{$2};
+		    }
+		}
+		else {
+		    Abort( $CODE->{'SYNTAX'},
+			      $FIC_CONF[0] . ":"
+			    . $line[0]
+			    . ": Directive "
+			    . $1
+			    . " inconnue" );
+		}
+		next;
+	    }
+
+	    # Detection des sections
+	    if (/^\[([^\]]+)\]$/) {
+		if ( defined $substdestvars && $substdestvars ) {
+		    $current = Subst_vars( $1, $substdestvars );
+		}
+		else {
+		    $current = $1;
+		}
+		if ( defined( $CONF->{$current} ) ) {
+		    Abort( $CODE->{'SYNTAX'},
+			      $FIC_CONF[0] . ":"
+			    . $line[0] . ": ["
+			    . $current
+			    . "] dupliquee (precedente a "
+			    . $LOCATION->{$current}->{_location}
+			    . ")" );
+		}
+		else {
+		    $CONF->{$current} = {};
+		    $LOCATION->{$current}->{_location}
+			= $FIC_CONF[0] . ":" . $line[0];
+		}
+		next;
+	    }
+
+	    # Traitement des variables
+	    if (/^([^\s]+)\s*=\s*(.+)$/) {
+	    	my ( $var, $val ) = ( $1, $2 ) ;
+		if ( defined( $CONF->{$current}->{$var} ) ) {
+		    Abort( $CODE->{'SYNTAX'},
+			      $FIC_CONF[0] . ":"
+			    . $line[0] . ": "
+			    . $var
+			    . " dupliquee (precedente a "
+			    . $LOCATION->{$current}->{$var}->{_location}
+			    . ")" );
+		}
+		else {
+
+		    if ( __Add_var( $CONF->{$current}, $var, $val ) == $CODE->{'SYNTAX'} )
+		    {
+			Abort( $CODE->{'SYNTAX'},
+			          $FIC_CONF[0] . ":"
+				. $line[0] . ": "
+				. $var
+				. " dupliquee (precedente a "
+				. $LOCATION->{$current}->{$var}->{_location}
+				. ")" );
+		    }
+		    $LOCATION->{$current}->{$var}->{_location}
+			= $FIC_CONF[0] . ":" . $line[0];
+		}
+	    }
+	    else {
+		Abort( $CODE->{'SYNTAX'},
+		    $FIC_CONF[0] . ":" . $line[0] . ": Erreur de syntaxe" );
+	    }
+	}
+	close( $FH[0] ) ;
+	print "Closing $FIC_CONF[0] -- $FH[0]\n"  if ( $DEBUG );
+	shift @FH;
+	print "Filehandles after closing --> @FH\n"  if ( $DEBUG );
+	shift @line;
+	shift @FIC_CONF;
+    }
+
+    # Conditions non fermees
+    if ( $#cond >= 0 ) {
+	Abort( $CODE->{'SYNTAX'}, "EOC: endif manquant" );
+    }
+
+    return ($CONF);
+}
+
+sub Parser_ini ($) {
+	my ( $file ) = @_;
+	
+	my $parse = new Config::IniFiles ( -file => $file, -allowedcommentchars => '@' );
+	if ( ! defined ( $parse ) ) {
+		if ( $DEBUG ) {
+			warn "Unable to parse file ".$file." with the following errors\n" ;
+			warn join ( "\n", @Config::IniFiles::errors ) ;
+		}
+		return undef ;
+	}
+	my $refined = $parse->{'v'};
+	foreach my $sect ( keys %{$refined} ) {
+		foreach my $key ( keys %{$refined->{$sect}} ) {
+			if ( ref ( $refined->{$sect}->{$key} ) eq 'ARRAY' && $key !~ /^@/ ) {
+				$refined->{$sect}->{$key} = pop ( @{$refined->{$sect}->{$key}} ) ;
+			} elsif ( $key =~ /^@/ && ref ( $refined->{$sect}->{$key} ) ne 'ARRAY' ) {
+				$refined->{$sect}->{$key} = [ $refined->{$sect}->{$key} ] ;
+			}
+		}
+	}
+	$refined->{'__sections_order'} = $parse->{'mysects'};
+	return $refined;
+}
+
+1;

Modified: branches/next-gen/lib/PFTools/Update.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update.pm?rev=766&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Update.pm (original)
+++ branches/next-gen/lib/PFTools/Update.pm Fri Jul  2 08:12:25 2010
@@ -31,19 +31,16 @@
 our @ISA = ('Exporter');
 
 our @EXPORT = qw(
-    $ERR_OPEN
-    $ERR_SYNTAX
-
     CVS_update
     dirname
     Do_update
-    Get_source
 );
 
 our @EXPORT_OK = qw();
 
 use PFTools::Conf;
 use PFTools::Net;
+use PFTools::Logger;
 use PFTools::Packages;
 
 use Fcntl ':mode';
@@ -53,10 +50,6 @@
 use Debconf::Template;
 use Debconf::ConfModule;
 
-# Error code
-our $ERR_OPEN = 1;
-our $ERR_SYNTAX = 2;
-
 $ENV{'PATH'}            = $ENV{'PATH'} . ":/usr/local/sbin:/usr/local/bin";
 $ENV{'DEBIAN_FRONTEND'} = "noninteractive";
 $ENV{'DEBIAN_PRIORITY'} = "critical";
@@ -65,7 +58,6 @@
 $DEFERREDLOG = 0;
 
 # Constantes
-my $PFTOOLSCONF     = "/etc/pf-tools.conf";
 my $CVS_CHECKOUT    = "/var/lib/cvsguest";
 my $HOSTNAME        = $SUBST{'HOSTNAME'};
 my $HOSTTYPE        = $SUBST{'HOSTTYPE'};
@@ -85,63 +77,6 @@
 
 #$PKGLIST         = "/var/lib/apt/lists";
 
-# Conf Par Defaut
-my $PF_STATUS_DIR = "/var/lib/pftools";
-
-my $CVS_USER       = "cvsguest";
-my $CVS_RSH        = "/usr/local/sbin/cvs_rsh";
-my $CVS_SERVER     = "cvs.private";
-my $CVS_ROOT       = "/var/lib/cvs";
-my $CVS_REPOSITORY = $CVS_ROOT . "/repository";
-my $CVS_CONFIG     = "config";
-our $CVS_COMMAND;
-my $CVS_BRANCHE;
-
-# End Conf Par Defaut!
-
-if ( -r $PFTOOLSCONF ) {
-    my $newuid;
-    my $newgid;
-    my $dev;
-    my $ino;
-    my $mode;
-    my $nlink;
-    my $uid;
-    my $gid;
-    my $rdev;
-    my $size;
-    my $atime;
-    my $mtime;
-    my $ctime;
-    my $blksize;
-    my $blocks;
-
-    (   $dev,  $ino,   $mode,  $nlink, $uid,     $gid, $rdev,
-	$size, $atime, $mtime, $ctime, $blksize, $blocks
-    ) = lstat($PFTOOLSCONF);
-
-    if ( $uid == 0 && $gid == 0 && S_IMODE($mode) == 0600 && S_ISREG($mode) )
-    {
-
-	my $result;
-	my $return;
-	unless ( $result = do $PFTOOLSCONF ) {
-	    warn "couldn't parse $PFTOOLSCONF: $@" if $@;
-	    warn "couldn't do $PFTOOLSCONF: $!" unless defined $return;
-	    warn "couldn't run $PFTOOLSCONF"    unless $return;
-	}
-    }
-    else {
-	print STDERR "Ignoring weak config (check owner/group/mode)\n";
-    }
-}
-
-# Constantes deduites de la conf
-my $CVS_WORKING_DIR = $CVS_CHECKOUT . "/" . $HOSTNAME;
-my $CVS_TMP_DIR     = $CVS_CHECKOUT . "/" . $HOSTNAME . "/tmp";
-my $CVS_OLD_DIR     = $CVS_CHECKOUT . "/" . $HOSTNAME . "/old";
-my $GLOBAL_CONF     = $CVS_WORKING_DIR . "/" . $CVS_CONFIG . "/GLOBAL";
-my $TEMPLATES       = $CVS_WORKING_DIR . "/" . $CVS_CONFIG . "/TEMPLATES";
 
 # Fonctions utilisees dans les fichiers de conf
 
@@ -299,7 +234,7 @@
     $group = defined( $S->{'group'} ) ? $S->{'group'} : $DEFAULT_GROUP;
 
     if ( fullchown( $owner, $group, $dest, $options ) ) {
-	Warn( $ERR_OPEN,
+	Warn( $CODE->{'OPEN'},
 	          "Impossible d'attribuer " 
 		. $dest . " a " 
 		. $owner . "."
@@ -314,7 +249,7 @@
     $mode =~ s/^[^0]/0$&/;
 
     if ( fullchmod( eval($mode), $dest, $options ) ) {
-	Warn( $ERR_OPEN,
+	Warn( $CODE->{'OPEN'},
 	    "Impossible d'attribuer les droits " . $mode . " a " . $dest );
 	return 1;
     }
@@ -324,7 +259,7 @@
 	my ( $cmd ) = @_;
 
 	if ( deferredlogsystem($cmd) ) {
-	    Warn( $ERR_OPEN, "Impossible d'executer [" . $cmd . "]" );
+	    Warn( $CODE->{'OPEN'}, "Impossible d'executer [" . $cmd . "]" );
 	    return 1;
 	}
 	return 0;
@@ -392,7 +327,7 @@
     my $cmp;
 
     if ( !defined( $S->{'source'} ) ) {
-	Abort( $ERR_SYNTAX, "Source non definie pour " . $dest );
+	Abort( $CODE->{'SYNTAX'}, "Source non definie pour " . $dest );
     }
     $SUBST{'SECTIONNAME'} = $dest;
     if ( $S->{'source'} =~ /\s/ ) {
@@ -403,7 +338,7 @@
 	foreach $splitsource ( split( ' ', $S->{'source'} ) ) {
 	    $splitsource = Get_source( Subst_vars($splitsource) );
 	    if ( !-f $splitsource ) {
-		Warn( $ERR_OPEN, "Impossible d'ouvrir " . $splitsource );
+		Warn( $CODE->{'OPEN'}, "Impossible d'ouvrir " . $splitsource );
 		return 1;
 	    }
 	    if (deferredlogsystem(
@@ -411,7 +346,7 @@
 		)
 		)
 	    {
-		Warn( $ERR_OPEN,
+		Warn( $CODE->{'OPEN'},
 		          "Impossible de concatener "
 			. $splitsource
 			. " dans "
@@ -431,7 +366,7 @@
     if ( defined( $S->{'filter'} ) ) {
 	my $filter = Subst_vars( $S->{'filter'} );
 	if ( deferredlogsystem($filter) ) {
-	    Warn( $ERR_OPEN, "Impossible d'appliquer " . $filter );
+	    Warn( $CODE->{'OPEN'}, "Impossible d'appliquer " . $filter );
 	    return 1;
 	}
     }
@@ -442,14 +377,14 @@
 	    )
 	    )
 	{
-	    Warn( $ERR_OPEN,
+	    Warn( $CODE->{'OPEN'},
 		"Impossible de copier " . $source . " vers " . $tmp );
 	    return 1;
 	}
     }
 
     if ( !-f $tmp ) {
-	Warn( $ERR_OPEN, "Impossible d'ouvrir " . $tmp );
+	Warn( $CODE->{'OPEN'}, "Impossible d'ouvrir " . $tmp );
 	return 1;
     }
 
@@ -492,7 +427,7 @@
 		)
 		)
 	    {
-		Warn( $ERR_OPEN,
+		Warn( $CODE->{'OPEN'},
 		    "Impossible de copier " . $tmp . " vers " . $dest );
 		return 1;
 	    }
@@ -520,12 +455,12 @@
 	$SUBST{'SECTIONNAME'} = $dest;
 	my $newdest = deferredlogpipe( Subst_vars($name_filter) );
 	unless ( defined $newdest ) {
-	    Warn( $ERR_OPEN,
+	    Warn( $CODE->{'OPEN'},
 		"Impossible d'appliquer name_filter $name_filter" );
 	    return 1;
 	}
 	unless ($newdest) {
-	    Warn( $ERR_OPEN, "Resultat vide pour name_filter $name_filter" );
+	    Warn( $CODE->{'OPEN'}, "Resultat vide pour name_filter $name_filter" );
 	    return 1;
 	}
 	$dest = $newdest;
@@ -551,7 +486,7 @@
 
     my $status = Get_pkg_status ( $pkg_type, $dest ) ;
     if ( ! defined $status ) {
-	Warn ( $ERR_OPEN, "Impossible d'obtenir le statut du paquet ".$dest ) ;
+	Warn ( $CODE->{'OPEN'}, "Impossible d'obtenir le statut du paquet ".$dest ) ;
 	return 1;
     }
 
@@ -567,12 +502,12 @@
 
 	if ( !$options->{'simul'} ) {
 # 	    if ( deferredlogsystem( $DPKG . " -P '" . $dest . "'" ) ) {
-# 		Warn( $ERR_OPEN,
+# 		Warn( $CODE->{'OPEN'},
 # 		    "Purge du package " . $dest . " impossible" );
 # 		return 1;
 # 	    }
 	    if ( ! Purge_pkg ( $pkg_type, $dest ) ) {
-		Warn ( $ERR_OPEN, "Une erreur est survenue lors de la purge du paquet ".$dest ) ;
+		Warn ( $CODE->{'OPEN'}, "Une erreur est survenue lors de la purge du paquet ".$dest ) ;
 		return 1 ;
 	    }
 	}
@@ -620,7 +555,7 @@
 #     close(APTDEP);
     my $deps = Get_pkg_depends ( $pkg_type, $dest ) ;
     if ( ! defined $deps ) {
-	Warn ( $ERR_OPEN, "Impossible de recuperer les dependances du paquet ".$dest ) ;
+	Warn ( $CODE->{'OPEN'}, "Impossible de recuperer les dependances du paquet ".$dest ) ;
 	return 1;
     }
     else {
@@ -642,12 +577,12 @@
 	$SUBST{'SECTIONNAME'} = $dest;
 	my $newdest = deferredlogpipe( Subst_vars($name_filter) );
 	unless ( defined $newdest ) {
-	    Warn( $ERR_OPEN,
+	    Warn( $CODE->{'OPEN'},
 		"Impossible d'appliquer name_filter $name_filter" );
 	    return 1;
 	}
 	unless ($newdest) {
-	    Warn( $ERR_OPEN, "Resultat vide pour name_filter $name_filter" );
+	    Warn( $CODE->{'OPEN'}, "Resultat vide pour name_filter $name_filter" );
 	    return 1;
 	}
 	$dest = $newdest;
@@ -673,16 +608,16 @@
     ( $installed_version, $available_version, $specified_version ) = Get_pkg_policy ( $pkg_type, $dest, $S->{'version'} ) ;
     
 #     if ( !defined($available_version) ) {
-# 	Warn( $ERR_OPEN, "Package " . $dest . " indisponible" );
+# 	Warn( $CODE->{'OPEN'}, "Package " . $dest . " indisponible" );
 # 	return 1;
 #     }
 
     if ( !defined ( $available_version ) ) {
-	Warn( $ERR_OPEN, "Package " . $dest . " indisponible" );
+	Warn( $CODE->{'OPEN'}, "Package " . $dest . " indisponible" );
 	return 1;
     }
     if ( defined ( $S->{'version'} ) && ! $specified_version ) {
-	Warn( $ERR_OPEN, "Package " . $dest . " en version " . $S->{'version'} . " indisponible" );
+	Warn( $CODE->{'OPEN'}, "Package " . $dest . " en version " . $S->{'version'} . " indisponible" );
 	return 1;
     }
 
@@ -772,11 +707,11 @@
 # 		)
 # 		)
 # 	    {
-# 		Warn( $ERR_OPEN, "Installation de " . $dest . " impossible" );
+# 		Warn( $CODE->{'OPEN'}, "Installation de " . $dest . " impossible" );
 # 		return 1;
 # 	    }
 	    if ( ! Install_pkg ( $pkg_type, $dest, $S->{'version'} ) ) {
-	        Warn( $ERR_OPEN, "Installation de ".$dest." impossible" ) ;
+	        Warn( $CODE->{'OPEN'}, "Installation de ".$dest." impossible" ) ;
 		return 1;
 	    }
 	}
@@ -825,7 +760,7 @@
     my $Z;
 
     if ( !defined( $S->{'source'} ) ) {
-	Abort( $ERR_SYNTAX, "Source non definie pour " . $dest );
+	Abort( $CODE->{'SYNTAX'}, "Source non definie pour " . $dest );
     }
     $SUBST{'SECTIONNAME'} = $dest;
     $source = Subst_vars( $S->{'source'} );
@@ -865,7 +800,7 @@
     $SUBST{'FSTYPE'} = $fstype;
 
     if ( !open( FSTAB, "< /etc/fstab" ) ) {
-	Warn( $ERR_OPEN, "Impossible de lire /etc/fstab" );
+	Warn( $CODE->{'OPEN'}, "Impossible de lire /etc/fstab" );
 	return 1;
     }
     while (<FSTAB>) {
@@ -941,7 +876,7 @@
 
     if ( !$options->{'noaction'} ) {
 	if ( !open( MOUNTS, "< /proc/mounts" ) ) {
-	    Warn( $ERR_OPEN, "Impossible de lire /proc/mounts" );
+	    Warn( $CODE->{'OPEN'}, "Impossible de lire /proc/mounts" );
 	}
 	else {
 	    while (<MOUNTS>) {
@@ -1014,7 +949,7 @@
 
 	if ( !-d $dest && $dest ne 'none' ) {
 	    if ( !defined( $FUNCTIONS{'mkdir'} ) ) {
-		Warn( $ERR_OPEN, "Fonction mkdir necessaire pour addmount" );
+		Warn( $CODE->{'OPEN'}, "Fonction mkdir necessaire pour addmount" );
 		return 1;
 	    }
 	    $FUNCTIONS{'mkdir'}->( $S, $dest, $options );
@@ -1024,12 +959,12 @@
 	    my $tmp = Get_tmp_dest("/etc/fstab");
 
 	    if ( !open( FSTAB, "< /etc/fstab" ) ) {
-		Warn( $ERR_OPEN, "Impossible de lire /etc/fstab" );
+		Warn( $CODE->{'OPEN'}, "Impossible de lire /etc/fstab" );
 		return 1;
 	    }
 
 	    if ( !open( NEWFSTAB, "> " . $tmp ) ) {
-		Warn( $ERR_OPEN, "Impossible de creer " . $tmp );
+		Warn( $CODE->{'OPEN'}, "Impossible de creer " . $tmp );
 		return 1;
 	    }
 
@@ -1039,7 +974,7 @@
 		    && $oldsource ne $source
 		    && $line =~ m|^[ 	]*$oldsource[ 	]+| )
 		{
-		    Warn( $ERR_OPEN,
+		    Warn( $CODE->{'OPEN'},
 			      "Suppression de la source "
 			    . $oldsource
 			    . " de fstab" );
@@ -1048,7 +983,7 @@
 		    && $olddest ne $dest
 		    && $line =~ m|^[ 	]*[^ 	]+[ 	]+$olddest[ 	]+| )
 		{
-		    Warn( $ERR_OPEN,
+		    Warn( $CODE->{'OPEN'},
 			      "Suppression de la destination " 
 			    . $olddest
 			    . " de fstab" );
@@ -1057,7 +992,7 @@
 		    && $oldfstype ne $fstype
 		    && $line =~ m|^[ 	]*$source+[ 	]+$dest[ 	]+| )
 		{
-		    Warn( $ERR_OPEN,
+		    Warn( $CODE->{'OPEN'},
 			      "Suppression du mauvais type "
 			    . $oldfstype
 			    . " pour "
@@ -1068,7 +1003,7 @@
 		    && $oldopts ne $opts
 		    && $line =~ m|^[ 	]*$source+[ 	]+$dest[ 	]+| )
 		{
-		    Warn( $ERR_OPEN,
+		    Warn( $CODE->{'OPEN'},
 			      "Suppression des mauvaises options " 
 			    . $oldopts
 			    . " pour "
@@ -1090,7 +1025,7 @@
 
 	    if ( !$options->{'simul'} ) {
 		if ( system( "cat '" . $tmp . "' > /etc/fstab" ) ) {
-		    Warn( $ERR_OPEN,
+		    Warn( $CODE->{'OPEN'},
 			      "Impossible de recopier " 
 			    . $tmp
 			    . " dans /etc/fstab" );
@@ -1157,7 +1092,7 @@
 		{
 		    if ( deferredlogsystem( "umount '" . $oldmsource . "'" ) )
 		    {
-			Warn( $ERR_OPEN,
+			Warn( $CODE->{'OPEN'},
 			    "Impossible d'unmounter la source "
 				. $oldmsource );
 			return 1;
@@ -1166,7 +1101,7 @@
 
 		if ( defined($oldmdest) && $oldmdest ne $dest ) {
 		    if ( deferredlogsystem( "umount '" . $oldmdest . "'" ) ) {
-			Warn( $ERR_OPEN,
+			Warn( $CODE->{'OPEN'},
 			    "Impossible d'unmounter la destination "
 				. $oldmdest );
 			return 1;
@@ -1175,7 +1110,7 @@
 
 		if ( defined($oldmfstype) && $oldmfstype ne $fstype ) {
 		    if ( deferredlogsystem( "umount '" . $dest . "'" ) ) {
-			Warn( $ERR_OPEN,
+			Warn( $CODE->{'OPEN'},
 			    "Impossible d'unmounter la destination "
 				. $dest );
 			return 1;
@@ -1192,7 +1127,7 @@
 			)
 			)
 		    {
-			Warn( $ERR_OPEN,
+			Warn( $CODE->{'OPEN'},
 			          "Impossible de remounter la destination " 
 				. $dest
 				. " avec les options "
@@ -1212,7 +1147,7 @@
 			)
 			)
 		    {
-			Warn( $ERR_OPEN,
+			Warn( $CODE->{'OPEN'},
 			          "Impossible de mounter la source " 
 				. $source . " sur "
 				. $dest
@@ -1261,7 +1196,7 @@
 
     $SUBST{'SECTIONNAME'} = $dest;
     if ( !defined( $S->{'source'} ) ) {
-	Abort( $ERR_SYNTAX, "Source non definie pour " . $dest );
+	Abort( $CODE->{'SYNTAX'}, "Source non definie pour " . $dest );
     }
     my $source = Subst_vars( $S->{'source'} );
 
@@ -1289,7 +1224,7 @@
 	    Do_moveold( $dest, $options );
 
 	    if ( Mk_dest_dir($dest) || ln_sfn( $source, $dest ) ) {
-		Warn( $ERR_OPEN,
+		Warn( $CODE->{'OPEN'},
 		    "Impossible de lier " . $dest . " a " . $source );
 		return 1;
 	    }
@@ -1339,7 +1274,7 @@
 		    )
 		    )
 		{
-		    Warn( $ERR_OPEN,
+		    Warn( $CODE->{'OPEN'},
 			"Impossible de creer le fichier " . $dest );
 		    return 1;
 		}
@@ -1357,14 +1292,14 @@
 	$SUBST{'DESTINATION'} = $tmp;
 
 	if ( !-f $source ) {
-	    Warn( $ERR_OPEN, "Impossible d'ouvrir " . $source );
+	    Warn( $CODE->{'OPEN'}, "Impossible d'ouvrir " . $source );
 	    return 1;
 	}
 
 	if ( defined( $S->{'filter'} ) ) {
 	    my $filter = Subst_vars( $S->{'filter'} );
 	    if ( deferredlogsystem($filter) ) {
-		Warn( $ERR_OPEN, "Impossible d'appliquer " . $filter );
+		Warn( $CODE->{'OPEN'}, "Impossible d'appliquer " . $filter );
 		return 1;
 	    }
 	}
@@ -1375,14 +1310,14 @@
 		)
 		)
 	    {
-		Warn( $ERR_OPEN,
+		Warn( $CODE->{'OPEN'},
 		    "Impossible de copier " . $source . " vers " . $tmp );
 		return 1;
 	    }
 	}
 
 	if ( !-f $tmp ) {
-	    Warn( $ERR_OPEN, "Impossible d'ouvrir " . $tmp );
+	    Warn( $CODE->{'OPEN'}, "Impossible d'ouvrir " . $tmp );
 	    return 1;
 	}
 
@@ -1406,7 +1341,7 @@
 		    )
 		    )
 		{
-		    Warn( $ERR_OPEN,
+		    Warn( $CODE->{'OPEN'},
 			"Impossible de creer le fichier " . $dest );
 		    return 1;
 		}
@@ -1455,7 +1390,7 @@
 	    Do_moveold( $dest, $options );
 
 	    if ( deferredlogsystem( "/bin/mkdir -p '" . $dest . "'" ) ) {
-		Warn( $ERR_OPEN,
+		Warn( $CODE->{'OPEN'},
 		    "Impossible de creer le repertoire " . $dest );
 		return 1;
 	    }
@@ -1478,7 +1413,7 @@
 
     my $cmp = 0;
     if ( -d $dest ) {
-	Warn( $ERR_OPEN,
+	Warn( $CODE->{'OPEN'},
 	    "La destination " . $dest . "doit etre un fichier!" );
 	return 1;
     }
@@ -1500,7 +1435,7 @@
 	    # Pas besoin, move -> del
 	    #if (!unlink($dest) )
 	    #{
-	    #    Warn( $ERR_OPEN,
+	    #    Warn( $CODE->{'OPEN'},
 	    #        "Impossible d'effacer " . $dest );
 	    #    return;
 	    #}
@@ -1524,7 +1459,7 @@
 
     my $cmp = 0;
     if ( -e $dest && !-d $dest ) {
-	Warn( $ERR_OPEN,
+	Warn( $CODE->{'OPEN'},
 	    "La destination " . $dest . "doit etre un repertoire!" );
 	return 1;
     }
@@ -1546,7 +1481,7 @@
 	    # Pas besoin, move -> del
 	    #if (!rmdir($dest) )
 	    #{
-	    #    Warn( $ERR_OPEN,
+	    #    Warn( $CODE->{'OPEN'},
 	    #        "Impossible d'effacer " . $dest );
 	    #    return;
 	    #}
@@ -1727,7 +1662,7 @@
 		foreach $d (@dependsraw) {
 		    if ( defined($d) && $d ne "" && defined( $C->{$d} ) ) {
 			if ( $d eq $s ) {
-			    Warn ( $ERR_SYNTAX,
+			    Warn ( $CODE->{'SYNTAX'},
 				"["
 				. $s
 				. "] circular dependancy detected, skipping this depend"
@@ -1737,7 +1672,7 @@
 			}
 			push @depends, $d;
 			if ( $C->{$d}->{'action'} eq 'addmount' ) {
-			    Warn( $ERR_OPEN,
+			    Warn( $CODE->{'OPEN'},
 				"[" 
 				. $s
 				. "] depends on addmount ["
@@ -1757,10 +1692,10 @@
 	    Log( "[" . $s . "]" );
 
 	    if ( !defined( $C->{$s}->{'action'} ) ) {
-		Abort( $ERR_SYNTAX, "Action non definie" );
+		Abort( $CODE->{'SYNTAX'}, "Action non definie" );
 	    }
 	    if ( !defined( $FUNCTIONS{ $C->{$s}->{'action'} } ) ) {
-		Abort( $ERR_SYNTAX,
+		Abort( $CODE->{'SYNTAX'},
 		    "Action inconnue '" . $C->{$s}->{'action'} . "'" );
 	    }
 
@@ -1809,13 +1744,13 @@
 
     if ( CVS_update( $branchecvs, $ref_options ) || ( !( $C = Get_conf() ) ) )
     {
-	Abort( $ERR_OPEN, "Impossible de charger la configuration\n" );
+	Abort( $CODE->{'OPEN'}, "Impossible de charger la configuration\n" );
     }
 
     SaveRunningBrancheName($branchecvs);
 
     if ( defined( $ref_options->{'noupdate'} ) ) {
-	Abort( $ERR_OPEN, "Configuration desactivee [noupdate]" );
+	Abort( $CODE->{'OPEN'}, "Configuration desactivee [noupdate]" );
     }
 
     @sortedkeys = sort { Trie_dependances( $C, $a, $b ) } keys %$C;
@@ -1840,10 +1775,10 @@
 
     opendir( CONFIG, Get_source("GLOBAL:") );
     foreach $conf ( $COMMON, sort grep ( /^$template$/, readdir(CONFIG) ) ) {
-	my $c = Load_conf( Get_source( "GLOBAL:" . $conf ), 1 );
+	my $c = Load_conf( Get_source( "GLOBAL:" . $conf ), \%SUBST, 'config' );
 	foreach ( keys %$c ) {
 	    if ( $c->{$_}->{'action'} eq 'ignore' && !defined( $C->{$_} ) ) {
-		Warn( $ERR_OPEN,
+		Warn( $CODE->{'OPEN'},
 		    "ignoring previous inexistant [" . $_ . "] in " . $conf );
 	    }
 	    $C->{$_} = $c->{$_};




More information about the pf-tools-commits mailing list