Changeset 6323 for branches/1.7


Ignore:
Timestamp:
May 11, 2016 10:05:24 AM (8 years ago)
Author:
gah
Message:

fixes for sharing simulations w/ url

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.7/gui/scripts/analyzer.tcl

    r6272 r6323  
    120120    private method SelectSimsetForLoading {}
    121121    private method SelectSimsetNameAndSave {}
    122     private method SelectSimsetToPublish {}
    123     private method WriteSimsetFile { appName fileName publish }
     122    private method SelectSimsetToShare {}
     123    private method WriteSimsetFile { appName fileName share }
    124124    private method OverwriteSaveFile {}
    125125    private method BuildQuestionDialog { popup }
    126126    private method Save {}
    127127    private method CleanName { name }
     128    private method InstallSharedFile { installdir file }
     129    private method CreateSharedPath { path }
     130    private method ExportURL { appName installdir }
     131    private method ExportFile { src msgFile }
    128132}
    129133
     
    213217    buildMenu $itk_component(help).menu $url $_appName
    214218   
    215     if 0 {
    216         # To be eliminated with menu changes.
    217     itk_component add about {
    218         button $itk_component(hubcntls).about \
    219             -text "About this tool" \
    220             -command [list Rappture::filexfer::webpage \
    221                           "$url/tools/$_appName"]
    222     } {
    223         usual
    224         ignore -font
    225         rename -background -simcontrolcolor simControlColor Color
    226         rename -highlightbackground -simcontrolcolor simControlColor Color
    227     }
    228     pack $itk_component(about) -side top -anchor w
    229    
    230     itk_component add questions {
    231         button $itk_component(hubcntls).questions -text Questions? \
    232             -command [list Rappture::filexfer::webpage \
    233                           "$url/resources/$_appName/questions"]
    234     } {
    235         usual
    236         ignore -font
    237         rename -background -simcontrolcolor simControlColor Color
    238         rename -highlightbackground -simcontrolcolor simControlColor Color
    239     }
    240     pack $itk_component(questions) -side top -anchor w
    241     if { $url == "" || $_appName == "" } {
    242         $itk_component(questions) configure -state disabled
    243         $itk_component(about) configure -state disabled
    244     } else {
    245         $itk_component(questions) configure -state normal
    246         $itk_component(about) configure -state normal
    247     }       
    248     }
    249219    itk_component add simstatus {
    250220        text $itk_component(simbg).simstatus -borderwidth 0 \
     
    477447        # check to see if simulation is really needed
    478448        $_tool sync
    479         if {[$_resultset contains [$_tool xml object]]
    480               && ![string equal $_control "manual-resim"]} {
     449        if {[$_resultset contains [$_tool xml object]] &&
     450            ![string equal $_control "manual-resim"]} {
    481451            # not needed -- show results and return
    482452            $itk_component(notebook) current analyze
     
    569539    # check to see if simulation is really needed
    570540    $_tool sync
    571     if {![$_resultset contains [$_tool xml object]]
    572           || [string equal $_control "manual-resim"]} {
     541    if {![$_resultset contains [$_tool xml object]] ||
     542        [string equal $_control "manual-resim"]} {
    573543        # if control mode is "auto", then simulate right away
    574544        if {[string match auto* $_control]} {
     
    11581128    # Scan through and pick out any =RAPPTURE-PROGRESS=> messages first.
    11591129    #
    1160 
    1161     while {[regexp -indices \
    1162                {=RAPPTURE-PROGRESS=> *([-+]?[0-9]+) +([^\n]*)(\n|$)} $message \
    1163                 match percent mesg]} {
     1130    set pattern {=RAPPTURE-PROGRESS=> *([-+]?[0-9]+) +([^\n]*)(\n|$)}
     1131    while {[regexp -indices $pattern $message match percent mesg]} {
    11641132
    11651133        foreach {i0 i1} $percent break
     
    12031171    #
    12041172    $itk_component(runinfo) configure -state normal
    1205 
    1206     while {[regexp -indices \
    1207                {=RAPPTURE-([a-zA-Z]+)=>([^\n]*)(\n|$)} $message \
    1208                 match type mesg]} {
    1209 
     1173    set pattern {=RAPPTURE-([a-zA-Z]+)=>([^\n]*)(\n|$)}
     1174    while {[regexp -indices $pattern $message match type mesg]} {
    12101175        foreach {i0 i1} $match break
    12111176        set first [string range $message 0 [expr {$i0-1}]]
     
    12501215    set name [$itk_component(viewselector) value]
    12511216    if {[info exists _label2desc($name)] &&
    1252          [string length $_label2desc($name)] > 0} {
     1217        [string length $_label2desc($name)] > 0} {
    12531218        append tip "$_label2desc($name)\n\n"
    12541219    }
     
    15181483            continue
    15191484        }
    1520         if 0 {
    1521         # Recurse over all child nodes.
    1522         _trajToSequence $xmlobj $current
    1523         }
    15241485    }
    15251486}
     
    15501511    if { [FindSimsetsForApp $_appName] == 0 } {
    15511512        $m entryconfigure "Load Simulations" -state disable
    1552         $m entryconfigure "Publish Simulations" -state disable
     1513        $m entryconfigure "Share Simulations" -state disable
    15531514        $m entryconfigure "Delete Simulations" -state disabled
    15541515    } else {
    15551516        $m entryconfigure "Load Simulations" -state normal
    1556         $m entryconfigure "Publish Simulations" -state normal
     1517        $m entryconfigure "Share Simulations" -state normal
    15571518        $m entryconfigure "Delete Simulations" -state normal
    15581519    }
     
    15781539    set webcmd Rappture::filexfer::webpage
    15791540    set group "app-$_appName"
     1541    if { [info exists env(SESSION)] }  {
     1542        set referer "&referrer=$url/tools/$appName/session?sess=$env(SESSION)"
     1543    } else {
     1544        set referer ""
     1545    }
    15801546    $m add command -label "About this tool" \
    15811547        -command [list $webcmd "$url/tools/$appName"] \
     
    15851551        -state $state
    15861552    $m add command -label "Tickets" -state $state \
    1587         -command [list $webcmd "$url/feedback/report_problems?group=$group"]
     1553        -command [list $webcmd "$url/feedback/report_problems?group=$group$referer"]
    15881554    $m add command -label "Wish List" -state disabled
    15891555    $m add separator
     
    15971563        -command [itcl::code $this SelectSimsetForDeletion] \
    15981564        -state $state
    1599     $m add command -label "Publish Simulations" \
    1600         -command [itcl::code $this SelectSimsetToPublish] \
     1565    $m add command -label "Share Simulations" \
     1566        -command [itcl::code $this SelectSimsetToShare] \
    16011567        -state $state
    16021568    return $m
     
    16831649itcl::body Rappture::Analyzer::SelectSimsetNameAndSave {} {
    16841650    if { [EditSimset] } {
    1685         set appDir [file normalize ~/data/saved/$_appName]
    1686         file mkdir $appDir
    1687         set fileName [file join $appDir [CleanName $_saved(Name).sav]]
     1651        set name [CleanName $_saved(Name)]
     1652        set saveDir [file join ~/data/saved $_appName $name]
     1653        set saveDir [file normalize $saveDir]
     1654        file mkdir $saveDir
     1655        set fileName [file join $saveDir $name.sav]
    16881656        if { [file exists $fileName] } {
    16891657            if { ![OverwriteSaveFile] } {
     
    17001668# Use the table to omit specific results
    17011669# Use file chooser to save to specific
    1702 itcl::body Rappture::Analyzer::SelectSimsetToPublish {} {
    1703     if { [GetSimset "publish"] } {
     1670itcl::body Rappture::Analyzer::SelectSimsetToShare {} {
     1671    if { [GetSimset "share"] } {
    17041672        global env
    1705         set shareDir [file join /data/tools/shared $_appName $env(USER)]
     1673        set name [CleanName $_saved(Name)]
     1674        set shareDir [file join /data/tools/shared $env(USER) $_appName $name]
    17061675        if { [catch {
    1707             file mkdir $shareDir
    1708             file attributes $shareDir -permissions o+r,g+rw
     1676            CreateSharedPath $shareDir
    17091677        } errs] != 0 } {
    17101678            puts stderr errs=$errs
    17111679            return
    17121680        }
    1713         set fileName [file join $shareDir [CleanName $_saved(Name).sav]]
     1681        set fileName [file join $shareDir $name.sav]
    17141682        if { [file exists $fileName] } {
    17151683            if { ![OverwriteSaveFile] } {
     
    17181686        }
    17191687        WriteSimsetFile $_appName $fileName 1
     1688        ExportURL $_appName $shareDir
    17201689    }
    17211690}
     
    17831752    array unset _saved
    17841753    array set _saved [$_tree get $node]
    1785     set root [file root $_saved(FileName)]
     1754    set saveDir [file dirname $_saved(FileName)]
    17861755    set files {}
    17871756    foreach file $_saved(Files) {
    17881757        if { [file pathtype $file] == "relative" } {
    1789             set file [file join $root $file]
     1758            set file [file join $saveDir $file]
    17901759        }
    17911760        lappend files $file
     
    17981767# WriteSimsetFile --
    17991768#
    1800 #       Write the .sav file and the runfiles in the ~/data/saved/$_appName
    1801 #       directory.  The subdirectory where the runfiles are written is
    1802 #       the root of the .save file name.
    1803 #
    1804 itcl::body Rappture::Analyzer::WriteSimsetFile { appName fileName publish } {
    1805     # The runfiles directory is the root of the filename.  For example, if
    1806     # the simset file is /path/to/myName.sav, the runfile directory is
    1807     # /path/to/myName
    1808     set root [file root $fileName]
    1809     if { [file exists $root] } {
    1810         file delete -force $root
     1769#       Write the .sav file and the runfiles in the
     1770#            ~/data/saved/$_appName/$name
     1771#       directory. 
     1772# The run files will be in the same directory as the .sav file. 
     1773# For example, if the simset file is /path/to/appName/myName/myName.sav,
     1774# the runfile directory is /path/to/appName/myName.
     1775#
     1776itcl::body Rappture::Analyzer::WriteSimsetFile { appName fileName share } {
     1777    set saveDir [file dirname $fileName]
     1778    if { [file exists $saveDir] } {
     1779        file delete -force $saveDir
    18111780    }
    18121781    if { [catch {
    1813         file mkdir $root
     1782        if { $share } {
     1783            CreateSharedPath $saveDir
     1784        } else {
     1785            file mkdir $saveDir
     1786        }
    18141787        set f [open $fileName "w"]
    18151788        puts $f [list "Name"        $_saved(Name)]
     
    18231796        foreach file $_saved(Files) {
    18241797            set tail [file tail $file]
    1825             set dest [file join $root $tail]
    1826             file copy -force $file $dest
    1827             if { $publish } {
    1828                 file attributes $dest -permissions o+r,g+rw
     1798            set dest [file join $saveDir $tail]
     1799            if { $share } {
     1800                InstallSharedFile $saveDir $file
     1801            } else {
     1802                file copy -force $file $dest
    18291803            }
    18301804            lappend runfiles $tail
     
    18321806        puts $f [list "Files" $runfiles]
    18331807        close $f
    1834         if { $publish } {
     1808        if { $share } {
    18351809            file attributes $fileName -permissions o+r,g+rw
    18361810        }
     
    18491823    Rappture::Balloon $popup -title "Save set of simulations..."
    18501824    set inner [$popup component inner]
    1851    
     1825
    18521826    label $inner.name_l -text "Simulation Set Name"
    18531827    entry $inner.name -background white
     
    19141888        return 0
    19151889    }
    1916     set root [file root $fileName]
     1890    set saveDir [file dirname $fileName]
    19171891    foreach file $_saved(Files) {
    19181892        if { [file pathtype $file] == "relative" } {
    1919             set file [file join $root $file]
     1893            set file [file join $saveDir $file]
    19201894        }
    19211895        if { ![file readable $file] } {
     
    19381912itcl::body Rappture::Analyzer::LoadSimulations { files } {
    19391913    set loadobjs {}
    1940     set root [file root $_saved(FileName)]
     1914    set saveDir [file dirname $_saved(FileName)]
    19411915    foreach runfile $files {
    19421916        if { [file pathtype $runfile] == "relative" } {
    1943             set runfile [file join $root $runfile]
     1917            set runfile [file join $saveDir $runfile]
    19441918        }
    19451919        if { ![file exists $runfile] } {
     
    19591933    $win.pager current analyzer
    19601934    $win.pager configure -nosim 0
    1961    if 0 {
    1962     # Load the inputs for the very last run
    1963     global tool
    1964     $tool load $runobj
    1965 }
    19661935}
    19671936
     
    19741943    }
    19751944    if { [GetSimset "delete"] } {
    1976         set root [file root $_saved(FileName)]
    1977         file delete -force $root
    1978         file delete -force $_saved(FileName)
     1945        set saveDir [file dirname $_saved(FileName)]
     1946        file delete -force $saveDir
    19791947    }
    19801948}
     
    19841952#
    19851953itcl::body Rappture::Analyzer::FindSimsetsForApp { appName } {
     1954    if { $appName == "" } {
     1955        puts stderr "No application name found"
     1956        return 0
     1957    }
    19861958    $_tree delete 0
    1987     foreach fileName [glob -nocomplain ~/data/saved/$appName/*.sav] {
     1959    foreach fileName [glob -nocomplain ~/data/saved/$appName/*/*.sav] {
    19881960        if { [ReadSimsetFile $fileName] } {
    19891961            if { $_revision > 0 && [info exists _saved(Revision)] &&
     
    20201992    scrollbar $inner.ys -orient vertical -command "$tv yview"
    20211993    frame $inner.controls
    2022        
     1994   
    20231995    $tv column insert end "Name" "Description" "Date" "Creator"
    20241996    $tv column configure treeView -hide yes
     
    20922064    # Create the print dialog widget and add it to the the balloon popup.
    20932065    label $popup.title -text " " \
    2094         -padx 10 -pady 10 \
    2095         -background grey92
     2066        -padx 10 -pady 10 \
     2067        -background grey92
    20962068    button $popup.yes -text "Yes" \
    2097         -highlightthickness 0 \
    2098         -bd 2  \
    2099         -command [itcl::code $this Save]
     2069        -highlightthickness 0 \
     2070        -bd 2  \
     2071        -command [itcl::code $this Save]
    21002072    button $popup.no -text "No" \
    2101         -highlightthickness 0 \
    2102         -bd 2 \
    2103         -command [itcl::code $this Cancel]
     2073        -highlightthickness 0 \
     2074        -bd 2 \
     2075        -command [itcl::code $this Cancel]
    21042076    blt::table $popup \
    2105         0,0 $popup.title -cspan 2  -fill x -pady 4 \
    2106         1,0 $popup.yes -width { 0 1i .6i } -pady 4 \
    2107         1,1 $popup.no -width { 0 1i .6i }  -pady 4
     2077        0,0 $popup.title -cspan 2  -fill x -pady 4 \
     2078        1,0 $popup.yes -width { 0 1i .6i } -pady 4 \
     2079        1,1 $popup.no -width { 0 1i .6i }  -pady 4
    21082080    blt::table configure $popup  r2 -height 0.125i
    21092081}
     
    21162088    set popup .question
    21172089    if { ![winfo exists $popup] } {
    2118         BuildQuestionDialog $popup
     2090        BuildQuestionDialog $popup
    21192091    }
    21202092    set text "Simulation set \"$_saved(Name)\" already exists. Overwrite?"
     
    21432115    return $doSave
    21442116}
     2117
     2118itcl::body Rappture::Analyzer::InstallSharedFile { installdir file } {
     2119    set dst [file join $installdir [file tail $file]]
     2120    file copy -force $file $dst
     2121    file attributes $dst -permissions g+rw,o+r
     2122    return $dst
     2123}
     2124
     2125itcl::body Rappture::Analyzer::CreateSharedPath { path } {
     2126    set dir ""
     2127    foreach file [file split $path] {
     2128        set dir [file join $dir $file]
     2129        if { [file exists $dir] } {
     2130            if { ![file isdirectory $dir] } {
     2131                error "error in path \"$path\": \"$dir\" is not a directory."
     2132            }
     2133        } else {
     2134            file mkdir $dir
     2135            file attributes $dir -permissions g+rwx,o+rx
     2136        }
     2137    }
     2138}
     2139
     2140itcl::body Rappture::Analyzer::ExportURL { appName installdir } {
     2141    set fileName [file join $installdir url.txt]
     2142    set name [file tail $installdir]
     2143    set f [open $fileName "w"]
     2144    puts $f "https://nanohub.org/tools/$appName/invoke?params=file(simset):$installdir/$name.sav\n"
     2145    close $f
     2146    file attributes $fileName -permissions g+rw,o+r
     2147    if { [file exists /usr/bin/exportfile] } {
     2148        set msgFile [file join $::Rappture::installdir export.html]
     2149        ExportFile $fileName $msgFile
     2150    }
     2151}
     2152
     2153itcl::body Rappture::Analyzer::ExportFile { src msgFile } {
     2154    set dstdir ~/.filexfer/exportfile
     2155    file mkdir $dstdir
     2156    set dst [file join $dstdir [file tail $src]]
     2157    if { [file exists $dst] } {
     2158        puts stderr "could be a problem: already waiting to export $dst"
     2159    }
     2160    file copy -force $src $dst
     2161    # Now export the file.
     2162    if { [catch {
     2163        global exportFileVar
     2164        set exportFileVar 0;            # Kill any previous export.
     2165        set mesg "Select file to export to desktop/laptop"
     2166        update
     2167        set cmd "/usr/bin/exportfile --delete $dst --timeout 3 "
     2168        if { [file exists $msgFile] } {
     2169            append cmd "--message $msgFile"
     2170        }
     2171        blt::bgexec exportFileVar /bin/sh -c $cmd &
     2172    } errs]  != 0 } {
     2173        global errorInfo
     2174        puts stderr "err: $errorInfo"
     2175        file delete -force $dst
     2176    }
     2177}
     2178
Note: See TracChangeset for help on using the changeset viewer.