diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2005-02-17 13:25:11 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2005-02-17 13:25:11 +0000 |
commit | c3047f667361d9f7726a996c2363cf8fd77e461e (patch) | |
tree | 371bd77393dea099a5f03e9a2c5fb2bd9fc2f47b /perl-install/detect_devices.pm | |
parent | f2242e8ab84506cad5759294bf165fa8cc72a1da (diff) | |
download | drakx-c3047f667361d9f7726a996c2363cf8fd77e461e.tar drakx-c3047f667361d9f7726a996c2363cf8fd77e461e.tar.gz drakx-c3047f667361d9f7726a996c2363cf8fd77e461e.tar.bz2 drakx-c3047f667361d9f7726a996c2363cf8fd77e461e.tar.xz drakx-c3047f667361d9f7726a996c2363cf8fd77e461e.zip |
- create dmidecode_category()
- don't use field {string} when not needed
- better use regexps on dmidecode returned strings (even the kernel use strstr)
Diffstat (limited to 'perl-install/detect_devices.pm')
-rw-r--r-- | perl-install/detect_devices.pm | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/perl-install/detect_devices.pm b/perl-install/detect_devices.pm index 158a212cb..165b7a6b8 100644 --- a/perl-install/detect_devices.pm +++ b/perl-install/detect_devices.pm @@ -794,34 +794,38 @@ my (@dmis, $dmidecode_already_runned); # we return a list b/c several DMIs have the same name: sub dmidecode() { - return @dmis if $dmidecode_already_runned; - - foreach (run_program::get_stdout('dmidecode')) { - if (/^\t\t(.*)/) { - $dmis[-1]{string} .= "$1\n"; - $dmis[-1]{$1} = $2 if /^\t\t(.*): (.*)$/; - } elsif (my ($s) = /^\t(.*)/) { - next if $s =~ /^DMI type /; - $s =~ s/ Information$//; - push @dmis, { name => $s }; - } + return @dmis if $dmidecode_already_runned; + + foreach (run_program::get_stdout('dmidecode')) { + if (/^\t\t(.*)/) { + $dmis[-1]{string} .= "$1\n"; + $dmis[-1]{$1} = $2 if /^\t\t(.*): (.*)$/; + } elsif (my ($s) = /^\t(.*)/) { + next if $s =~ /^DMI type /; + $s =~ s/ Information$//; + push @dmis, { name => $s }; } - $dmidecode_already_runned = 1; + } + $dmidecode_already_runned = 1; @dmis; } +sub dmidecode_category { + my ($cat) = @_; + my @l = find { $_->{name} eq $cat } dmidecode(); + wantarray() ? @l : $l[0] || {}; +} sub computer_info() { - my @l = dmidecode(); - my $chassis = (find { $_->{name} eq 'Chassis' } @l) || { string => '' }; - my $Chassis = $chassis->{string} =~ /^Type:\s*(\S+)/m && $1; - my $BIOS = (find { $_->{name} eq 'BIOS' } @l) || { string => '' }; - my $BIOS_Year = $BIOS->{string} =~ m!^Release Date:.*?(\d{4})!m && $1 || - $BIOS->{string} =~ m!^Release Date:.*?\d\d/\d\d/(\d\d)!m && "20$1"; + my $Chassis = dmidecode_category('Chassis')->{Type} =~ /(\S+)/ && $1; + + my $date = dmidecode_category('BIOS')->{'Release Date'} || ''; + my $BIOS_Year = $date =~ m!(\d{4})! && $1 || + $date =~ m!\d\d/\d\d/(\d\d)! && "20$1"; - +{ - isLaptop => member($Chassis, 'Portable', 'Laptop', 'Notebook', 'Sub Notebook', 'Docking Station'), - if_($BIOS_Year, BIOS_Year => $BIOS_Year), - }; + +{ + isLaptop => member($Chassis, 'Portable', 'Laptop', 'Notebook', 'Sub Notebook', 'Docking Station'), + if_($BIOS_Year, BIOS_Year => $BIOS_Year), + }; } #- try to detect a laptop, we assume pcmcia service is an indication of a laptop or |