Talk:Variables: Difference between revisions

From FAIWiki
Jump to navigation Jump to search
No edit summary
 
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= ancient =
Hi Mr Fai!
Hi Mr Fai!


Line 26: Line 28:
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 43:
     )*
     )*
   \}  
   \}  
/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 ($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.


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


for (@files) {
The list is incomplete. E.g. SWAPLIST is available in FAI 4.0.6 [[User:ThomasNeumann|ThomasNeumann]] 22:10, 2 March 2013 (UTC)
    chomp $_;
    local $/;
    my $file;
    open(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);
}
 
# Denn man es nicht im dumper format haben will
#foreach $var ( keys %variables ){
#    print "$var:\t@{ $variables{$var} }\n";
#}
 
 
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.

Latest revision as of 22:59, 2 March 2013

ancient

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.

documentation incomplete

The list is incomplete. E.g. SWAPLIST is available in FAI 4.0.6 ThomasNeumann 22:10, 2 March 2013 (UTC)