Acme-Tools
view release on metacpan or search on metacpan
(@r,@a)
}
#cat Tools.pm|perl -I. /usr/local/bin/zsize -tp
#cat Tools.pm|perl -I. /usr/local/bin/zsize -tp -
#cat Tools.pm|perl -I. /usr/local/bin/zsize -tp Tools.pm
sub cmd_zsize {
my %o;
my @argv=opts("heEpts",\%o,@_);
my $stdin=!@argv || join(",",@argv) eq '-';
@argv=("/tmp/acme-tools.$$.stdin") if $stdin;
writefile($argv[0],join("",<STDIN>)) if $stdin;
my @prog=grep qx(which $_), qw(gzip bzip2 xz zstd brotli);
for my $f (@argv){
my $sf=-s$f;
print "--- $f does not exists\n" and next if !-e$f;
print "--- $f is not a file\n" and next if !-f$f;
print "--- $f ($sf b) is not readable\n" and next if !-r$f;
print "--- $sf b ".bytes_readable($sf)." ".($stdin?"-":$f)."\n";
next if !$sf;
my(@t,@s);
for my $prog (@prog){
next if !qx(which $prog);
my @l=1..9;
push @l,map"e$_",1..9 if $prog eq 'xz' and $o{e};
@l=map"e$_",1..9 if $prog eq 'xz' and $o{E};
@l=map 10+$_,@l if $prog eq 'zstd';
@l=map"q $_",3..11 if $prog eq 'brotli';
printf "%-6s",$prog;
push @t, $prog, [] if $o{t};
push @s, $prog, [] if $o{p} and $o{s};
for my $l (@l){ #level
my $t=time_fp();
my $b=qx(cat $f|$prog -$l|wc -c);
push@{$t[-1]},time_fp()-$t if $o{t};
push@{$s[-1]},$b if $o{p} and $o{s};
$o{p} ? printf("%9.1f%% ",100*$b/$sf)
:$o{h} ? printf("%10s ",bytes_readable($b))
: printf("%10d ",$b);
}
print "\n";
}
while(@s){
printf "%-6s",shift@s;
$o{h}?printf("%10s ",bytes_readable($_)):printf("%10d ",$_) for @{shift@s}; print "\n";
}
while(@t){
printf "%-6s",shift@t;
printf "%9.3fs ",$_ for @{shift@t}; print "\n";
}
}
unlink $argv[0] if $stdin;
}
sub cmd_rttop { die "rttop: not implemented here yet.\n" }
sub cmd_whichpm { die "whichpm: not implemented here yet.\n" } #-a (all, inkl VERSION og ls -l)
sub cmd_catal { die "catal: not implemented here yet.\n" } #-a (all, inkl VERSION og ls -l)
#todo: cmd_tabdiff (fra sonyk)
#todo: cmd_catlog (ala catal med /etc/catlog.conf, default er access_log)
=head1 DATABASE STUFF - NOT IMPLEMENTED YET
Uses L<DBI>. Comming soon...
$Dbh
dlogin
dlogout
drow
drows
drowc
drowsc
dcols
dpk
dsel
ddo
dins
dupd
ddel
dcommit
drollback
=cut
#my$dummy=<<'SOON';
sub dtype {
my $connstr=shift;
return 'SQLite' if $connstr=~/(\.sqlite|sqlite:.*\.db)$/i;
return 'Oracle' if $connstr=~/\@/;
return 'Pg' if 1==2;
die;
}
our($Dbh,@Dbh,%Sth);
our %Dbattr=(RaiseError => 1, AutoCommit => 0); #defaults
sub dlogin {
my $connstr=shift();
my %attr=(%Dbattr,@_);
my $type=dtype($connstr);
my($dsn,$u,$p)=('','','');
if($type eq 'SQLite'){
$dsn=$connstr;
}
elsif($type eq 'Oracle'){
($u,$p,$dsn)=($connstr=~m,(.+?)(/.+?)?\@(.+),);
}
elsif($type eq 'Pg'){
croak "todo";
}
else{
croak "dblogin: unknown database type for connection string $connstr\n";
}
$dsn="dbi:$type:$dsn";
push @Dbh, $Dbh if $Dbh; #local is better?
require DBI;
$Dbh=DBI->connect($dsn,$u,$p,\%attr); #connect_cached?
}
sub dlogout {
$Dbh->disconnect;
$Dbh=pop@Dbh if @Dbh;
}
sub drow {
( run in 0.624 second using v1.01-cache-2.11-cpan-140bd7fdf52 )