Created
September 28, 2014 09:41
-
-
Save mjrosenb/08a39b0ae394fdd2d1ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use 5.14.0; | |
use warnings; | |
use IPC::System::Simple qw(capture); | |
use Time::Piece; | |
use Time::Seconds; | |
use Data::Dumper; | |
my $max_age = ONE_WEEK; | |
my $install_log_by = parse_qlop(capture('qlop -Clq')); | |
my $removal_log_by = parse_qlop(capture('qlop -Cuq')); | |
my %installed = map { chomp; $_ => 1 } capture('qlist -CI'); | |
my $ignores_file="$ENV{'HOME'}/.probate_ignore"; | |
my @ignores = (-f $ignores_file) ? do { open my $fh, "<", $ignores_file; <$fh> } : (); | |
my %ignore_set = map { chomp; print "ignoring $_"; $_ => 1 } @ignores; | |
print Dumper \%ignore_set; | |
my @candidates; | |
for my $atom (keys %$install_log_by) { | |
if (! $installed{$atom}) { | |
$ignore_set{$atom} = 0 if $ignore_set{$atom}; | |
next | |
} | |
for my $epoch (@{ $install_log_by->{$atom} }) { | |
if (! grep { abs($epoch - $_) <= 60 } @{ $removal_log_by->{$atom} }) { | |
$ignore_set{$atom} = 2 if $ignore_set{$atom}; | |
push @candidates, $atom if !$ignore_set{$atom} && ! length capture("qdepends -Q $atom"); | |
} | |
} | |
} | |
for my $atom (@candidates) { | |
print "$atom was newly installed (within last $max_age seconds)\n"; | |
} | |
open my $fh, ">", "$ENV{'HOME'}/.probate_ignore.tmp" or die $!; | |
for my $atom (keys %ignore_set) { | |
$fh->print($atom) if $ignore_set{$atom} == 2; | |
} | |
close $fh; | |
rename "$ENV{'HOME'}/.probate_ignore.tmp", $ignores_file or die $!; | |
sub parse_qlop { | |
my %log_by; | |
for my $line (reverse @_) { | |
$line =~ m/^(.+) (?:<<<|>>>) (.+)$/ or next; | |
my ($date, $atom) = ($1, $2); | |
my $then = Time::Piece->strptime($date, '%a %b %d %T %Y'); | |
my $now = Time::Piece->new; | |
last if ($then < $now - $max_age); | |
unshift @{ $log_by{$atom} }, $then->epoch; | |
} | |
return \%log_by; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment