From owner-freebsd-ports-bugs@FreeBSD.ORG Thu Mar 20 14:40:01 2008 Return-Path: Delivered-To: freebsd-ports-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 157CF1065679 for ; Thu, 20 Mar 2008 14:40:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id EC8C88FC36 for ; Thu, 20 Mar 2008 14:40:00 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m2KEe07m069992 for ; Thu, 20 Mar 2008 14:40:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m2KEe0Uo069991; Thu, 20 Mar 2008 14:40:00 GMT (envelope-from gnats) Resent-Date: Thu, 20 Mar 2008 14:40:00 GMT Resent-Message-Id: <200803201440.m2KEe0Uo069991@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-ports-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Ulrich Spoerlein Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 17BCF106566B; Thu, 20 Mar 2008 14:31:53 +0000 (UTC) (envelope-from uspoerlein@gmail.com) Received: from acme.spoerlein.net (unknown [IPv6:2a01:198:200:2a::2]) by mx1.freebsd.org (Postfix) with ESMTP id 7563D8FC15; Thu, 20 Mar 2008 14:31:52 +0000 (UTC) (envelope-from uspoerlein@gmail.com) Received: from roadrunner.spoerlein.net (e180159152.adsl.alicedsl.de [85.180.159.152]) by acme.spoerlein.net (8.14.2/8.14.2) with ESMTP id m2KEVoUe066138 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 20 Mar 2008 15:31:51 +0100 (CET) (envelope-from uspoerlein@gmail.com) Received: from roadrunner.spoerlein.net (localhost [127.0.0.1]) by roadrunner.spoerlein.net (8.14.2/8.14.2) with ESMTP id m2KEVn8o004276 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 20 Mar 2008 15:31:49 +0100 (CET) (envelope-from uspoerlein@gmail.com) Received: (from uqs@localhost) by roadrunner.spoerlein.net (8.14.2/8.14.2/Submit) id m2KEVn99004275; Thu, 20 Mar 2008 15:31:49 +0100 (CET) (envelope-from uspoerlein@gmail.com) Message-Id: <20080320143149.GB14618@roadrunner.spoerlein.net> Date: Thu, 20 Mar 2008 15:31:49 +0100 From: Ulrich Spoerlein To: FreeBSD-gnats-submit@FreeBSD.org Cc: stefan@FreeBSD.org Subject: ports/121910: [PATCH] ports-mgmt/pkg_cutleaves: Implement "visual" mode X-BeenThere: freebsd-ports-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Ports bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Mar 2008 14:40:01 -0000 >Number: 121910 >Category: ports >Synopsis: [PATCH] ports-mgmt/pkg_cutleaves: Implement "visual" mode >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: update >Submitter-Id: current-users >Arrival-Date: Thu Mar 20 14:40:00 UTC 2008 >Closed-Date: >Last-Modified: >Originator: Ulrich Spoerlein >Release: FreeBSD 7.0-STABLE i386 >Organization: >Environment: System: FreeBSD roadrunner.spoerlein.net 7.0-STABLE FreeBSD 7.0-STABLE #2: Sat Mar 15 23:22:37 CET 2008 >Description: - 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. If find this easier to use than the interactive mode, where I frequently will press enter too fast, and then have to either start all over again or do a second run. Feel free to change the "visual" name and the -V flag to anything you like. Port maintainer (stefan@FreeBSD.org) is cc'd. Generated with FreeBSD Port Tools 0.77 >How-To-Repeat: >Fix: --- pkg_cutleaves-20080320.patch begins here --- Index: Makefile =================================================================== RCS file: /home/ncvs/ports/ports-mgmt/pkg_cutleaves/Makefile,v retrieving revision 1.14 diff -u -p -u -r1.14 Makefile --- Makefile 21 Oct 2007 08:29:06 -0000 1.14 +++ Makefile 20 Mar 2008 08:55:15 -0000 @@ -6,7 +6,7 @@ # PORTNAME= pkg_cutleaves -PORTVERSION= 20071021 +PORTVERSION= 20080320 CATEGORIES= ports-mgmt MASTER_SITES= # none DISTFILES= # none Index: files/pkg_cutleaves =================================================================== RCS file: /home/ncvs/ports/ports-mgmt/pkg_cutleaves/files/pkg_cutleaves,v retrieving revision 1.1 diff -u -p -u -r1.1 pkg_cutleaves --- files/pkg_cutleaves 21 Oct 2007 08:29:06 -0000 1.1 +++ files/pkg_cutleaves 20 Mar 2008 08:55:15 -0000 @@ -1,4 +1,5 @@ #!/usr/bin/perl +# $Id$ # # Copyright (c) 2003 Stefan Walter # @@ -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() =~ 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() =~ /(\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() =~ 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' Index: files/pkg_cutleaves.1 =================================================================== RCS file: /home/ncvs/ports/ports-mgmt/pkg_cutleaves/files/pkg_cutleaves.1,v retrieving revision 1.1 diff -u -p -u -r1.1 pkg_cutleaves.1 --- files/pkg_cutleaves.1 21 Oct 2007 08:29:06 -0000 1.1 +++ files/pkg_cutleaves.1 20 Mar 2008 08:55:15 -0000 @@ -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 users +.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 sta .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 string +.Ev EDITOR +will be invoked instead of the default editor +.Xr vi 1 . +.El .Sh SEE ALSO .Xr pkg_deinstall 1 , .Xr pkgdb 1 , --- pkg_cutleaves-20080320.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted: