[45246] users/perry/port_cutleaves
perry at macports.org
perry at macports.org
Sun Jan 11 16:57:19 PST 2009
Revision: 45246
http://trac.macports.org/changeset/45246
Author: perry at macports.org
Date: 2009-01-11 16:57:19 -0800 (Sun, 11 Jan 2009)
Log Message:
-----------
perry/port_cutleaves - Updated the script.
* Processed leaves are tracked.
* After a successful run, the script can search for new leaves to process.
Modified Paths:
--------------
users/perry/port_cutleaves/README
users/perry/port_cutleaves/port_cutleaves
Modified: users/perry/port_cutleaves/README
===================================================================
--- users/perry/port_cutleaves/README 2009-01-11 22:52:17 UTC (rev 45245)
+++ users/perry/port_cutleaves/README 2009-01-12 00:57:19 UTC (rev 45246)
@@ -1,14 +1,4 @@
$Id$
Inspired by FreeBSD's pkg_cutleaves, port_cutleaves is an interactive script
-that eases the uninstallation of "leaf" ports - ports that have no dependents.
-
-port_cutleaves iterates through the list of leaf ports, prompting the user to:
- * keep the specified port.
- * uninstall the specified port.
- * flush any uninstallation operations.
- * abort the procedure.
-
-Upon flush or reaching the end of the list, (1) any ports marked for
-uninstallation are uninstalled and (2) a summary of operations is displayed
-(e.g., which ports were installed).
+that eases the uninstallation of "leaves" - ports that have no dependents.
Modified: users/perry/port_cutleaves/port_cutleaves
===================================================================
--- users/perry/port_cutleaves/port_cutleaves 2009-01-11 22:52:17 UTC (rev 45245)
+++ users/perry/port_cutleaves/port_cutleaves 2009-01-12 00:57:19 UTC (rev 45246)
@@ -1,119 +1,141 @@
-#!/usr/bin/tclsh
+#!/bin/sh
+# \
+exec /usr/bin/tclsh "$0" "$@"
# $Id$
-catch {source [file join "/Library/Tcl" macports1.0 macports_fastload.tcl]}
+catch {source "/Library/Tcl/macports1.0/macports_fastload.tcl"}
package require macports
-# Iterates through the list of ports, prompting the user to:
-# * keep the specified port.
-# * uninstall the specified port.
-# * flush any uninstallation operations.
-# * abort the procedure.
-# Upon flush or reaching the end of the list, (1) any ports marked for
-# uninstallation are uninstalled and (2) a summary of operations is displayed
-# (e.g., which ports were installed).
-proc cut_leaves {ports} {
- set current_port 1
- set total_ports [llength $ports]
- set ports_to_uninstall {}
+proc cut_leaves {leaves {processed_leaves {}}} {
+ # TODO: Use an array rather than a list.
+ foreach leaf [lrange $leaves 0 end] {
+ if {[lsearch -exact $processed_leaves $leaf] == -1} {
+ lappend processed_leaves $leaf
+ } else {
+ set index [lsearch -exact $leaves $leaf]
+ set leaves [lreplace $leaves $index $index]
+ }
+ }
- if {$total_ports < 1} {
- return
+ set total_leaves [llength $leaves]
+ if {$total_leaves < 1} {
+ puts "There are no new leaves to process."
+ return 0
}
- foreach port $ports {
- set name [lindex $port 0]
- set version [lindex $port 1]
- set revision [lindex $port 2]
- set variants [lindex $port 3]
- set is_active [lindex $port 4]
+
+ set current_leaf 1
+ set to_uninstall {}
+
+ foreach leaf $leaves {
+ set name [lindex $leaf 0]
+ set version [lindex $leaf 1]
+ set revision [lindex $leaf 2]
+ set variants [lindex $leaf 3]
+ set is_active [lindex $leaf 4]
set composite_version "${version}_${revision}${variants}"
- set port "$name @$composite_version"
+ set leaf "$name @$composite_version"
- if {$is_active == 0} {
- set status " \(Inactive)"
+ if {$is_active == 1} {
+ set status "Active"
} else {
- set status " \(Active)"
+ set status "Inactive"
}
- puts "\[Port $current_port of $total_ports] ${port}${status}:"
+ puts "\[Leaf $current_leaf of $total_leaves] $leaf ($status):"
puts -nonewline " \[keep] / (u)ninstall / (f)lush / (a)bort: "
flush stdout
gets stdin action
switch -glob $action {
- a* {
- puts "** Aborting..."
+ a* {
+ puts "\nAborting port_cutleaves..."
exit 0
}
- f* {
- puts "** Flushing...\n"
+ f* {
+ puts "\nFlushing any uninstallation operations...\n"
break
}
u* {
- puts "** Marked $port for uninstallation.\n"
- lappend ports_to_uninstall [list $name $composite_version]
+ puts "** $leaf will be uninstalled.\n"
+ lappend to_uninstall [list $name $composite_version]
}
- default { puts "** $port will be kept.\n" }
+ default { puts "** $leaf will be kept.\n" }
}
- set current_port [expr {$current_port + 1}]
+ set current_leaf [expr {$current_leaf + 1}]
}
- if {[llength $ports_to_uninstall] < 1} {
- puts "No ports were marked for uninstallation."
+ if {[llength $to_uninstall] < 1} {
+ puts "No leaves were marked for uninstallation."
+ return 0
} else {
- set uninstalled_ports [uninstall $ports_to_uninstall]
+ set uninstalled [uninstall $to_uninstall]
- if {[llength $uninstalled_ports] < 1} {
- puts "\nNo ports were uninstalled."
+ if {[llength $uninstalled] < 1} {
+ puts "\nNo leaves were uninstalled."
+ return 1
} else {
puts "\nThe following ports were uninstalled:"
- foreach port $uninstalled_ports {
+ foreach port $uninstalled {
puts " $port"
}
+
+ puts "\nSearch for new leaves?"
+ puts -nonewline " \[no] / (y)es: "
+ flush stdout
+
+ gets stdin choice
+ switch -glob $choice {
+ y* {
+ puts ""
+ return [cut_leaves [leaves] $processed_leaves]
+ }
+ default { return 0 }
+ }
}
}
}
-# Returns the list of installed ports with no dependents.
-proc get_installed_with_no_dependents {} {
+proc leaves {} {
+ set leaves {}
+
registry::open_dep_map
+ if {[catch {set installed [registry::installed]} result]} {
+ puts stderr "Error: registry::installed failed: $result"
+ } else {
+ foreach port $installed {
+ set name [lindex $port 0]
+ set dependents [registry::list_dependents $name]
- set ports {}
- foreach port [registry::installed] {
- set name [lindex $port 0]
- set dependents [registry::list_dependents $name]
-
- if {[llength $dependents] < 1} {
- lappend ports $port
+ if {[llength $dependents] < 1} {
+ lappend leaves $port
+ }
}
}
- return $ports
+
+ return $leaves
}
-# Uninstalls the specified ports, displaying any encountered errors on stderr.
proc uninstall {ports} {
- set uninstalled_ports {}
+ set uninstalled {}
- if {[llength $ports] < 1} {
- return;
- }
foreach port $ports {
set name [lindex $port 0]
set composite_version [lindex $port 1]
if {[catch {portuninstall::uninstall $name $composite_version {}} \
result]} {
- puts stderr "portuninstall failed: $result"
+ puts stderr "Error: portuninstall:uninstall failed: $result"
} else {
- lappend uninstalled_ports "$name @$composite_version"
+ lappend uninstalled "$name @$composite_version"
}
}
- return $uninstalled_ports;
+
+ return $uninstalled
}
if {[catch {mportinit} result]} {
- puts stderr "mportinit failed: $result"
+ puts stderr "Error: mportinit failed: $result"
exit 1
}
-cut_leaves [get_installed_with_no_dependents]
+exit [cut_leaves [leaves]]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20090111/a9169a22/attachment-0001.html>
More information about the macports-changes
mailing list