From c99a629e8e6b8d91c333f0e0bd7e4f04c33c84e8 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Fri, 5 Mar 2021 22:38:43 -0700 Subject: [PATCH] update-all-config.pl: add nice progress indicator Use the new Girocco::CLIUtil::Progress class to add a nice progress indicator to the output. Also sneak in a tiny change to make the project sort order stable. Signed-off-by: Kyle J. McKay --- toolbox/update-all-config.pl | 65 ++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/toolbox/update-all-config.pl b/toolbox/update-all-config.pl index 15356cd..9e3fee3 100755 --- a/toolbox/update-all-config.pl +++ b/toolbox/update-all-config.pl @@ -61,6 +61,9 @@ BEGIN { my $owning_group_id; my $htmlcache_owning_group_id; my $ctags_owning_group_id; +my $progress; + +sub pwarn { $progress->warn(@_) } sub main { local *ARGV = \@_; @@ -129,31 +132,35 @@ sub main { push(@projects, $_); } } else { - @projects = sort {lc($a) cmp lc($b)} @allprojs; + @projects = sort {lc($a) cmp lc($b) || $a cmp $b} @allprojs; } nice_me(18); my $bad = 0; + $progress = Girocco::CLIUtil::Progress->new(scalar(@projects), + "Updating config files"); + my $pcnt = 0; foreach (@projects) { my $projdir = "$root/$_.git"; if (! -d $projdir) { - warn "$_: does not exist -- skipping\n" unless $quiet; + pwarn "$_: does not exist -- skipping\n" unless $quiet; next; } if (!is_git_dir($projdir)) { - warn "$_: is not a .git directory -- skipping\n" unless $quiet; + pwarn "$_: is not a .git directory -- skipping\n" unless $quiet; next; } if (-e "$projdir/.noconfig") { - warn "$_: found .noconfig -- skipping\n" unless $quiet; + pwarn "$_: found .noconfig -- skipping\n" unless $quiet; next; } if (!chdir($projdir)) { - warn "$_: chdir to project directory failed: $!\n" unless $quiet; + pwarn "$_: chdir to project directory failed: $!\n" unless $quiet; next; } process_one_project($_) or $bad = 1; - } + } continue {$progress->update(++$pcnt)} + $progress = undef; return $bad ? 1 : 0; } @@ -200,7 +207,7 @@ sub openfind_ { POSIX::dup2(fileno($duperr), 2); close($duperr); } - $ans or die "find failed: $!\n"; + $ans or die "\nfind failed: $!\n"; return $fd; } @@ -259,7 +266,7 @@ sub process_one_project do { if (! -d $_) { if (-e $_) { - warn "$proj: bypassing project, exists but not directory: $_\n" unless $quiet; + pwarn "$proj: bypassing project, exists but not directory: $_\n" unless $quiet; $reallybad = $bad = 1; last; } else { @@ -291,7 +298,7 @@ sub process_one_project do { if (-e $_) { if (! -f $_) { - warn "$proj: bypassing project, exists but not file: $_\n" unless $quiet; + pwarn "$proj: bypassing project, exists but not file: $_\n" unless $quiet; $reallybad = $bad = 1; last; } @@ -310,7 +317,7 @@ sub process_one_project $dryrun || check_fperm($proj, "config") or $bad = 1; my $config = read_config_file_hash("config", !$quiet); if (!defined($config)) { - warn "$proj: could not read config file -- skipping\n" unless $quiet; + pwarn "$proj: could not read config file -- skipping\n" unless $quiet; return 0; } @@ -436,7 +443,7 @@ sub process_one_project foreach (@fixfpermsfiles) { if (-e $_) { if (! -f $_) { - warn "$proj: bypassing project, exists but not file: $_\n" unless $quiet; + pwarn "$proj: bypassing project, exists but not file: $_\n" unless $quiet; $reallybad = $bad = 1; last; } @@ -495,10 +502,10 @@ sub do_mkdir } elsif ($info[5] != $grpid) { if (!chown($info[4], $grpid, $subdir)) { $result = "FAILED"; - warn "chgrp: ($proj) $subdir: $!\n" unless $quiet; + pwarn "chgrp: ($proj) $subdir: $!\n" unless $quiet; } elsif (!chmod($info[2] & 07777, $subdir)) { $result = "FAILED"; - warn "chmod: ($proj) $subdir: $!\n" unless $quiet; + pwarn "chmod: ($proj) $subdir: $!\n" unless $quiet; } } } @@ -513,7 +520,7 @@ sub check_dperm { my ($proj, $subdir) = @_; my $oldmode = (stat($subdir))[2]; if (!defined($oldmode) || $oldmode eq "") { - warn "chmod: ($proj) $subdir: No such file or directory\n" unless $quiet; + pwarn "chmod: ($proj) $subdir: No such file or directory\n" unless $quiet; return 0; } my $newmode = ($oldmode & ~07777) | $dmode; @@ -522,7 +529,7 @@ sub check_dperm { if (!$dryrun) { if (!chmod($newmode & 07777, $subdir)) { $result = "FAILED"; - warn "chmod: ($proj) $subdir: $!\n" unless $quiet; + pwarn "chmod: ($proj) $subdir: $!\n" unless $quiet; } } else { $result = "(dryrun)"; @@ -535,7 +542,7 @@ sub change_dpermrwx { my ($proj, $subdir) = @_; my $oldmode = (stat($subdir))[2]; if (!defined($oldmode) || $oldmode eq "") { - warn "chmod: ($proj) $subdir: No such file or directory\n" unless $quiet; + pwarn "chmod: ($proj) $subdir: No such file or directory\n" unless $quiet; return 0; } my $newmode = $oldmode | ($wall ? 0777 : 0775); @@ -544,7 +551,7 @@ sub change_dpermrwx { if (!$dryrun) { if (!chmod($newmode & 07777, $subdir)) { $result = "FAILED"; - warn "chmod: ($proj) $subdir: $!\n" unless $quiet; + pwarn "chmod: ($proj) $subdir: $!\n" unless $quiet; } } else { $result = "(dryrun)"; @@ -558,7 +565,7 @@ sub change_dpermrx { $subdir =~ s,^\./,,; my $oldmode = (stat($subdir))[2]; if (!defined($oldmode) || $oldmode eq "") { - warn "chmod: ($proj) $subdir: No such file or directory\n" unless $quiet; + pwarn "chmod: ($proj) $subdir: No such file or directory\n" unless $quiet; return 0; } my $newmode = $oldmode | 0555; @@ -567,7 +574,7 @@ sub change_dpermrx { if (!$dryrun) { if (!chmod($newmode & 07777, $subdir)) { $result = "FAILED"; - warn "chmod: ($proj) $subdir: $!\n" unless $quiet; + pwarn "chmod: ($proj) $subdir: $!\n" unless $quiet; } } else { $result = "(dryrun)"; @@ -580,7 +587,7 @@ sub check_fperm { my ($proj, $file) = @_; my $oldmode = (stat($file))[2]; if (!defined($oldmode) || $oldmode eq "") { - warn "chmod: ($proj) $file: No such file or directory\n" unless $quiet; + pwarn "chmod: ($proj) $file: No such file or directory\n" unless $quiet; return 0; } my $newmode = ($oldmode & ~07777) | $fmode; @@ -589,7 +596,7 @@ sub check_fperm { if (!$dryrun) { if (!chmod($newmode & 07777, $file)) { $result = "FAILED"; - warn "chmod: ($proj) $file: $!\n" unless $quiet; + pwarn "chmod: ($proj) $file: $!\n" unless $quiet; } } else { $result = "(dryrun)"; @@ -603,7 +610,7 @@ sub check_fpermr { $file =~ s,^\./,,; my $oldmode = (stat($file))[2]; if (!defined($oldmode) || $oldmode eq "") { - warn "chmod: ($proj) $file: No such file or directory\n" unless $quiet; + pwarn "chmod: ($proj) $file: No such file or directory\n" unless $quiet; return 0; } my $newmode = $oldmode | 0444; @@ -612,7 +619,7 @@ sub check_fpermr { if (!$dryrun) { if (!chmod($newmode & 07777, $file)) { $result = "FAILED"; - warn "chmod: ($proj) $file: $!\n" unless $quiet; + pwarn "chmod: ($proj) $file: $!\n" unless $quiet; } } else { $result = "(dryrun)"; @@ -626,7 +633,7 @@ sub check_fpermnox { $file =~ s,^\./,,; my $oldmode = (stat($file))[2]; if (!defined($oldmode) || $oldmode eq "") { - warn "chmod: ($proj) $file: No such file or directory\n" unless $quiet; + pwarn "chmod: ($proj) $file: No such file or directory\n" unless $quiet; return 0; } my $newmode = $oldmode & ~0111; @@ -635,7 +642,7 @@ sub check_fpermnox { if (!$dryrun) { if (!chmod($newmode & 07777, $file)) { $result = "FAILED"; - warn "chmod: ($proj) $file: $!\n" unless $quiet; + pwarn "chmod: ($proj) $file: $!\n" unless $quiet; } } else { $result = "(dryrun)"; @@ -649,7 +656,7 @@ sub change_group { $item =~ s,^\./,,; my @info = stat($item); if (@info < 6 || $info[2] eq "" || $info[4] eq "" || $info[5] eq "") { - warn "chgrp: ($proj) $item: No such file or directory\n" unless $quiet; + pwarn "chgrp: ($proj) $item: No such file or directory\n" unless $quiet; return 0; } $info[5] == $grpid and return 1; @@ -657,10 +664,10 @@ sub change_group { if (!$dryrun) { if (!chown($info[4], $grpid, $item)) { $result = "FAILED"; - warn "chgrp: ($proj) $item: $!\n" unless $quiet; + pwarn "chgrp: ($proj) $item: $!\n" unless $quiet; } elsif (!chmod($info[2] & 07777, $item)) { $result = "FAILED"; - warn "chmod: ($proj) $item: $!\n" unless $quiet; + pwarn "chmod: ($proj) $item: $!\n" unless $quiet; } } else { $result = "(dryrun)"; @@ -680,7 +687,7 @@ sub pmsg { $prefix = $wrote . $proj . ":\n"; $hdr = 1; } - print $prefix, " ", join(' ', @_), "\n"; + $progress->emit($prefix . " " . join(' ', @_) . "\n"); $wrote = "\n"; } -- 2.11.4.GIT