[24463] branches/dp2mp-move/base/src

source_changes at macosforge.org source_changes at macosforge.org
Tue Apr 24 12:37:27 PDT 2007


Revision: 24463
          http://trac.macosforge.org/projects/macports/changeset/24463
Author:   jmpp at macports.org
Date:     2007-04-24 12:37:27 -0700 (Tue, 24 Apr 2007)

Log Message:
-----------
Manually merging (file name differences) eridius' r24460: Make darwinports infrastructure easier to use from scripts. (...).

Modified Paths:
--------------
    branches/dp2mp-move/base/src/macports1.0/macports.tcl
    branches/dp2mp-move/base/src/port1.0/tests/portutil.tcl

Modified: branches/dp2mp-move/base/src/macports1.0/macports.tcl
===================================================================
--- branches/dp2mp-move/base/src/macports1.0/macports.tcl	2007-04-24 19:33:42 UTC (rev 24462)
+++ branches/dp2mp-move/base/src/macports1.0/macports.tcl	2007-04-24 19:37:27 UTC (rev 24463)
@@ -70,23 +70,33 @@
 # ui_prefix returns the prefix for the messages, if any.
 # ui_channels returns a list of channels to output the message to, empty for
 #     no message.
+# if these functions are not provided, defaults are used, but this should
+# not be relied upon for production code
 
 proc darwinports::ui_init {priority message} {
 	# Get the list of channels.
-	set channels [ui_channels $priority]
+	if {[llength [info commands ui_channels]] > 0} {
+		set channels [ui_channels $priority]
+	} else {
+	    set channels [ui_channels_default $priority]
+	}
 
 	# Simplify ui_$priority.
 	set nbchans [llength $channels]
 	if {$nbchans == 0} {
 		proc ::ui_$priority {str} {}
 	} else {
-		set prefix [ui_prefix $priority]
+		if {[llength [info commands ui_prefix]] > 0} {
+			set prefix [ui_prefix $priority]
+		} else {
+		    set prefix [ui_prefix_default $priority]
+		}
 
 		if {$nbchans == 1} {
 			set chan [lindex $channels 0]
-			proc ::ui_$priority {str} [subst -nocommands { puts $chan "$prefix\$str" }]
+			proc ::ui_$priority {str} [subst { puts $chan "$prefix\$str" }]
 		} else {
-			proc ::ui_$priority {str} [subst -nocommands {
+			proc ::ui_$priority {str} [subst {
 				foreach chan \$channels {
 					puts $chan "$prefix\$str"
 				}
@@ -98,8 +108,45 @@
 	}
 }
 
+# Defult implementation of ui_prefix
+proc darwinports::ui_prefix_default {priority} {
+	switch $priority {
+		debug {
+			return "DEBUG: "
+		}
+		error {
+			return "Error: "
+		}
+		warn {
+			return "Warning: "
+		}
+		default {
+			return ""
+		} 
+	}
+}
+
+# Default implementation of ui_channels
+proc darwinports::ui_channels_default {priority} {
+    switch $priority {
+        debug -
+        info {
+            return {}
+        }
+        msg {
+            return {stdout}
+        }
+        error {
+            return {stderr}
+        }
+        default {
+            return {stdout}
+        }
+    }
+}
+
 foreach priority ${darwinports::ui_priorities} {
-    eval "proc ui_$priority {str} \{ darwinports::ui_init $priority \$str \}"
+    proc ui_$priority {str} [subst { darwinports::ui_init $priority \$str }]
 }
 
 # Replace puts to catch errors (typically broken pipes when being piped to head)
@@ -175,10 +222,22 @@
 	}
 }
 
-proc dportinit {up_ui_options up_options up_variations} {
-	upvar  $up_ui_options ui_options
-	upvar  $up_options	  options
-	upvar  $up_variations variations
+proc dportinit {{up_ui_options {}} {up_options {}} {up_variations {}}} {
+	if {$up_ui_options eq ""} {
+		array set ui_options {}
+	} else {
+		upvar $up_ui_options ui_options
+	}
+	if {$up_options eq ""} {
+		array set options {}
+	} else {
+		upvar $up_options options
+	}
+	if {$up_variations eq ""} {
+		array set $up_variations {}
+	} else {
+		upvar $up_variations variations
+	}
 	
 	global auto_path env
 	global darwinports::autoconf::dports_conf_path

Modified: branches/dp2mp-move/base/src/port1.0/tests/portutil.tcl
===================================================================
--- branches/dp2mp-move/base/src/port1.0/tests/portutil.tcl	2007-04-24 19:33:42 UTC (rev 24462)
+++ branches/dp2mp-move/base/src/port1.0/tests/portutil.tcl	2007-04-24 19:37:27 UTC (rev 24463)
@@ -7,53 +7,8 @@
 source [file dirname [info script]]/../portutil.tcl
 package require darwinports
 
-# boilerplate necessary for using the macports infrastructure
-proc ui_isset {val} { return 0 }
+dportinit
 
-# no global options
-proc global_option_isset {val} { return 0 }
-
-# UI callback
-proc ui_prefix {priority} {
-    switch $priority {
-        debug {
-            return "DEBUG: "
-        }
-        error {
-            return "Error: "
-        }
-        warn {
-            return "Warning: "
-        }
-        default {
-            return ""
-        }
-    }
-}
-
-proc ui_channels {priority} {
-    switch $priority {
-        debug -
-        info {
-            return {}
-        }
-        msg {
-            return {stdout}
-        }
-        error {
-            return {stderr}
-        }
-        default {
-            return {stdout}
-        }
-    }
-}
-
-array set ui_options {}
-array set global_options {}
-array set global_variations {}
-dportinit ui_options global_options global_variations
-
 # end boilerplate
 
 namespace eval tests {

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070424/568d3bdc/attachment.html


More information about the macports-changes mailing list