Talk:Variables

From FAIWiki
Revision as of 18:36, 1 August 2006 by OliverOsburg (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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:

  1. ! /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;

  1. 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;
   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); 

}

  1. Denn man es nicht im dumper format haben will
  2. foreach $var ( keys %variables ){
  3. print "$var:\t@{ $variables{$var} }\n";
  4. }


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.