diff options
author | Jacob Pipkin <j@dawnrazor.net> | 2012-12-06 23:13:29 -0600 |
---|---|---|
committer | Jacob Pipkin <j@dawnrazor.net> | 2012-12-06 23:13:29 -0600 |
commit | c83b0ab28c8c16a5aee9b51acf5bcc4e4382bfad (patch) | |
tree | 428146f4f87aaea34271230ce1f2f9f6b7ea8dec /sboremove | |
parent | f6bf4ba365c233da686c97f5f5d2b378998d1867 (diff) | |
download | sbotools-c83b0ab28c8c16a5aee9b51acf5bcc4e4382bfad.tar.xz |
first bit of sboremove rewrite - use a complex data structure to know which args are the "root" ones
Diffstat (limited to 'sboremove')
-rwxr-xr-x | sboremove | 122 |
1 files changed, 59 insertions, 63 deletions
@@ -52,11 +52,12 @@ show_usage and exit 0 unless exists $ARGV[0]; my $inst_names = get_inst_names (get_installed_sbos); -my @remove; +# ensure that all provided arguments are valid sbos +my @arguments; for my $sbo (@ARGV) { - if (get_sbo_location ($sbo)) { + if (get_sbo_location($sbo)) { if ($sbo ~~ @$inst_names) { - push @remove, $sbo; + push @arguments, $sbo; } else { say "$sbo is not installed"; } @@ -65,32 +66,70 @@ for my $sbo (@ARGV) { } } -my ($remove_queue, %required_by, %warnings, @confirmed); +my %sbos{$_} = [] for @arguments; +# wrapper to pull the list of requirements for a given sbo +# TODO: look at moving this into Lib.pm sub get_requires ($) { my $location = get_sbo_location (shift); - my $requires = get_from_info (LOCATION => $location, GET => 'REQUIRES') - if $location; - return $requires; + return get_from_info(LOCATION => $location, GET => 'REQUIRES') +} + +# populate the %sbos hash with requirements for each sbo +$sbos{$_} = get_requires $_ for keys $sbos; + +# clean the %sbos hash of anything that's already a hash key +while (my ($key, $val) = each %sbos) { + my @remove; + for my $key (keys @$val) { + push @remove, $key if $$val[$key] ~~ %sbos; + } + for my $rem (@remove) { + splice(@$val, $rem, 1); + $_-- for @remove; + } } +# now we have to go backwards - starting from the end, check every requirement +# to ensure that it's not already listed earlier. +for my $key (reverse %sbos) { + for my $sbo (@$key) { + # running out of var names, so prefix these with n for "next" + FIRST: while (my ($nkey, $nval) = each %sbos) { + # move on if we're looking at the same key we're starting with + next FIRST if $key == $nkey; + my @remove; + for my $key (keys @$nval) { + push @remove, $key if $key $$nval[$key] == $sbo; + } + for my $rem (@remove) { + splice(@$nval, $rem, 1) + $_-- for @remove; + } + } + } +} + +my ($remove_queue, %required_by, %warnings, @confirmed); + # Determine required by for all installed sbo's sub get_reverse_reqs () { FIRST: for my $inst (@$inst_names) { my $requires = get_requires $inst; next FIRST unless $$requires[0]; for my $req (@$requires) { - unless ( $req eq "%README%" ) { + unless ( $req eq '%README%' ) { push @{$required_by{$req}}, $inst if $req ~~ $inst_names; } } } } +get_reverse_reqs unless $no_reqs; + sub get_required_by ($) { my $sbo = shift; my @dep_of; - get_reverse_reqs unless keys %required_by > 0; if ( $required_by{$sbo} ) { for my $req_by (@{$required_by{$sbo}}) { unless ($req_by ~~ @confirmed) { @@ -103,9 +142,7 @@ sub get_required_by ($) { sub confirm_remove ($) { my $sbo = shift; - unless ($sbo ~~ @confirmed) { - push @confirmed, $sbo; - } + push @confirmed, @sbo unless $sbo ~~ @confirmed; } # Determine dependencies & warnings @@ -120,63 +157,22 @@ if ($no_reqs) { my @temp; if ($inst_names) { for my $sbo (@$remove_queue) { - if ($sbo ~~ $inst_names) { - push @temp, $sbo; - } + push @temp, $sbo if $sbo ~~ @$inst_names; } $remove_queue = \@temp; } -# Gather instructions from user -unless ($non_int) { - my ($req_by, $req_count, $cnf_count); - for my $pkg (@$remove_queue) { - $req_by = get_required_by $pkg; - $cnf_count = 0; - for my $val (@$req_by) { - if ( $val ~~ @confirmed ) { $cnf_count++; } - } - my $rootpkg = ($pkg ~~ @remove); - if ($cnf_count == @$req_by or $rootpkg or $alwaysask) { - say $pkg; - if ( @$req_by ) { - say "Required by: " . join(' ', @$req_by); - } else { - unless ($rootpkg) { - #Skip this prompt if the pkg in question was passed by user. - say "It appears $pkg will no longer be required on your system"; - } - } - if ( exists $warnings{$pkg} ) { - say "$pkg suggests you view its README before proceeding,"; - print "view now? [y] : "; - chomp(my $viewrm = <STDIN>); - if ($viewrm =~ /^[Yy]/) { - print "\n"; - my $locrm = get_sbo_location ($pkg); - $locrm .= '/README'; - open(README, '<', $locrm) or die "could not open $locrm"; - for my $line (<README>) { - print $line; - } - } - } - print "Remove $pkg? [n] : "; - chomp(my $userin = <STDIN>); - if ($userin =~ /^[Yy]/) { - confirm_remove $pkg; - say "* added $pkg to remove queue\n"; - } else { - say "* ignoring $pkg\n" - } - } - } -} else { - for my $sbo (@$remove_queue) { - confirm_remove $sbo; - } +if ($non_int) { + confirm_remove $_ for @$remove_queue; + goto CONFIRMED; } +for my $remove (@$remove_queue) { + my $required_by = get_required_by $remove; + + +CONFIRMED: + # Show remove queue my $remove_count = @confirmed; if ($remove_count) { |