diff options
author | stefan <stefan@FreeBSD.org> | 2008-03-26 02:55:30 +0800 |
---|---|---|
committer | stefan <stefan@FreeBSD.org> | 2008-03-26 02:55:30 +0800 |
commit | 782dc074181c19a13939733acb2e5cfa3475125a (patch) | |
tree | 848ddc115044a996c2f12c29c37a1520aefd9cdc /ports-mgmt | |
parent | 8ff530938a577113c624667ed12e07950e9c5eef (diff) | |
download | freebsd-ports-gnome-782dc074181c19a13939733acb2e5cfa3475125a.tar.gz freebsd-ports-gnome-782dc074181c19a13939733acb2e5cfa3475125a.tar.zst freebsd-ports-gnome-782dc074181c19a13939733acb2e5cfa3475125a.zip |
Update to 20080320:
Implement a "visual" mode, where the user is given the complete list of leaf
packages inside his editor. He can then remove packages by removing the lines in
the file, save and exit. The now missing packages will then be removed.
PR: 121910
Submitted by: Ulrich Spoerlein <uspoerlein@gmail.com>
Diffstat (limited to 'ports-mgmt')
-rw-r--r-- | ports-mgmt/pkg_cutleaves/Makefile | 2 | ||||
-rw-r--r-- | ports-mgmt/pkg_cutleaves/files/pkg_cutleaves | 107 | ||||
-rw-r--r-- | ports-mgmt/pkg_cutleaves/files/pkg_cutleaves.1 | 18 |
3 files changed, 101 insertions, 26 deletions
diff --git a/ports-mgmt/pkg_cutleaves/Makefile b/ports-mgmt/pkg_cutleaves/Makefile index b9a182005173..44289fd2610f 100644 --- a/ports-mgmt/pkg_cutleaves/Makefile +++ b/ports-mgmt/pkg_cutleaves/Makefile @@ -6,7 +6,7 @@ # PORTNAME= pkg_cutleaves -PORTVERSION= 20071021 +PORTVERSION= 20080320 CATEGORIES= ports-mgmt MASTER_SITES= # none DISTFILES= # none diff --git a/ports-mgmt/pkg_cutleaves/files/pkg_cutleaves b/ports-mgmt/pkg_cutleaves/files/pkg_cutleaves index ca52bbecefab..d2193eeeef96 100644 --- a/ports-mgmt/pkg_cutleaves/files/pkg_cutleaves +++ b/ports-mgmt/pkg_cutleaves/files/pkg_cutleaves @@ -1,4 +1,5 @@ #!/usr/bin/perl +# $Id$ # # Copyright (c) 2003 Stefan Walter <sw@gegenunendlich.de> # @@ -27,7 +28,7 @@ # Interactive script for deinstalling "leaf" packages # -# Syntax: pkg_cutleaves [-cFgLlRx] +# Syntax: pkg_cutleaves [-cFgLlRVx] # Options: # -c: Show comments, too; only works with '-l' (ignored otherwise) # -F: Fix package db after each deinstallation run (via 'pkgdb -F') @@ -35,8 +36,10 @@ # -L: Interpret exclude file as list of packages that *should* be installed # -l: List leaf packages only, don't ask if they should be deinstalled # -R: Autoprune new leaves +# -V: Visual mode, invoke $EDITOR # -x: Honor exclude list in $excludefile +use File::Temp qw/ tempfile /; use Getopt::Std; use strict; @@ -48,7 +51,7 @@ my $exclpattern; my %leavestokeep; my %opt; -getopts('cFgLlRx', \%opt); +getopts('cFgLlRVx', \%opt); set_excl_pattern(); # LIST MODE @@ -124,31 +127,89 @@ else { # Initialize counter for progress status $i = 1; - LEAVESLOOP: foreach my $leaf (sort keys %leaves) { - print "Package $i of $nleaves:\n"; - print "$leaf - $leaves{$leaf}\n"; - print "$leaf - [keep]/(d)elete/(f)lush marked pkgs/(a)bort? "; - # Get first character of input, without leading whitespace - my ($answer) = (lc(<STDIN>) =~ m/(\S)/); - if ($answer eq 'd') { - print "** Marking $leaf for removal.\n\n"; - $leavestocut{$leaf} = 1; + if ($opt{V}) { + # Write list, including descriptions out to temp file + my ($fh, $filename) = tempfile() or die "Can't create file: $!"; + print $fh "# Delete the lines whose packages you want removed.\n"; + print $fh "# Simply save and quit, when you are done.\n"; + print $fh "# There are $nleaves (new) leaf packages:\n"; + foreach my $leaf (sort keys %leaves) { + # XXX Calculate maximum length first instead of 40? + printf $fh "%-40s - %s\n", $leaf, $leaves{$leaf}; } - elsif ($answer eq 'f') { - print "\n"; - last LEAVESLOOP; + close($fh); + + # Invoke $EDITOR, vi if no EDITOR set + my $editor = ($ENV{'EDITOR'} eq "") ? "vi" : $ENV{'EDITOR'}; + system "$editor $filename"; + if ($? == -1) { + print "failed to execute: $!\n"; + unlink($filename); + exit 1; } - elsif ($answer eq 'a') { - print "\n"; - $opt{aborted} = 1; - last ROUND; + + # Read back and parse list, the diff to the original list will be removed + open($fh, $filename) or die "Can't reopen file: $!"; + while(<$fh>) { + next if $_ =~ m/\s*#/; + next if $_ =~ m/^\s*$/; + my ($leaf, $desc) = split(/\s/, $_, 2); + + if (defined $leaves{$leaf}) { + delete $leaves{$leaf}; + $leavestokeep{$leaf} = 1; + } else { + print "Package \"$leaf\" not known, skipping\n"; + } } - else { - print "** Keeping $leaf.\n\n"; - $leavestokeep{$leaf} = 1; + close($fh); + unlink($filename); + + exit 0 if (keys %leaves == 0); + # print the lists of packages which will be removed, due to + # typos in the editor, the user might have 'removed' a package + # he is still interested in. This batch mode, really should get a last + # confirmation from the user. + print "The following packages will be removed:\n"; + # XXX Use map here? + # XXX check empty hash FIXME + foreach my $leaf (sort keys %leaves) { + $leavestocut{$leaf} = 1; + print " $leaf\n"; } - $i++; - } # LEAVESLOOP + print "Are you sure? [yes]: "; + my ($answer) = (lc(<STDIN>) =~ /(\S)/o); + print "\n"; + exit 0 if $answer =~ /n/; + + # Fallthrough to actual package removal + } else { + LEAVESLOOP: foreach my $leaf (sort keys %leaves) { + print "Package $i of $nleaves:\n"; + print "$leaf - $leaves{$leaf}\n"; + print "$leaf - [keep]/(d)elete/(f)lush marked pkgs/(a)bort? "; + # Get first character of input, without leading whitespace + my ($answer) = (lc(<STDIN>) =~ m/(\S)/); + if ($answer eq 'd') { + print "** Marking $leaf for removal.\n\n"; + $leavestocut{$leaf} = 1; + } + elsif ($answer eq 'f') { + print "\n"; + last LEAVESLOOP; + } + elsif ($answer eq 'a') { + print "\n"; + $opt{aborted} = 1; + last ROUND; + } + else { + print "** Keeping $leaf.\n\n"; + $leavestokeep{$leaf} = 1; + } + $i++; + } # LEAVESLOOP + } AUTOPRUNE: # The -R switch jump # Initialize 'progress meter' diff --git a/ports-mgmt/pkg_cutleaves/files/pkg_cutleaves.1 b/ports-mgmt/pkg_cutleaves/files/pkg_cutleaves.1 index b184cf88ee73..10242df60708 100644 --- a/ports-mgmt/pkg_cutleaves/files/pkg_cutleaves.1 +++ b/ports-mgmt/pkg_cutleaves/files/pkg_cutleaves.1 @@ -1,6 +1,6 @@ .\" PKG_CUTLEAVES 1 "Jul 2003" FreeBSD .\" -.Dd July 27, 2003 +.Dd March 20, 2008 .Dt PKG_CUTLEAVES 1 .Os FreeBSD .Sh NAME @@ -8,7 +8,7 @@ .Nd deinstall 'leaf' packages .Sh SYNOPSIS .Nm -.Op Fl cFglRx +.Op Fl cFglRVx .Sh DESCRIPTION .Nm pkg_cutleaves finds installed @@ -67,6 +67,11 @@ leaf packages. List leaf packages only, one per line, and don't ask for anything to be deinstalled. .Pp +.It Fl V +Visual mode. Will compile a list of leaf packages and invoke the user's +.Ev EDITOR . +Lines or package names that are deleted in the editor will then be removed. +.Pp .It Fl R Autoprune mode. Automatically deinstall non-required packages on which the removed leaf packages depended. Will not remove packages on the @@ -132,6 +137,15 @@ will exclude all packages with names starting with .Fl g option. .El +.Sh ENVIRONMENT +The following environment variables will be used in visual mode: +.Bl -tag -width EDITOR +.It Ev EDITOR +The editor specified by the variable +.Ev EDITOR +will be invoked instead of the default editor +.Xr vi 1 . +.El .Sh SEE ALSO .Xr pkg_deinstall 1 , .Xr pkgdb 1 , |