Changeset 29191


Ignore:
Timestamp:
Sep 17, 2007, 7:55:36 AM (12 years ago)
Author:
jmpp@…
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.

Location:
trunk/base/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/macports1.0/macports.tcl

    r28796 r29191  
    7878# not be relied upon for production code
    7979
     80# ui_options accessor
     81proc macports::ui_isset {ui_options val} {
     82    upvar $ui_options up_ui_options
     83    if {[info exists up_ui_options($val)]} {
     84        if {$up_ui_options($val) == "yes"} {
     85            return 1
     86        }
     87    }
     88    return 0
     89}
     90
     91
     92# global_options accessor
     93proc macports::global_option_isset {global_options val} {
     94    upvar $global_options up_global_options
     95    if {[info exists up_global_options($val)]} {
     96        if {$up_global_options($val) == "yes"} {
     97            puts "Global option \"$val\" in action!"
     98            return 1
     99        }
     100    }
     101    return 0
     102}
     103
     104
    80105proc macports::ui_init {priority message} {
    81106    # Get the list of channels.
  • trunk/base/src/port/port.tcl

    r29172 r29191  
    3535
    3636#
    37 #   TODO:
     37# TODO:
    3838#
    3939
     
    4646# ui_options(ports_verbose) - If set, output info messages (ui_info)
    4747# ui_options(ports_quiet) - If set, don't output "standard messages"
    48 
    49 # ui_options accessor
    50 proc ui_isset {val} {
    51     global ui_options
    52     if {[info exists ui_options($val)]} {
    53         if {$ui_options($val) == "yes"} {
    54             return 1
    55         }
    56     }
    57     return 0
    58 }
    59 
    60 # global_options accessor
    61 proc global_option_isset {val} {
    62     global global_options
    63     if {[info exists global_options($val)]} {
    64         if {$global_options($val) == "yes"} {
    65             return 1
    66         }
    67     }
    68     return 0
    69 }
    7048
    7149# UI Callback
     
    8866
    8967proc ui_channels {priority} {
    90     global logfd
     68    global ui_options
    9169    switch $priority {
    9270        debug {
    93             if {[ui_isset ports_debug]} {
     71            if {[macports::ui_isset ui_options ports_debug]} {
    9472                return {stderr}
    9573            } else {
     
    9876        }
    9977        info {
    100             if {[ui_isset ports_verbose]} {
     78            if {[macports::ui_isset ui_options ports_verbose]} {
    10179                return {stdout}
    10280            } else {
     
    10583        }
    10684        msg {
    107             if {[ui_isset ports_quiet]} {
     85            if {[macports::ui_isset ui_options ports_quiet]} {
    10886                return {}
    10987            } else {
     
    214192# case we continue
    215193proc fatal_softcontinue s {
    216     if {[global_option_isset ports_force]} {
     194    global global_options
     195    if {[macports::global_option_isset global_options ports_force]} {
    217196        ui_error $s
    218197        return -code continue
     
    227206# case we continue
    228207proc break_softcontinue { msg status name_status } {
     208    global ui_options
    229209    upvar $name_status status_var
    230210    ui_error $msg
    231     if {[ui_isset ports_processall]} {
     211    if {[macports::ui_isset ui_options ports_processall]} {
    232212        set status_var 0
    233213        return -code continue
     
    561541
    562542proc get_outdated_ports {} {
    563     global macports::registry.installtype
     543    global macports::registry.installtype ui_options
    564544    set is_image_mode [expr 0 == [string compare "image" ${macports::registry.installtype}]]
    565545
     
    598578            }
    599579            if {[llength $res] < 2} {
    600                 if {[ui_isset ports_debug]} {
     580                if {[macports::ui_isset ui_options ports_debug]} {
    601581                    puts "$portname ($installed_compound is installed; the port was not found in the port index)"
    602582                }
     
    11501130
    11511131proc action_info { action portlist opts } {
     1132    global ui_options
    11521133    set status 0
    11531134    require_portlist portlist
     
    12241205       
    12251206        # Figure out whether to show field name
    1226         set quiet [ui_isset ports_quiet]
     1207        set quiet [macports::ui_isset ui_options ports_quiet]
    12271208        if {$quiet} {
    12281209            set show_label 0
     
    15021483
    15031484proc action_uninstall { action portlist opts } {
     1485    global global_options
    15041486    set status 0
    1505     if {[global_option_isset port_uninstall_old]} {
     1487    if {[macports::global_option_isset global_options port_uninstall_old]} {
    15061488        # if -u then uninstall all inactive ports
    15071489        # (union these to any other ports user has in the port list)
    15081490        set portlist [opUnion $portlist [get_inactive_ports]]
    15091491    } else {
    1510         # Otherwise the user had better have supplied a portlist, or we'll default to the existing directory
     1492        # Otherwise the user hopefully supplied a portlist, or we'll default to the existing directory
    15111493        require_portlist portlist
    15121494    }
     
    15251507
    15261508proc action_installed { action portlist opts } {
     1509    global global_options
    15271510    set status 0
    15281511    set restrictedList 0
    15291512    set ilist {}
    15301513   
    1531     if { [llength $portlist] || ![global_option_isset ports_no_args]} {
     1514    if { [llength $portlist] || ![macports::global_option_isset global_options ports_no_args]} {
    15321515        set restrictedList 1
    15331516        foreachport $portlist {
     
    15761559
    15771560proc action_outdated { action portlist opts } {
    1578     global macports::registry.installtype
     1561    global macports::registry.installtype ui_options global_options
    15791562    set is_image_mode [expr 0 == [string compare "image" ${macports::registry.installtype}]]
    15801563
     
    15841567    set ilist {}
    15851568    set restrictedList 0
    1586     if { [llength $portlist] || ![global_option_isset ports_no_args]} {
     1569    if { [llength $portlist] || ![macports::global_option_isset global_options ports_no_args]} {
    15871570        set restrictedList 1
    15881571        foreach portspec $portlist {
     
    16321615            }
    16331616            if {[llength $res] < 2} {
    1634                 if {[ui_isset ports_debug]} {
     1617                if {[macports::ui_isset ui_options ports_debug]} {
    16351618                    puts "$portname ($installed_compound is installed; the port was not found in the port index)"
    16361619                }
     
    16741657               
    16751658                # Emit information
    1676                 if {$comp_result < 0 || [ui_isset ports_verbose]} {
     1659                if {$comp_result < 0 || [macports::ui_isset ui_options ports_verbose]} {
    16771660               
    16781661                    if { $num_outdated == 0 } {
     
    18301813
    18311814proc action_search { action portlist opts } {
     1815    global global_options
    18321816    set status 0
    1833     if {![llength $portlist] && [global_option_isset ports_no_args]} {
     1817    if {![llength $portlist] && [macports::global_option_isset global_options ports_no_args]} {
    18341818        ui_error "You must specify a search pattern"
    18351819        return 1
     
    18781862
    18791863proc action_list { action portlist opts } {
     1864    global global_options
    18801865    set status 0
    18811866   
    18821867    # Default to list all ports if no portnames are supplied
    1883     if {![llength $portlist] && [global_option_isset ports_no_args]} {
     1868    if {![llength $portlist] && [macports::global_option_isset global_options ports_no_args]} {
    18841869        add_to_portlist portlist [list name "-all-"]
    18851870    }
     
    23762361proc process_cmd { argv } {
    23772362    global cmd_argc cmd_argv cmd_argn
    2378     global global_options global_options_base
     2363    global global_options global_options_base ui_options
    23792364    global current_portdir
    23802365    set cmd_argv $argv
     
    24432428
    24442429        # If we're not in exit mode then ignore the status from the command
    2445         if { ![ui_isset ports_exit] } {
     2430        if { ![macports::ui_isset ui_options ports_exit] } {
    24462431            set action_status 0
    24472432        }
     
    25452530
    25462531proc process_command_file { in } {
    2547     global current_portdir
     2532    global current_portdir ui_options
    25482533
    25492534    # Initialize readline
     
    25602545
    25612546    # Be noisy, if appropriate
    2562     set noisy [expr $isstdin && ![ui_isset ports_quiet]]
     2547    set noisy [expr $isstdin && ![macports::ui_isset ui_options ports_quiet]]
    25632548    if { $noisy } {
    25642549        puts "MacPorts [macports::version]"
     
    25912576       
    25922577        # Ignore status unless we're in error-exit mode
    2593         if { ![ui_isset ports_exit] } {
     2578        if { ![macports::ui_isset ui_options ports_exit] } {
    25942579            set exit_status 0
    25952580        }
     
    26112596
    26122597proc process_command_files { filelist } {
     2598    global ui_options
    26132599    set exit_status 0
    26142600
     
    26372623
    26382624        # Ignore status unless we're in error-exit mode
    2639         if { ![ui_isset ports_exit] } {
     2625        if { ![macports::ui_isset ui_options ports_exit] } {
    26402626            set exit_status 0
    26412627        }
  • trunk/base/src/port/portindex.tcl

    r29188 r29191  
    2929# ui_options(ports_quiet) - If set, don't output "standard messages"
    3030
    31 # ui_options accessor
    32 proc ui_isset {val} {
    33     global ui_options
    34     if {[info exists ui_options($val)]} {
    35         if {$ui_options($val) == "yes"} {
    36             return 1
    37         }
    38     }
    39     return 0
    40 }
    41 
    4231# UI Callback
    4332proc ui_prefix {priority} {
     
    6150    switch $priority {
    6251        debug {
    63             if {[ui_isset ports_debug]} {
     52            if {[macports::ui_isset ui_options ports_debug]} {
    6453                return {stderr}
    6554            } else {
     
    6857        }
    6958        info {
    70             if {[ui_isset ports_verbose]} {
     59            if {[macports::ui_isset ui_options ports_verbose]} {
    7160                return {stdout}
    7261            } else {
     
    7564        }
    7665        msg {
    77             if {[ui_isset ports_quiet]} {
     66            if {[macports::ui_isset ui_options ports_quiet]} {
    7867                return {}
    7968            } else {
  • trunk/base/src/port/portmirror.tcl

    r29189 r29191  
    2626# ui_options(ports_quiet) - If set, don't output "standard messages"
    2727
    28 # ui_options accessor
    29 proc ui_isset {val} {
    30     global ui_options
    31     if {[info exists ui_options($val)]} {
    32     if {$ui_options($val) == "yes"} {
    33         return 1
    34     }
    35     }
    36     return 0
    37 }
    3828
    3929# UI Callback
     
    5848    switch $priority {
    5949        debug {
    60             if {[ui_isset ports_debug]} {
     50            if {[macports::ui_isset ui_options ports_debug]} {
    6151                return {stderr}
    6252            } else {
     
    6555        }
    6656        info {
    67             if {[ui_isset ports_verbose]} {
     57            if {[macports::ui_isset ui_options ports_verbose]} {
    6858                return {stdout}
    6959            } else {
     
    7262        }
    7363        msg {
    74             if {[ui_isset ports_quiet]} {
     64            if {[macports::ui_isset ui_options ports_quiet]} {
    7565                return {}
    7666            } else {
Note: See TracChangeset for help on using the changeset viewer.