Changeset 2772 for trunk/gui


Ignore:
Timestamp:
Jan 25, 2012 7:53:36 PM (12 years ago)
Author:
mmc
Message:

Fixed the Rappture::filexfer::upload command to support ordinary file
uploads with the file name taken from the remote side. If the <id>
argument is @@dir, then the remote file is loaded into the given directory
dir. The name of the remote file comes from the new --provenance flag
for filexfer. If the help info for importfile/exportfile doesn't have
that flag, then this defaults to the old behavior and returns the contents
of the file without renaming it to the desired location.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/filexfer.tcl

    r2744 r2772  
    5151        }
    5252        if {[file executable $path]} {
     53            # the new filexfer has a --provenance arg for file names
     54            set info [exec $path --help]
     55            if {[regexp -- {--provenance} $info]} {
     56                lappend path --provenance
     57            }
    5358            set commands($op) $path
    5459        } else {
     
    132137# information.  If anything goes wrong, the same callback is used
    133138# to post errors near the widget that invoked this operation.
     139#
     140# The <id> is usually a Rappture path for the control that is being
     141# uploaded into.  It is passed along to the <callback>, so that code
     142# knows where to put the result.  If <id> is "@@<dir>", then the file
     143# is uploaded into the specified directory <dir> using the name that
     144# comes from the remote upload.
    134145# ----------------------------------------------------------------------
    135146proc Rappture::filexfer::upload {tool controlList callback} {
     
    173184            set changed ""
    174185            set errs ""
    175             foreach file $job(output) {
     186            foreach line [split $job(output) \n] {
     187                # the new filexfer reports "file <= desktopName"
     188                # the old one just reports "file"
     189                set remote ""
     190                if {![regexp {(.+) +<= +(.+)} $line match file remote]} {
     191                    set file [string trim $line]
     192                }
     193
    176194                # load the uploaded for this control
    177195                set status [catch {
     
    180198                    set info [read $fid]
    181199                    close $fid
    182                     file delete -force $file
     200                    if {[string match @@* $file2path($file)]} {
     201                        if {$remote ne "" && $remote ne "@CLIPBOARD"} {
     202                            set dir [string range $file2path($file) 2 end]
     203                            if {$dir eq ""} { set dir [pwd] }
     204                            set newloc [file join $dir $remote]
     205                            file rename -force -- $file $newloc
     206                        }
     207                    } else {
     208                        file delete -force $file
     209                    }
    183210                } result]
    184211
     
    187214                } else {
    188215                    lappend changed $file2path($file)
    189                     uplevel #0 [list $callback path $file2path($file) data $info]
     216                    set cmd [list $callback path $file2path($file) local $file data $info]
     217                    if {$remote ne ""} {
     218                        lappend cmd remote $remote
     219                    }
     220                    uplevel #0 $cmd
    190221                }
    191222            }
     
    226257                    uplevel #0 [list $callback error "Error loading file [file tail $file]: $err"]
    227258                } else {
    228                     uplevel #0 [list $callback path $path data $info]
     259                    uplevel #0 [list $callback path $path data $info filename $file]
    229260                }
    230261            }
Note: See TracChangeset for help on using the changeset viewer.