From 8992b353f5dec29dc32323eb3d483329318dfb46 Mon Sep 17 00:00:00 2001 From: Harald Hope Date: Mon, 18 Dec 2023 12:36:39 -0800 Subject: [PATCH] program data refactors --- pinxi | 95 +++++++++++++++++++++++------------------------------------ 1 file changed, 37 insertions(+), 58 deletions(-) diff --git a/pinxi b/pinxi index 858e33c..6f1df33 100755 --- a/pinxi +++ b/pinxi @@ -51,7 +51,7 @@ use POSIX qw(ceil uname strftime ttyname); my $self_name='pinxi'; my $self_version='3.3.31'; my $self_date='2023-12-16'; -my $self_patch='29'; +my $self_patch='30'; ## END INXI INFO ## my ($b_pledge,@pledges); @@ -78,7 +78,7 @@ my (%alerts,%build_prop,%client,%colors,,%cpuinfo_machine,%disks_bsd,%dboot, %risc,%service_tool,%show,%sysctl,%system_files,%usb,%windows); ## System Arrays -my (@app,@cpuinfo,@dmi,@ifs,@ifs_bsd,@paths,@ps_aux,@ps_cmd,@ps_gui, +my (@cpuinfo,@dmi,@ifs,@ifs_bsd,@paths,@ps_aux,@ps_cmd,@ps_gui, @sensors_exclude,@sensors_use,@uname); ## Disk/Logical/Partition/RAID arrays @@ -5958,7 +5958,8 @@ sub get_client_name { } } if ($b_log){ - my $string = "Client: $client{'name'} :: version: $client{'version'} :: konvi: $client{'konvi'} :: PPID: $ppid"; + my $string = "Client: $client{'name'} :: version: $client{'version'} ::"; + $string .= " konvi: $client{'konvi'} :: PPID: $ppid"; main::log_data('data', $string); } eval $end if $b_log; @@ -5966,7 +5967,7 @@ sub get_client_name { sub get_client_version { eval $start if $b_log; - @app = ProgramData::values($client{'name'}); + my @app = ProgramData::data($client{'name'}); my (@data,@working,$string); if (@app){ $string = ($client{'name'} =~ /^gribble|limnoria|supybot$/) ? 'supybot' : $client{'name'}; @@ -6041,9 +6042,8 @@ sub get_client_version { # (KSirc sucks anyway ;) foreach (@$cmdline){ if ($_ =~ /dsirc/){ - $client{'version'} = ProgramData::version('ksirc','KSirc:',2,'-v',0,0); $client{'name'} = 'ksirc'; - $client{'name-print'} = 'KSirc'; + ($client{'name-print'},$client{'version'}) = ProgramData::full('ksirc'); } } $client{'console-irc'} = 1; @@ -6109,6 +6109,7 @@ sub get_cmdline { sub perl_python_client { eval $start if $b_log; return 1 if $client{'version'}; + my @app; # this is a hack to try to show konversation if inxi is running but started via /cmd # OR via program shortcuts, both cases in fact now # main::print_line("konvi: " . scalar grep { $_ =~ /konversation/ } @ps_cmd); @@ -6152,7 +6153,8 @@ sub perl_python_client { $client{'name-print'} = "Unknown $client{'name'} client"; } if ($b_log){ - my $string = "namep: $client{'name-print'} name: $client{'name'} version: $client{'version'}"; + my $string = "namep: $client{'name-print'} name: $client{'name'} "; + $string .= " version: $client{'version'}"; main::log_data('data',$string); } eval $end if $b_log; @@ -6185,7 +6187,7 @@ sub check_modern_konvi { } # print "$pid $konvi\n"; if ($konvi){ - @app = ProgramData::values('konversation'); + my @app = ProgramData::values('konversation'); $konvi_version = ProgramData::version($konvi,$app[0],$app[1],$app[2],$app[5],$app[6]); $client{'console-irc'} = $app[4]; $client{'konvi'} = 3; @@ -28283,7 +28285,7 @@ sub get_compiler_data { (my $name,$compiler_version) = ProgramData::full($compiler,$program); } if ($extra > 1){ - # glob /usr/bin for gccs, strip out all non numeric values + # glob /usr/bin,/usr/local/bin for ccs, strip out all non numeric values if (my @temp = globber("/usr/{local/,}bin/${compiler}{-,}[0-9]*")){ # usually like gcc-11 but sometimes gcc-11.2.0 foreach (@temp){ @@ -28712,7 +28714,8 @@ sub get_kde_trinity_data { $desktop->[0] = 'KDE Plasma'; } if (!$desktop->[1]){ - $desktop->[1] = ($kde_session_version) ? $kde_session_version : main::message('unknown-desktop-version'); + $desktop->[1] = ($kde_session_version) ? + $kde_session_version : main::message('unknown-desktop-version'); } # print Data::Dumper::Dumper \@version_data; if ($extra > 1){ @@ -28814,9 +28817,7 @@ sub get_env_xprop_gnome_based_data { my %versions = ('mate-about' => '','mate-session' => ''); foreach my $key (keys %versions){ if ($program = main::check_program($key)){ - @data = ProgramData::full($key,$program,0); - $desktop->[0] = $data[0]; - $versions{$key} = $data[1]; + ($desktop->[0],$versions{$key}) = ProgramData::full($key,$program,0); } } # no consistent rule about which version is higher, so just compare them and take highest @@ -30702,9 +30703,8 @@ sub get_linux_distro { } elsif ($etc_issue){ if (-d '/etc/guix' && $lc_issue =~ /^this is the gnu system\./){ - $distro = 'Guix'; - # They didn't use any standard paths or files for os data, sigh, use pm version - my $version = ProgramData::version('guix', '^guix', '4','--version',1); + # No standard paths or files for os data, use pm version + ($distro,my $version) = ProgramData::full('guix'); $distro .= " $version" if $version; $b_skip_issue = 1; } @@ -33933,6 +33933,7 @@ sub set_values { 'irssi-text' => ['irssi',2,'-v','Irssi',1,1,0,'',''], 'konversation' => ['konversation',2,'-v','Konversation',0,0,0,'',''], 'kopete' => ['Kopete',2,'-v','Kopete',0,0,0,'',''], + 'ksirc' => ['KSirc',2,'-v','KSirc',0,0,0,'',''], 'kvirc' => ['[0-9.]+',2,'-v','KVIrc',0,0,1,'',''], # special 'pidgin' => ['[0-9.]+',2,'-v','Pidgin',0,1,0,'',''], 'quassel' => ['',1,'-v','Quassel [M]',0,0,0,'',''], # special @@ -34273,6 +34274,8 @@ sub set_values { 'upstart' => ['upstart',3,'--version','Upstart',0,1,0,'',''], ## Tools: Miscellaneous ## 'sudo' => ['^Sudo',3,'-V','Sudo',1,1,0,'',''], # sudo pre 1.7 does not have --version + ## Tools: Package Managers ## + 'guix' => ['^guix',4,'--version','Guix',0,1,0,'',''], # used for distro ID ); } @@ -34850,7 +34853,7 @@ my $b_debug = 0; # disable all debugger output in case forget to comment out! # fine, that's what it is. sub set { eval $start if $b_log; - my ($cmd,$parent,$pppid,$shell); + my (@app,$cmd,$parent,$pppid,$shell); $loaded{'shell-data'} = 1; $cmd = "ps -wwp $ppid -o comm= 2>/dev/null"; $shell = qx($cmd); @@ -36790,49 +36793,25 @@ sub info_item { } } if ($extra > 0){ - my ($clang,$clang_alt,$gcc,$gcc_alt,$path,$zigcc,$zigcc_alt); - my $clangs = main::get_compiler_data('clang'); - if (@$clangs){ - $clang = shift @$clangs; - if ($extra > 1 && @$clangs){ - $clang_alt = join('/', @$clangs); - } - $clang ||= 'N/A'; # should not be needed after fix but leave in case undef - } - my $gccs = main::get_compiler_data('gcc'); - if (@$gccs){ - $gcc = shift @$gccs; - if ($extra > 1 && @$gccs){ - $gcc_alt = join('/', @$gccs); - } - $gcc ||= 'N/A'; # should not be needed after fix but leave in case undef - } - my $zigccs = main::get_compiler_data('zigcc'); - if (@$zigccs){ - $zigcc = shift @$zigccs; - if ($extra > 1 && @$zigccs){ - $zigcc_alt = join('/', @$zigccs); - } - $zigcc ||= 'N/A'; # should not be needed after fix but leave in case undef - } - my $compiler = ($gcc || $clang || $zigcc) ? '': 'N/A'; - $data->{$data_name}[$index]{main::key($num++,1,1,'Compilers')} = $compiler; - if ($clang){ - $data->{$data_name}[$index]{main::key($num++,0,2,'clang')} = $clang; - if ($extra > 1 && $clang_alt){ - $data->{$data_name}[$index]{main::key($num++,0,3,'alt')} = $clang_alt; + my (%cc,$path); + foreach my $compiler (qw(clang gcc zigcc)){ + my $comps = main::get_compiler_data($compiler); + if (@$comps){ + $cc{$compiler}->{'version'} = shift @$comps; + if ($extra > 1 && @$comps){ + $cc{$compiler}->{'alt'} = join('/', @$comps); + } + $cc{$compiler}->{'version'} ||= 'N/A'; # should not be needed after fix but leave in case undef } } - if ($gcc){ - $data->{$data_name}[$index]{main::key($num++,1,2,'gcc')} = $gcc; - if ($extra > 1 && $gcc_alt){ - $data->{$data_name}[$index]{main::key($num++,0,3,'alt')} = $gcc_alt; - } - } - if ($zigcc){ - $data->{$data_name}[$index]{main::key($num++,1,2,'zigcc')} = $zigcc; - if ($extra > 1 && $zigcc_alt){ - $data->{$data_name}[$index]{main::key($num++,0,3,'alt')} = $zigcc_alt; + my $cc_value = ($cc{'clang'} || $cc{'gcc'} || $cc{'zigcc'}) ? '': 'N/A'; + $data->{$data_name}[$index]{main::key($num++,1,1,'Compilers')} = $cc_value; + foreach my $compiler (qw(clang gcc zigcc)){ + if ($cc{$compiler}){ + $data->{$data_name}[$index]{main::key($num++,0,2,$compiler)} = $cc{$compiler}->{'version'}; + if ($extra > 1 && $cc{$compiler}->{'alt'}){ + $data->{$data_name}[$index]{main::key($num++,0,3,'alt')} = $cc{$compiler}->{'alt'}; + } } } }