From 1f011bf405bb60ddc4f86fb9a636eafe944cb16c Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Wed, 3 Mar 2021 20:05:32 -0700 Subject: [PATCH] lint-all-readme.pl: switch to Girocco::CLIUtil::Progress Remove original Progress class code in favor of the new version now located in Girocco/CLIUtil.pm. Take advantage of the new emit method at the same time. Signed-off-by: Kyle J. McKay --- toolbox/lint-all-readme.pl | 90 +++------------------------------------------- 1 file changed, 5 insertions(+), 85 deletions(-) diff --git a/toolbox/lint-all-readme.pl b/toolbox/lint-all-readme.pl index d22558d..5965063 100755 --- a/toolbox/lint-all-readme.pl +++ b/toolbox/lint-all-readme.pl @@ -20,81 +20,6 @@ use Girocco::CLIUtil; use Girocco::Project; my $bn; BEGIN {$bn = basename(__FILE__)} -{package Progress; - -use Time::HiRes qw(gettimeofday); - -sub fractime() { return scalar(gettimeofday) } - -sub new { - my $class = shift || __PACKAGE__; - my $max = shift; - defined($max) or $max = 100; - my $title = shift; - defined($title) or $title = "Progress"; - return bless { - title => $title, - max => $max, - cur => 0, - len => 0, - lastupd => fractime + 2 - }, $class; -} - -sub update { - my $self = shift; - !$self->{max} and return; - my $newcur = shift; - defined($newcur) or $newcur = $self->{cur} + 1; - $newcur > $self->{max} and $newcur = $self->{max}; - $newcur >= $self->{cur} or $newcur = $self->{cur}; - my $now = fractime; - if ($self->{lastupd} + 1 <= $now) { - $self->{lastupd} = $now; - if (!$self->{len} || $self->{cur} != $newcur) { - $self->{cur} = $newcur; - $self->show; - } - } -} - -sub show { - my $self = shift; - delete $self->{wasvis}; - !$self->{max} and return; - my $p = int((100 * $self->{cur} / $self->{max}) + 0.5); - $p > 100 and $p = 100; - $p == 100 && $self->{cur} < $self->{max} and $p = 99; - my $status = sprintf("%s: %3d%% (%d/%d)", $self->{title}, - $p, $self->{cur}, $self->{max}); - my $newlen = length($status); - $self->{len} > $newlen and $status .= " " x ($self->{len} - $newlen); - $status .= "\r"; - print STDERR $status; - $self->{len} = $newlen; -} - -sub clear { - my $self = shift; - if ($self->{len}) { - print STDERR " " x $self->{len}, "\r"; - $self->{len} = 0; - $self->{wasvis} = 1; - } -} - -sub restore { - my $self = shift; - $self->{wasvis} and $self->show; -} - -sub DESTROY { - my $self = shift; - $self->clear; -} - -}# END package Progress - exit(&main(@ARGV)||0); our $help; @@ -114,13 +39,13 @@ sub lint_project_readmes { my @outdated = (); my @badlint = (); my $bd = $Girocco::Config::reporoot . '/'; - my $progress = Progress->new($show_progress ? scalar(@allprojs) : 0, + my $progress = Girocco::CLIUtil::Progress->new( + $show_progress ? scalar(@allprojs) : 0, "Checking project readme files"); my $cnt = 0; foreach (@allprojs) { ++$cnt; $progress->update($cnt); - $progress->restore; my $pd = $bd . $_ . '.git'; -d $pd or next; # just ignore any phantoms my $proj = undef; @@ -132,26 +57,23 @@ sub lint_project_readmes { my ($cnt, $err) = $proj->_lint_readme(0); if ($cnt) { push(@badlint, $_); - $progress->clear; - chomp($err); - print "$_: error: $err\n"; + $progress->emit("$_: error: $err"); next; } my $newreadme = $proj->{README}; defined($newreadme) or $newreadme = ""; chomp($newreadme); $readme eq $newreadme and next; - $progress->clear; if ($dryrun) { push(@outdated, $_); - print "$_: needs update\n"; + $progress->emit("$_: needs update"); } else { push(@outdated, $_); $proj->_property_fput("READMEDATA", $proj->{READMEDATA}, 1); $proj->_property_fput("README", $proj->{README}, -e "$pd/README.html"); $proj->_property_fput("rmtype", $proj->{rmtype}, 1); $proj->_set_changed; - print "$_: updated\n"; + $progress->emit("$_: updated"); } } return {count => scalar(@allprojs), outdated => \@outdated, @@ -177,8 +99,6 @@ sub main { shift, $progress=0, redo if @ARGV && $ARGV[0] =~ /^(?:--no-progress)$/i; } !@ARGV && !$help or dohelp($help ? \*STDOUT : \*STDERR, !$help); - select((select(STDERR),$|=1)[0]); - select((select(STDOUT),$|=1)[0]); my $results = lint_project_readmes(!!$dryrun, $progress); printf "Total: %d %s: %d Lintfail: %d\n", $results->{count}, -- 2.11.4.GIT