[29191] trunk/base/src

source_changes at macosforge.org source_changes at macosforge.org
Mon Sep 17 00:55:36 PDT 2007


Revision: 29191
          http://trac.macosforge.org/projects/macports/changeset/29191
Author:   jmpp at macports.org
Date:     2007-09-17 00:55:36 -0700 (Mon, 17 Sep 2007)

Log Message:
-----------

API change:

 * move ui_isset and global_option_isset procs that are found in every single macports1.0 client into macports1.0 itself, sparing the clients from implementing them repeatedly;
 * change their prototypes to require the arrays as arguments, so that the library clients can still set and fill them up as desired;
 * update every macports1.0 client in our tree to use this new API (this expands to the port, portindex and portmirror scripts in the base/src/port, do let me know of I'm missing any).

PS: The purpose of this commit is to further simplify macports1.0 scripting, so that a client is not forced to do all the UI initialization plumbing.

Modified Paths:
--------------
    trunk/base/src/macports1.0/macports.tcl
    trunk/base/src/port/port.tcl
    trunk/base/src/port/portindex.tcl
    trunk/base/src/port/portmirror.tcl

Modified: trunk/base/src/macports1.0/macports.tcl
===================================================================
--- trunk/base/src/macports1.0/macports.tcl	2007-09-17 07:34:37 UTC (rev 29190)
+++ trunk/base/src/macports1.0/macports.tcl	2007-09-17 07:55:36 UTC (rev 29191)
@@ -77,6 +77,31 @@
 # if these functions are not provided, defaults are used, but this should
 # not be relied upon for production code
 
+# ui_options accessor
+proc macports::ui_isset {ui_options val} {
+    upvar $ui_options up_ui_options
+    if {[info exists up_ui_options($val)]} {
+        if {$up_ui_options($val) == "yes"} {
+            return 1
+        }
+    }
+    return 0
+}
+
+
+# global_options accessor
+proc macports::global_option_isset {global_options val} {
+    upvar $global_options up_global_options
+    if {[info exists up_global_options($val)]} {
+        if {$up_global_options($val) == "yes"} {
+            puts "Global option \"$val\" in action!"
+            return 1
+        }
+    }
+    return 0
+}
+
+
 proc macports::ui_init {priority message} {
     # Get the list of channels.
     if {[llength [info commands ui_channels]] > 0} {

Modified: trunk/base/src/port/port.tcl
===================================================================
--- trunk/base/src/port/port.tcl	2007-09-17 07:34:37 UTC (rev 29190)
+++ trunk/base/src/port/port.tcl	2007-09-17 07:55:36 UTC (rev 29191)
@@ -34,7 +34,7 @@
 # POSSIBILITY OF SUCH DAMAGE.
 
 #
-#   TODO:
+# TODO:
 #
 
 catch {source \
@@ -46,28 +46,6 @@
 # ui_options(ports_verbose) - If set, output info messages (ui_info)
 # ui_options(ports_quiet) - If set, don't output "standard messages"
 
-# ui_options accessor
-proc ui_isset {val} {
-    global ui_options
-    if {[info exists ui_options($val)]} {
-        if {$ui_options($val) == "yes"} {
-            return 1
-        }
-    }
-    return 0
-}
-
-# global_options accessor
-proc global_option_isset {val} {
-    global global_options
-    if {[info exists global_options($val)]} {
-        if {$global_options($val) == "yes"} {
-            return 1
-        }
-    }
-    return 0
-}
-
 # UI Callback
 proc ui_prefix {priority} {
     switch $priority {
@@ -87,24 +65,24 @@
 }
 
 proc ui_channels {priority} {
-    global logfd
+    global ui_options
     switch $priority {
         debug {
-            if {[ui_isset ports_debug]} {
+            if {[macports::ui_isset ui_options ports_debug]} {
                 return {stderr}
             } else {
                 return {}
             }
         }
         info {
-            if {[ui_isset ports_verbose]} {
+            if {[macports::ui_isset ui_options ports_verbose]} {
                 return {stdout}
             } else {
                 return {}
             }
         }
         msg {
-            if {[ui_isset ports_quiet]} {
+            if {[macports::ui_isset ui_options ports_quiet]} {
                 return {}
             } else {
                 return {stdout}
@@ -213,7 +191,8 @@
 # we're handling errors in a soft fashion, in which
 # case we continue
 proc fatal_softcontinue s {
-    if {[global_option_isset ports_force]} {
+    global global_options
+    if {[macports::global_option_isset global_options ports_force]} {
         ui_error $s
         return -code continue
     } else {
@@ -226,9 +205,10 @@
 # we're handling errors in a soft fashion, in which
 # case we continue
 proc break_softcontinue { msg status name_status } {
+    global ui_options
     upvar $name_status status_var 
     ui_error $msg
-    if {[ui_isset ports_processall]} {
+    if {[macports::ui_isset ui_options ports_processall]} {
         set status_var 0
         return -code continue
     } else {
@@ -560,7 +540,7 @@
 
 
 proc get_outdated_ports {} {
-    global macports::registry.installtype
+    global macports::registry.installtype ui_options
     set is_image_mode [expr 0 == [string compare "image" ${macports::registry.installtype}]]
 
     # Get the list of installed ports
@@ -597,7 +577,7 @@
                 fatal "search for portname $portname failed: $result"
             }
             if {[llength $res] < 2} {
-                if {[ui_isset ports_debug]} {
+                if {[macports::ui_isset ui_options ports_debug]} {
                     puts "$portname ($installed_compound is installed; the port was not found in the port index)"
                 }
                 continue
@@ -1149,6 +1129,7 @@
 
 
 proc action_info { action portlist opts } {
+    global ui_options
     set status 0
     require_portlist portlist
     foreachport $portlist {
@@ -1223,7 +1204,7 @@
         }
         
         # Figure out whether to show field name
-        set quiet [ui_isset ports_quiet]
+        set quiet [macports::ui_isset ui_options ports_quiet]
         if {$quiet} {
             set show_label 0
         }
@@ -1501,13 +1482,14 @@
 
 
 proc action_uninstall { action portlist opts } {
+    global global_options
     set status 0
-    if {[global_option_isset port_uninstall_old]} {
+    if {[macports::global_option_isset global_options port_uninstall_old]} {
         # if -u then uninstall all inactive ports
         # (union these to any other ports user has in the port list)
         set portlist [opUnion $portlist [get_inactive_ports]]
     } else {
-        # Otherwise the user had better have supplied a portlist, or we'll default to the existing directory
+        # Otherwise the user hopefully supplied a portlist, or we'll default to the existing directory
         require_portlist portlist
     }
 
@@ -1524,11 +1506,12 @@
 
 
 proc action_installed { action portlist opts } {
+    global global_options
     set status 0
     set restrictedList 0
     set ilist {}
     
-    if { [llength $portlist] || ![global_option_isset ports_no_args]} {
+    if { [llength $portlist] || ![macports::global_option_isset global_options ports_no_args]} {
         set restrictedList 1
         foreachport $portlist {
             set composite_version [composite_version $portversion [array get variations]]
@@ -1575,7 +1558,7 @@
 
 
 proc action_outdated { action portlist opts } {
-    global macports::registry.installtype
+    global macports::registry.installtype ui_options global_options
     set is_image_mode [expr 0 == [string compare "image" ${macports::registry.installtype}]]
 
     set status 0
@@ -1583,7 +1566,7 @@
     # If port names were supplied, limit ourselves to those ports, else check all installed ports
     set ilist {}
     set restrictedList 0
-    if { [llength $portlist] || ![global_option_isset ports_no_args]} {
+    if { [llength $portlist] || ![macports::global_option_isset global_options ports_no_args]} {
         set restrictedList 1
         foreach portspec $portlist {
             array set port $portspec
@@ -1631,7 +1614,7 @@
                 break_softcontinue "search for portname $portname failed: $result" 1 status
             }
             if {[llength $res] < 2} {
-                if {[ui_isset ports_debug]} {
+                if {[macports::ui_isset ui_options ports_debug]} {
                     puts "$portname ($installed_compound is installed; the port was not found in the port index)"
                 }
                 continue
@@ -1673,7 +1656,7 @@
                 }
                 
                 # Emit information
-                if {$comp_result < 0 || [ui_isset ports_verbose]} {
+                if {$comp_result < 0 || [macports::ui_isset ui_options ports_verbose]} {
                 
                     if { $num_outdated == 0 } {
                         puts "The following installed ports are outdated:"
@@ -1829,8 +1812,9 @@
 
 
 proc action_search { action portlist opts } {
+    global global_options
     set status 0
-    if {![llength $portlist] && [global_option_isset ports_no_args]} {
+    if {![llength $portlist] && [macports::global_option_isset global_options ports_no_args]} {
         ui_error "You must specify a search pattern"
         return 1
     }
@@ -1877,10 +1861,11 @@
 
 
 proc action_list { action portlist opts } {
+    global global_options
     set status 0
     
     # Default to list all ports if no portnames are supplied
-    if {![llength $portlist] && [global_option_isset ports_no_args]} {
+    if {![llength $portlist] && [macports::global_option_isset global_options ports_no_args]} {
         add_to_portlist portlist [list name "-all-"]
     }
     
@@ -2375,7 +2360,7 @@
 
 proc process_cmd { argv } {
     global cmd_argc cmd_argv cmd_argn
-    global global_options global_options_base
+    global global_options global_options_base ui_options
     global current_portdir
     set cmd_argv $argv
     set cmd_argc [llength $argv]
@@ -2442,7 +2427,7 @@
         if {$action_status == -999} break
 
         # If we're not in exit mode then ignore the status from the command
-        if { ![ui_isset ports_exit] } {
+        if { ![macports::ui_isset ui_options ports_exit] } {
             set action_status 0
         }
     }
@@ -2544,7 +2529,7 @@
 
 
 proc process_command_file { in } {
-    global current_portdir
+    global current_portdir ui_options
 
     # Initialize readline
     set isstdin [string match $in "stdin"]
@@ -2559,7 +2544,7 @@
     }
 
     # Be noisy, if appropriate
-    set noisy [expr $isstdin && ![ui_isset ports_quiet]]
+    set noisy [expr $isstdin && ![macports::ui_isset ui_options ports_quiet]]
     if { $noisy } {
         puts "MacPorts [macports::version]"
         puts "Entering interactive mode... (\"help\" for help, \"quit\" to quit)"
@@ -2590,7 +2575,7 @@
         if {$exit_status == -999} break
         
         # Ignore status unless we're in error-exit mode
-        if { ![ui_isset ports_exit] } {
+        if { ![macports::ui_isset ui_options ports_exit] } {
             set exit_status 0
         }
     }
@@ -2610,6 +2595,7 @@
 
 
 proc process_command_files { filelist } {
+    global ui_options
     set exit_status 0
 
     # For each file in the command list, process commands
@@ -2636,7 +2622,7 @@
         }
 
         # Ignore status unless we're in error-exit mode
-        if { ![ui_isset ports_exit] } {
+        if { ![macports::ui_isset ui_options ports_exit] } {
             set exit_status 0
         }
     }

Modified: trunk/base/src/port/portindex.tcl
===================================================================
--- trunk/base/src/port/portindex.tcl	2007-09-17 07:34:37 UTC (rev 29190)
+++ trunk/base/src/port/portindex.tcl	2007-09-17 07:55:36 UTC (rev 29191)
@@ -28,17 +28,6 @@
 # ui_options(ports_verbose) - If set, output info messages (ui_info)
 # ui_options(ports_quiet) - If set, don't output "standard messages"
 
-# ui_options accessor
-proc ui_isset {val} {
-    global ui_options
-    if {[info exists ui_options($val)]} {
-        if {$ui_options($val) == "yes"} {
-            return 1
-        }
-    }
-    return 0
-}
-
 # UI Callback
 proc ui_prefix {priority} {
     switch $priority {
@@ -60,21 +49,21 @@
 proc ui_channels {priority} {
     switch $priority {
         debug {
-            if {[ui_isset ports_debug]} {
+            if {[macports::ui_isset ui_options ports_debug]} {
                 return {stderr}
             } else {
                 return {}
             }
         }
         info {
-            if {[ui_isset ports_verbose]} {
+            if {[macports::ui_isset ui_options ports_verbose]} {
                 return {stdout}
             } else {
                 return {}
             }
         }
         msg {
-            if {[ui_isset ports_quiet]} {
+            if {[macports::ui_isset ui_options ports_quiet]} {
                 return {}
             } else {
                 return {stdout}

Modified: trunk/base/src/port/portmirror.tcl
===================================================================
--- trunk/base/src/port/portmirror.tcl	2007-09-17 07:34:37 UTC (rev 29190)
+++ trunk/base/src/port/portmirror.tcl	2007-09-17 07:55:36 UTC (rev 29191)
@@ -25,16 +25,6 @@
 # ui_options(ports_verbose) - If set, output info messages (ui_info)
 # ui_options(ports_quiet) - If set, don't output "standard messages"
 
-# ui_options accessor
-proc ui_isset {val} {
-    global ui_options
-    if {[info exists ui_options($val)]} {
-    if {$ui_options($val) == "yes"} {
-        return 1
-    }
-    }
-    return 0
-}
 
 # UI Callback
 proc ui_prefix {priority} {
@@ -57,21 +47,21 @@
 proc ui_channels {priority} {
     switch $priority {
         debug {
-            if {[ui_isset ports_debug]} {
+            if {[macports::ui_isset ui_options ports_debug]} {
                 return {stderr}
             } else {
                 return {}
             }
         }
         info {
-            if {[ui_isset ports_verbose]} {
+            if {[macports::ui_isset ui_options ports_verbose]} {
                 return {stdout}
             } else {
                 return {}
             }
         }
         msg {
-            if {[ui_isset ports_quiet]} {
+            if {[macports::ui_isset ui_options ports_quiet]} {
                 return {}
             } else {
                 return {stdout}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070917/0f276053/attachment.html


More information about the macports-changes mailing list