Talk:Variables: Difference between revisions

From FAIWiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 26: Line 26:
Das Script selbst so:
Das Script selbst so:


<tt>
#! /usr/bin/perl -w


use strict;
#! /usr/bin/perl -w
use File::Find;
use English;
use strict;
my $dir = "/usr/lib/fai";
use File::Find;
my @files;
use English;
my $klammerRegex;
my $dir = "/usr/lib/fai";
$klammerRegex = qr/
my @files;
my $klammerRegex;
$klammerRegex = qr/
   \{
   \{
     (
     (
Line 41: Line 41:
     )*
     )*
   \}  
   \}  
/sx;
/sx;
 
sub wanted;
sub wanted;
 
# Traverse desired filesystems
# Traverse desired filesystems
find({wanted => \&wanted},$dir);
find({wanted => \&wanted},$dir);
 
sub wanted {
sub wanted {
    my ($dev,$ino,$mode,$nlink,$uid,$gid);
    my ($dev,$ino,$mode,$nlink,$uid,$gid);
    return if m/.deb$/;
    return if m/.deb$/;
 
    (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
    (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
    -f _
    -f _
    && push @files,$File::Find::name;
    && push @files,$File::Find::name;
}
}  
 
my @FAI_VARIABLES=qw(BASH BASH_VERSION BOOT_DEVICE BOOT_IMAGE BOOT_PARTITION  
my @FAI_VARIABLES=qw(BASH BASH_VERSION BOOT_DEVICE BOOT_IMAGE BOOT_PARTITION  
BROADCAST COLOR_FAI_LOGO CONSOLE DEBIAN_FRONTEND DIRSTACK DNSDOMAIN DNSSRVS
BROADCAST COLOR_FAI_LOGO CONSOLE DEBIAN_FRONTEND DIRSTACK DNSDOMAIN DNSSRVS
  DNSSRVS_1 DOMAIN DO_INIT_TASKS FAI FAI_ACTION FAI_CONSOLEFONT FAI_FLAGS  
  DNSSRVS_1 DOMAIN DO_INIT_TASKS FAI FAI_ACTION FAI_CONSOLEFONT FAI_FLAGS  
FAI_KEYMAP FAI_LOCATION FAI_LOGPROTO FAI_REMOTECP FAI_REMOTESH FAI_ROOT  
FAI_KEYMAP FAI_LOCATION FAI_LOGPROTO FAI_REMOTECP FAI_REMOTESH FAI_ROOT  
FAI_RUNDATE FAI_VERSION FUNCNAME GATEWAYS GATEWAYS_1 GROUPS HOSTNAME HOSTTYPE  
FAI_RUNDATE FAI_VERSION FUNCNAME GATEWAYS GATEWAYS_1 GROUPS HOSTNAME HOSTTYPE  
IFS INIT_VERSION INSTALL IPADDR LOGDIR LOGPASSWD LOGREMOTEDIR LOGSERVER  
IFS INIT_VERSION INSTALL IPADDR LOGDIR LOGPASSWD LOGREMOTEDIR LOGSERVER  
LOGUSER MACHTYPE MNTPOINT NETMASK NETWORK OLDPWD OPTERR OPTIND OSTYPE OS_TYPE  
LOGUSER MACHTYPE MNTPOINT NETMASK NETWORK OLDPWD OPTERR OPTIND OSTYPE OS_TYPE  
PATH PIPESTATUS PREVLEVEL PS4 ROOTCMD ROOT_PARTITION RUNLEVEL SERVERINTERFACE  
PATH PIPESTATUS PREVLEVEL PS4 ROOTCMD ROOT_PARTITION RUNLEVEL SERVERINTERFACE  
SHELL SHLVL TEMP TERM UTC addpackages HOST backup bserver cfclasses classes  
SHELL SHLVL TEMP TERM UTC addpackages HOST backup bserver cfclasses classes  
console createvt device_size disklist diskvar faimond files fstab hdparm  
console createvt device_size disklist diskvar faimond files fstab hdparm  
hserver ip kernelimage kernelversion liloappend lpipe mirrorhost moduleslist  
hserver ip kernelimage kernelversion liloappend lpipe mirrorhost moduleslist  
moduleslog monserver netdevices netdevices_all netdevices_up nfsroot noexec  
moduleslog monserver netdevices netdevices_all netdevices_up nfsroot noexec  
printers rcslog renewclass romountopt rundir sndhostname sshd stamp target  
printers rcslog renewclass romountopt rundir sndhostname sshd stamp target  
taskname terror timezone);
taskname terror timezone);
 
 
 
my %variables;
my %variables;
my ($fai_variable,$key,$value,$var);
my ($fai_variable,$key,$value,$var);
 
for (@files) {
for (@files) {
    chomp $_;
    chomp $_;
    local $/;
    local $/;
    my $file;
    my $file;
    open(FILE,"<$_",) or die "can't open $_: $!";
    PrivoxyWindowOpen(FILE,"<$_",) or die "can't open $_: $!";
    while (<FILE>) {
    while (<FILE>) {
$file="$file$_";
$file="$file$_";
}
}
 
    while ($file =~ m/(\w+)\(\)\s+$klammerRegex/gsx){
    while ($file =~ m/(\w+)\(\)\s+$klammerRegex/gsx){
my $function = $MATCH;
my $function = $MATCH;
my $functionName = $1;
my $functionName = $1;
while ($function =~ m/\$\w+/gs) {
while ($function =~ m/\$\w+/gs) {
    my $variable = $MATCH;
    my $variable = $MATCH;
    $variables{$variable} = []
    $variables{$variable} = []
unless exists $variables{"$variable"};
  unless exists $variables{"$variable"};
    my $MATCHED=0;
    my $MATCHED=0;
    foreach (@{ $variables{"$variable"} }) {
    foreach (@{ $variables{"$variable"} }) {
if ( $_ eq $functionName) {
if ( $_ eq $functionName) {
    $MATCHED=1;
    $MATCHED=1;
}
}
    }
    }
      push (@{ $variables{"$variable"} }, $functionName)
      push (@{ $variables{"$variable"} }, $functionName)
    unless $MATCHED==1;
    unless $MATCHED==1;
}
}
    }
    }
    close(FILE);  
    close(FILE);  
}
}  
 
# Denn man es nicht im dumper format haben will
# Wenn man es nicht im dumper format haben will
#foreach $var ( keys %variables ){
#foreach $var ( keys %variables ){
#    print "$var:\t@{ $variables{$var} }\n";
#    print "$var:\t@{ $variables{$var} }\n";
#}
#}
 
use Data::Dumper;
print Dumper \%variables;


use Data::Dumper;
print Dumper \%variables;
</tt>


Die nächste Version soll alle Variablen noch selbst extrahieren können, aber einen Überblick bekommt man zumindest erstmal.
Die nächste Version soll alle Variablen noch selbst extrahieren können, aber einen Überblick bekommt man zumindest erstmal.

Revision as of 18:38, 1 August 2006

Hi Mr Fai!

das variablen-script, von dem ich auf dem Workshop geredet habe ist fertig, das ergebnis sieht auf meinem Testbaum so aus:

$VAR1 = {

         '$sd' => [
                    'task_mountdisks'
                  ],
         '$name' => [
                      'defnop'
                    ],
         '$thislog' => [
                         'save_log_local',
                         'save_log_remote_shell'
                       ],
         '$DO_INIT_TASKS' => [
                               'task_confdir',
                               'task_extrbase',
                               'task_setup',
                               'task_action',
                               'task_faiend'
                             ]
   };


Das Script selbst so:


#! /usr/bin/perl -w

use strict;
use File::Find;
use English;
my $dir = "/usr/lib/fai";
my @files;
my $klammerRegex;
$klammerRegex = qr/
 \{
   (
     [^{}] | (??{ $klammerRegex })
   )*
 \} 
/sx;

sub wanted;

# Traverse desired filesystems
find({wanted => \&wanted},$dir);

sub wanted {
    my ($dev,$ino,$mode,$nlink,$uid,$gid);
    return if m/.deb$/;

    (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
    -f _
    && push @files,$File::Find::name;
} 

my @FAI_VARIABLES=qw(BASH BASH_VERSION BOOT_DEVICE BOOT_IMAGE BOOT_PARTITION 
BROADCAST COLOR_FAI_LOGO CONSOLE DEBIAN_FRONTEND DIRSTACK DNSDOMAIN DNSSRVS
DNSSRVS_1 DOMAIN DO_INIT_TASKS FAI FAI_ACTION FAI_CONSOLEFONT FAI_FLAGS 
FAI_KEYMAP FAI_LOCATION FAI_LOGPROTO FAI_REMOTECP FAI_REMOTESH FAI_ROOT 
FAI_RUNDATE FAI_VERSION FUNCNAME GATEWAYS GATEWAYS_1 GROUPS HOSTNAME HOSTTYPE 
IFS INIT_VERSION INSTALL IPADDR LOGDIR LOGPASSWD LOGREMOTEDIR LOGSERVER 
LOGUSER MACHTYPE MNTPOINT NETMASK NETWORK OLDPWD OPTERR OPTIND OSTYPE OS_TYPE 
PATH PIPESTATUS PREVLEVEL PS4 ROOTCMD ROOT_PARTITION RUNLEVEL SERVERINTERFACE 
SHELL SHLVL TEMP TERM UTC addpackages HOST backup bserver cfclasses classes 
console createvt device_size disklist diskvar faimond files fstab hdparm 
hserver ip kernelimage kernelversion liloappend lpipe mirrorhost moduleslist 
moduleslog monserver netdevices netdevices_all netdevices_up nfsroot noexec 
printers rcslog renewclass romountopt rundir sndhostname sshd stamp target 
taskname terror timezone);



my %variables;
my ($fai_variable,$key,$value,$var);

for (@files) {
    chomp $_;
    local $/;
    my $file;
    PrivoxyWindowOpen(FILE,"<$_",) or die "can't open $_: $!";
    while (<FILE>) {
	$file="$file$_";
	}

    while ($file =~ m/(\w+)\(\)\s+$klammerRegex/gsx){
	my $function = $MATCH;
	my $functionName = $1;
	while ($function =~ m/\$\w+/gs) {
	    my $variable = $MATCH;
	    $variables{$variable} = []
 		unless exists $variables{"$variable"};
	    my $MATCHED=0;
	    foreach (@{ $variables{"$variable"} }) {
		if ( $_ eq $functionName) {
		    $MATCHED=1;
		}
	    }
  	    push (@{ $variables{"$variable"} }, $functionName)
		     unless $MATCHED==1;
	}
    }
    close(FILE); 
} 

# Wenn man es nicht im dumper format haben will
#foreach $var ( keys %variables ){
#    print "$var:\t@{ $variables{$var} }\n";
#}
use Data::Dumper;
print Dumper \%variables;


Die nächste Version soll alle Variablen noch selbst extrahieren können, aber einen Überblick bekommt man zumindest erstmal.