source: CPL/oasis3-mct/branches/OASIS3-MCT_2.0_branch/util/oasisgui/opentea/openpipe.tcl @ 6844

Last change on this file since 6844 was 4775, checked in by aclsce, 5 years ago
  • Imported oasis3-mct from Cerfacs svn server (not suppotred anymore).

The version has been extracted from https://oasis3mct.cerfacs.fr/svn/branches/OASIS3-MCT_2.0_branch/oasis3-mct@1818

File size: 8.0 KB
Line 
1#  This program is under CECILL_B licence. See footer for details.
2
3proc openPipe {win address} {
4    global widgetInfo codesPath tmpTree metaTree loadedProject workingDir configTree configPath
5   
6    Start_think "stopScript $win $address"
7   
8    #$win.action.progress start
9   
10    # Check that project has been been saved at least once, otherwise, quit
11    if {$loadedProject == "none"} {
12        log "The project needs to be saved first"
13        #tk_messageBox -message "The project first needs to be saved " -type ok -icon warning
14        Save_XML_File "new"
15    }
16   
17    if {$loadedProject == "none" || $loadedProject == ""} {
18        warning "The project is not savec. Aborting..."
19        Stop_think normal
20        return
21    }   
22   
23    saveDataset "dataset.xml" $address
24   
25   
26    # Detects type of script
27    set script $widgetInfo($address-scriptAddress)
28    set ext [file extension $script]
29    set pythonInterpreter "python"
30    if {[getConfig "config gui python interpreter"] == "user_specific"} {
31        set pythonInterpreter [getConfig "config gui python user_specific interpreter"]
32        log "python interpreter is now : $pythonInterpreter"
33    }
34    switch $ext {
35        ".py" {
36            execScript $win $address $pythonInterpreter
37        }
38        ".tcl" {
39           # set execCommand "wish $script"
40            execScript $win $address "tclsh" 
41        }
42       
43        default {
44           # set execCommand $script
45            debug "not implemented yet"
46        }
47    }
48   
49   
50#    if { [catch {tk_exec $execCommand} error_id] } {
51#        debug $error_id
52#        #debug $returnScript
53#        set widgetInfo($address-status) 0
54#        $win.action.progress stop
55#        return
56#    } else {
57#        #debug $returnScript
58#       
59#    }
60   
61    #set widgetInfo($address-status) 1
62   
63    #$win.action.progress stop
64   
65    #action_check $win $address
66   
67   
68}
69
70proc execScript {win address interpreter} {
71    global widgetInfo codesPath initializedSolver
72    # If the stop file already exists delete it !
73    # Apparently deprecadted
74    #if {[file exists [file join $initializedSolver stop_[file tail [file rootname $widgetInfo($address-scriptAddress)]]]]} {
75    #    file delete [file join $initializedSolver stop_[file tail [file rootname $widgetInfo($address-scriptAddress)]]]
76    #}
77    eval $widgetInfo($address-onScriptStarts)
78   
79   
80    if {$widgetInfo($address-cancellation) } {
81        log "cancellation of $address"
82        return
83    }
84    set os $::tcl_platform(os)
85    if {$os == "Windows NT"} {
86        #set execCommand "cmd \"$interpreter $widgetInfo($address-scriptAddress)\" "
87        set execCommand "$interpreter $widgetInfo($address-scriptAddress) $widgetInfo($address-args)"     
88    } else {
89        set execCommand "$interpreter $widgetInfo($address-scriptAddress) $widgetInfo($address-args)"
90    }   
91   
92    #log "\"$execCommand\" is now running"
93    set widgetInfo($address-starttime) [clock milliseconds]
94    set widgetInfo($address-actionChan) [open "| $execCommand" "r+"]
95    fileevent $widgetInfo($address-actionChan) readable "readPipe $win $address" 
96}
97
98proc readPipe {win address} {
99    global widgetInfo DStree metaTree
100    if {[gets $widgetInfo($address-actionChan) line] >= 0} {
101        if {[regexp {^%\d{1,3}%.*$} $line]} {
102            set line [split $line "%"]
103            set percent [lindex $line 1]
104            set message [join [lrange $line 2 end] "%"]
105            set widgetInfo($address-progressValue) $percent
106            set widgetInfo($address-status_txt) $message
107            eval $widgetInfo($address-updateProgress)
108        } else {
109            set tagid "none"
110            if {[string match "Ok*" $line]} { set tagid "ok"}
111            if {[string match "Error*" $line]} { set tagid "warning"}
112            if {[string match "Note*" $line]} { set tagid "debug"}
113            if {[string match "XDRExecute*" $line]} {
114                set tagid "xdrexecute"
115                set line [string map "XDRExecute >" $line]
116            }
117            log $line $tagid
118        }
119       
120    } else {
121        # Normal end
122        success "Script $widgetInfo($address-scriptAddress) is completed."
123        if {[catch {close $widgetInfo($address-actionChan) } err] } {
124            warning "Error in script $widgetInfo($address-scriptAddress) :\n$err"
125            set widgetInfo($address-status) 0   
126            set scriptStatus 0
127        } elseif {![file exists "out_dataset.xml"]} {
128            warning "No information found about this action. \n  Possible Causes \n - finish() statement not reached \n - permission denied on filesystem \n - disk quota exceeded \n\n Graphical application might behave erratically from now on..."
129           
130            set widgetInfo($address-status) 0   
131            set scriptStatus 0           
132        } else {
133            set widgetInfo($address-status) 1
134            loadDataset "out_dataset.xml"
135            file delete "out_dataset.xml"   
136            set scriptStatus [dTree_getAttribute $metaTree "root meta scriptSuccess" "value"]                 
137        }
138         
139       
140        #set dummyTree ""
141        #dTree_init dummyTree
142        #parseFile "out_dataset.xml" dummyTree "" "DStree"
143       
144       
145        #dTree_copyBranch dummyTree [gui2tree $address] DStree [lrange [gui2tree $address] 0 end-1]
146        # We need to reconstruct interface (multiple which depends on an unknown list have to be initialized)
147        #initializeNode tree "root"
148        #RefreshFamily $address
149        #RefreshFamily "root"
150        #CheckValidationStatus $address
151        #action_check $win $address
152        set widgetInfo($address-endtime) [clock milliseconds]
153        if {$scriptStatus == "0"} {
154            eval $widgetInfo($address-onScriptStops)           
155        } else {
156            eval $widgetInfo($address-onScriptEnds)
157        }
158       
159        Stop_think normal
160       
161    }
162}
163
164proc stopScript {win address} {
165    global codesPath widgetInfo debug
166   
167    warning "Trying to stop script. Zombies process can still be running. Beware !!!"
168#    debug "writing [file join $codesPath stop_[file tail [file rootname $widgetInfo($address-scriptAddress)]]]"
169#    set stopFile [open [file join $codesPath "stop_[file tail [file rootname $widgetInfo($address-scriptAddress)]]"] "w"]
170#    close $stopFile
171    set widgetInfo($address-endtime) [clock milliseconds]
172   
173    catch {close $widgetInfo($address-actionChan)} err
174   
175    eval $widgetInfo($address-onScriptStops)
176   
177} 
178
179
180
181#  Copyright CERFACS 2014
182#   
183#  antoine.dauptain@cerfacs.fr
184#   
185#  This software is a computer program whose purpose is to ensure technology
186#  transfer between academia and industry.
187#   
188#  This software is governed by the CeCILL-B license under French law and
189#  abiding by the rules of distribution of free software.  You can  use,
190#  modify and/ or redistribute the software under the terms of the CeCILL-B
191#  license as circulated by CEA, CNRS and INRIA at the following URL
192#  "http://www.cecill.info".
193#   
194#  As a counterpart to the access to the source code and  rights to copy,
195#  modify and redistribute granted by the license, users are provided only
196#  with a limited warranty  and the software's author,  the holder of the
197#  economic rights,  and the successive licensors  have only  limited
198#  liability.
199#   
200#  In this respect, the user's attention is drawn to the risks associated
201#  with loading,  using,  modifying and/or developing or reproducing the
202#  software by the user in light of its specific status of free software,
203#  that may mean  that it is complicated to manipulate,  and  that  also
204#  therefore means  that it is reserved for developers  and  experienced
205#  professionals having in-depth computer knowledge. Users are therefore
206#  encouraged to load and test the software's suitability as regards their
207#  requirements in conditions enabling the security of their systems and/or
208#  data to be ensured and,  more generally, to use and operate it in the
209#  same conditions as regards security.
210#   
211#  The fact that you are presently reading this means that you have had
212#  knowledge of the CeCILL-B license and that you accept its terms.
Note: See TracBrowser for help on using the repository browser.