From 1d0ea67ee55668ef1b35287a8573f602993b616c Mon Sep 17 00:00:00 2001 From: Will Budic Date: Thu, 25 Sep 2025 11:35:42 +1000 Subject: [PATCH] new release APP_SETTING revisited. --- apps/obtainLocalNetworkHistory.pl | 101 +++++++++++++++++++++++++++ system/modules/CNFParser.pm | 51 ++++++++++---- system/modules/ClassicAppSettings.pm | 52 +++++++++++--- 3 files changed, 179 insertions(+), 25 deletions(-) create mode 100644 apps/obtainLocalNetworkHistory.pl diff --git a/apps/obtainLocalNetworkHistory.pl b/apps/obtainLocalNetworkHistory.pl new file mode 100644 index 0000000..19ca955 --- /dev/null +++ b/apps/obtainLocalNetworkHistory.pl @@ -0,0 +1,101 @@ +#!/usr/bin/env perl +use v5.38; +use warnings; use strict; +use Syntax::Keyword::Try; +use Benchmark; +use Getopt::Long qw(Configure); +use lib 'system/modules'; + +require ClassicAppSettings; ClassicAppSettings::_set_defaults( + APP_NAME => "Local Network Histories App", + APP_CONFIG_DIR => $ENV{HOME}.'/.config/PerlCNF' + ); +require CNFParser; +require CNFSQL; +require DatabaseCentralPlugin; + +our $VERSION = 1.0; + +try{ +our $CNF = CNFParser->new(undef,{DO_ENABLED=>1,'%LOG'=>{console=>1}}); +our $config = do {local $/;}; $CNF -> parse(undef, $config); +our $SQL = $CNF->SQL(); + + +Configure( "default", "pass_through", "bundling_override", "require_order","auto_version"); +my $result = GetOptions( + "help|h|?" => \&help, +); +&main; + +sub main{ + my $target = '/tmp/'.($0 =~ m/(\w+)\.pl$/g)[0].'.result'; + my $central = $CNF->property('DB_CENTRAL')->{plugin}; + my $db = $$central-> centralDBConnect(); + $SQL->initDatabase($db); + my $pstRows = $SQL->selectRecords($db,$SQL->{selectByLongest_50_CMDs}); + + open(my $fh, '|-', "fzf > $target") or die "Couldn't open a pipe into FZF: $!"; + while (my @row=$pstRows->fetchrow_array()){ + print $fh decodeQuotes($row[0])."\n" + } + close($fh); + + my $command = `cat $target`; + + print $command + +} +}catch{ + ClassicAppSettings::_stack_trace($@); + exit 0; +} + + +sub encodeQuotes{ + my $ret = shift; $ret =~ s/\s*$//g; + $ret =~ s/\"/\"\"/g; $ret =~ s/\'/\'\'/g; $ret =~ s/\\n/%/g; + $ret =~ s/\\n/\\\\n/g; + return $ret +} +sub decodeQuotes{ + my $ret = shift; + $ret =~ s/\"\"/\"/g; $ret =~ s/\'\'/\'/g; #$ret =~ s/\\\\/\\/g; + $ret =~ s/\\n/%/g; + return $ret +} + +sub help{ + +} + +=begin copyright +Programed by : Will Budić +EContactHash : 990MWWLWM8C2MI8K (https://lifelog.hopto.org/gitweb/?p=PerlCNF.git;a=blob_plain;f=EContactHash.md;hb=HEAD) +Source : git clone git://lifelog.hopto.org/PerlCNF + This source file is copied and usually placed in a local directory, outside of its repository project. + So it could not be the actual or current version, can vary or has been modified for what ever purpose in another project. + Please leave source of origin in this file for future references. +Open Source Code License -> https://lifelog.hopto.org/gitweb/?p=PerlCNF.git;a=blob_plain;f=ISC_License.md;hb=HEAD +=cut copyright + + +__END__ +__DATA__ +# App Settings are also environmental variables. Which if set overwrite this ones here seen as second priority. +<<>> +# Get the local network config file for this script and load it. +<<>> + +## +# This is like a server side View, arguably slower as only an select statement. +## +< +SELECT "CMD", LENGTH("CMD") as len + FROM public.cmd_history WHERE LENGTH("CMD") > 3 +ORDER BY len DESC LIMIT 500; +>> + + diff --git a/system/modules/CNFParser.pm b/system/modules/CNFParser.pm index 5ab9d59..3e355d7 100644 --- a/system/modules/CNFParser.pm +++ b/system/modules/CNFParser.pm @@ -22,7 +22,7 @@ require CNFDateTime; ##no critic qw(Subroutines::RequireFinalReturn) ##no critic Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions -use constant VERSION => '3.3.4'; +use constant VERSION => '3.3.5'; use constant APP_STS => 'APP_SETTINGS'; use constant APP_ARGS => 'ARGUMENTS'; our @files; @@ -670,15 +670,38 @@ sub doInstruction { my ($self,$e,$t,$v,$is_tagged) = @_; sub doLoadDataFile { my ($self,$e,$v)=@_; my ($path,$cnf_file) = ("",$self->{CNF_CONTENT}); $v=~s/\s+//g; - if ($v eq '$0'){ - $path = $0; $path =~ m/.*\/(.*)\..*$/ ; $path = $ENV{HOME}."/.config/$1.cnf"; + if($v=~m/^\*(.*)\*\/(.*)/){ + my $link = $1; $v = $2; + my $translation; + foreach(split '/', $link){ + my $prp = $self->property($_); + if($prp){ + $translation = $prp; + next + }elsif($translation){ + $translation = $translation -> {$_}; + } + } + if ($v eq '$0'){ + $path = $0; $path =~ m/.*\/(.*)\..*$/ ; + if($translation){ + $path = $translation ."/$1.cnf"; + }else{ + $path = $ENV{HOME}."/.config/$1.cnf"; + } + + }elsif($translation){ + $path = $translation .'/'. $v; + } + if( -e $path ){ - $self ->parse($path) + $self ->parse($path) }else{ - $self->warn("Skipping conventional local config file is missing: $path") + $self->warn("Skipping conventional local config file is missing: $path") } - return; - } + + + } elsif(! -e $v){ $path = substr($path, 0, rindex($cnf_file,'/')) .'/'.$v; }else{ @@ -1479,7 +1502,7 @@ sub doPlugin { my $prp = $plugin->{property}; my $sub = $plugin->{subroutine}; if($instructor eq APP_STS){ - $pck = 'ClassicAPP_STStings' if ! $pck; + $pck = 'ClassicAppSettings' if ! $pck; ## no critic (RequireBarewordIncludes) require "$pck.pm"; my $obj = $pck -> new($plugin); @@ -1654,11 +1677,11 @@ sub log { my %log = $self -> property('%LOG'); my $time = CNFDateTime -> now(exists($self->{TZ})?{TZ=>$self->{TZ}}:undef) -> toTimestamp(); - $message = "$type "."\e[33m".$message."[0m" if $isWarning; + $message = "$type "."\e[33m".$message."\e[0m" if $isWarning; $message = "" if not $message; if($message =~ /^ERROR/ || ($isWarning && $self->{ENABLE_WARNINGS})){ $message =~ s/(\s+line\s)(\d+)\.*\s+/:$2\n/gm; - warn $time . " " .$message; + print $time . " " .$message; } elsif(%log && $log{console}){ print $time . " " .$message ."\n" @@ -1801,19 +1824,19 @@ undef %properties; undef %lists; undef %instructors; } -1; + =begin copyright Programed by : Will Budić EContactHash : 990MWWLWM8C2MI8K (https://github.com/wbudic/EContactHash.md) Source : git clone git://lifelog.hopto.org/PerlCNF : https://github.com/wbudic/PerlCNF.git -Documentation : Specifications_For_CNF_ReadMe.md +Documentation : https://lifelog.hopto.org/gitweb/?p=PerlCNF.git;a=blob;f=Specifications_For_CNF_ReadMe.md;hb=HEAD This source file is copied and usually placed in a local directory, outside of its repository project. So it could not be the actual or current version, can vary or has been modified for what ever purpose in another project. Please leave source of origin in this file for future references. -Open Source Code License -> https://github.com/wbudic/PerlCNF/blob/master/ISC_License.md +Open Source Code License -> https://lifelog.hopto.org/gitweb/?p=PerlCNF.git;a=blob_plain;f=ISC_License.md;hb=HEAD =cut copyright - +1; __END__ ## Instructions & Reserved words diff --git a/system/modules/ClassicAppSettings.pm b/system/modules/ClassicAppSettings.pm index ff21a13..24926db 100644 --- a/system/modules/ClassicAppSettings.pm +++ b/system/modules/ClassicAppSettings.pm @@ -27,7 +27,7 @@ package ClassicAppSettings; use strict;use warnings; -use feature qw(signatures); +use feature qw(signatures say); use constant VERSION => '1.0'; @@ -35,7 +35,7 @@ our %global_defaults; our $gl_clone_constances = 0; sub _set_defaults(%defaults){ - %global_defaults = %defaults + %global_defaults = %defaults; } sub _set_clone_constances(){ $gl_clone_constances = 1 @@ -75,10 +75,10 @@ sub setConstant($this, $config, $CONSTANT){ # APP_SETTINGS_SYNC == 1 - Scripted setting not found as an default. # APP_SETTINGS_SYNC == 2 - New Setting in script not declared. # APP_SETTINGS_SYNC == 3 - Scripted setting changed from default. -# APP_SETTINGS_SYNC == 4 - Constance not programatically properly wired. +# APP_SETTINGS_SYNC == 4 - Constance not programmatically properly wired. # APP_SETTINGS_SYNC == 5 - Constance synched in, can't be changed with store synch. # APP_SETTINGS_SYNC == 6 - Added new during store synch. -# APP_SETTINGS_SYNC == 7 - Changed from scipt default during store synch.. +# APP_SETTINGS_SYNC == 7 - Changed from script default during store synch.. ## sub setup_with($this, $config, %constants){ @@ -99,10 +99,10 @@ sub setup_with($this, $config, %constants){ $this->{$key} = $global_defaults{$key}; $sync_state{$key} = 2; }else{ - my $v = $global_defaults{$key}; + my $v = $global_defaults{$key}; if(not defined($this->{$key})){ $sync_state{$key} = 4; - $this->{$key} = $global_defaults{$key}; + $this->{$key} = $v; }elsif($this->{$key} ne $v){ #Default changed in script $sync_state{$key} = 3; @@ -113,7 +113,7 @@ sub setup_with($this, $config, %constants){ } ### # Must be called by obtainer of this, that also handles the store. -# Just befoer the App uses the settings. +# Just before the App uses the settings. ### sub sync_with($this, %store){ foreach my $key ( keys %store ) { @@ -127,15 +127,45 @@ sub sync_with($this, %store){ return \%sync_state; } +sub _stack_trace { + use Devel::StackTrace; + my $trace = $@->trace; + my $error = $@->error; +# CNFParser->new(undef,{DO_ENABLED=>1,'%LOG'=>{console=>1}})->error($exception -> {message}); + my $file = $@->file; + my $line = $@->line; + + + say "\e[31m$error\e[0m\nat $file:$line\n"; + my $next = $trace->next_frame; + my $package = $next-> subroutine; + while($next = $trace->next_frame){ + my $str = $next->as_string; + my $filename = $next->filename; + my $line = $next->line; + my $subroutine = $next->subroutine; + my @args_array = $next->args; + my $args; + foreach my $arg(@args_array){ + if($arg){ $args .= $arg.", " }else{ $arg .= "undef, " } + } + $args =~ s/,\s*$//g if $args; + say "\e[33m$package\e[0m <- \e[37m$subroutine\e[0m ($args)"; + say " at \e[32m$filename:$line\e[0m"; + $package = $subroutine; + } +} + + 1; +__END__ =begin copyright Programed by : Will Budić -EContactHash : 990MWWLWM8C2MI8K (https://github.com/wbudic/EContactHash.md) -Source : https://github.com/wbudic/PerlCNF.git -Documentation : Specifications_For_CNF_ReadMe.md +EContactHash : 990MWWLWM8C2MI8K (https://lifelog.hopto.org/gitweb/?p=PerlCNF.git;a=blob_plain;f=EContactHash.md;hb=HEAD) +Source : git clone git://lifelog.hopto.org/PerlCNF This source file is copied and usually placed in a local directory, outside of its repository project. So it could not be the actual or current version, can vary or has been modified for what ever purpose in another project. Please leave source of origin in this file for future references. -Open Source Code License -> https://github.com/wbudic/PerlCNF/blob/master/ISC_License.md +Open Source Code License -> https://lifelog.hopto.org/gitweb/?p=PerlCNF.git;a=blob_plain;f=ISC_License.md;hb=HEAD =cut copyright \ No newline at end of file -- 2.34.1