[45253] users/perry/port_cutleaves/port_cutleaves

perry at macports.org perry at macports.org
Sun Jan 11 22:37:24 PST 2009


Revision: 45253
          http://trac.macports.org/changeset/45253
Author:   perry at macports.org
Date:     2009-01-11 22:37:23 -0800 (Sun, 11 Jan 2009)
Log Message:
-----------
perry/port_cutleaves - Sped up the script and updated the usage argument.

Modified Paths:
--------------
    users/perry/port_cutleaves/port_cutleaves

Modified: users/perry/port_cutleaves/port_cutleaves
===================================================================
--- users/perry/port_cutleaves/port_cutleaves	2009-01-12 04:52:14 UTC (rev 45252)
+++ users/perry/port_cutleaves/port_cutleaves	2009-01-12 06:37:23 UTC (rev 45253)
@@ -3,42 +3,40 @@
 exec /usr/bin/tclsh "$0" "$@"
 # $Id$
 
-package require cmdline
-
 set VERSION 0.1
 
 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]
+    set to_process {}
+    foreach leaf $leaves {
+        if {[lsearch -exact $processed_leaves $leaf] != -1} {
+            continue
         }
+        lappend processed_leaves    $leaf
+        lappend to_process          $leaf
     }
 
-    set total_leaves [llength $leaves]
+    set total_leaves [llength $to_process]
     if {$total_leaves < 1} {
         puts "There are no new leaves to process."
         return 0
     }
 
-    set current_leaf 1
-    set to_uninstall {}
+    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]
+    foreach leaf $to_process {
+        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 leaf                "$name @$composite_version"
 
-        if {$is_active == 1} {
-            set status Active
-        } else {
+        set status Active
+        if {$is_active == 0} {
             set status Inactive
         }
 
@@ -48,11 +46,11 @@
 
         gets stdin action
         switch -glob $action {
-            a* { 
+            a* {
                 puts "\nAborting port_cutleaves..."
                 exit 0
             }
-            f* { 
+            f* {
                 puts "\nFlushing any uninstallation operations...\n"
                 break
             }
@@ -63,62 +61,54 @@
             default { puts "** $leaf will be kept.\n" }
         }
 
-        set current_leaf [expr {$current_leaf + 1}]
+        set current_leaf [expr $current_leaf + 1]
     }
 
     if {[llength $to_uninstall] < 1} {
         puts "No leaves were marked for uninstallation."
         return 0
-    } else {
-        set uninstalled [uninstall $to_uninstall]
+    }
+    set uninstalled [uninstall $to_uninstall]
+    if {[llength $uninstalled] < 1} {
+        puts "\nNo leaves were uninstalled."
+        return 1
+    }
+    puts "\nThe following ports were uninstalled:"
+    foreach port $uninstalled {
+        puts "  $port"
+    }
 
-        if {[llength $uninstalled] < 1} {
-            puts "\nNo leaves were uninstalled."
-            return 1
-        } else {
-            puts "\nThe following ports were uninstalled:"
-            foreach port $uninstalled {
-                puts "  $port"
-            }
+    puts "\nSearch for new leaves?"
+    puts -nonewline "  \[no] / (y)es: "
+    flush stdout
 
-            puts "\nSearch for new leaves?"
-            puts -nonewline "  \[no] / (y)es: "
-            flush stdout
-
-            gets stdin choice
-            if {[regexp {^y} $choice]} {
-                puts {}
-                return [cut_leaves [leaves] $processed_leaves]
-            } else {
-                return 0
-            }
-        }
+    gets stdin choice
+    if {[regexp {^y} $choice]} {
+        puts {}
+        return [cut_leaves [leaves] $processed_leaves]
     }
+    return 0
 }
 
 proc leaves {} {
-    set leaves {}
-
     registry::open_dep_map
+
+    set leaves {}
     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]
-
-            if {[llength $dependents] < 1} {
+            if {[llength [registry::list_dependents $name]] < 1} {
                 lappend leaves $port
             }
         }
     }
-
     return $leaves
 }
 
 proc uninstall {ports} {
     set uninstalled {}
-
     foreach port $ports {
         set name              [lindex $port 0]
         set composite_version [lindex $port 1]
@@ -130,21 +120,22 @@
             lappend uninstalled "$name @$composite_version"
         }
     }
-
     return $uninstalled
 }
 
+package require cmdline
 set options {
     { t.arg /Library/Tcl \
             "Specify a different location for the base MacPorts Tcl file" }
     { V     "Display version information and exit" }
 }
+set usage "\[-t value] \[-V] \[-help] \[-?]\n\nOptions:"
 if {[catch {array set parameters [::cmdline::getoptions argv $options]}]} {
-    puts [::cmdline::usage $options {}]
+    puts [::cmdline::usage $options $usage]
     exit 1
 }
 
-if {[catch {source "$parameters(t)/macports1.0/macports_fastload.tcl"} \
+if {[catch {source $parameters(t)/macports1.0/macports_fastload.tcl} \
            result]} {
     puts stderr "Error: source failed: $result"
     exit 1
@@ -157,6 +148,5 @@
 } elseif {[catch {mportinit} result]} {
     puts stderr "Error: mportinit failed: $result"
     exit 1
-} else {
-    exit [cut_leaves [leaves]]
 }
+exit [cut_leaves [leaves]]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20090111/998a7873/attachment.html>


More information about the macports-changes mailing list