Module EDActionExecuteSystemCommand
[hide private]
[frames] | no frames]

Source Code for Module EDActionExecuteSystemCommand

 1  # 
 2  #    Project: The EDNA Kernel 
 3  #             http://www.edna-site.org 
 4  # 
 5  #    File: "$Id$" 
 6  # 
 7  #    Copyright (C) 2008-2009 European Synchrotron Radiation Facility 
 8  #                            Grenoble, France 
 9  # 
10  #    Principal authors: Marie-Francoise Incardona (incardon@esrf.fr) 
11  #                       Olof Svensson (svensson@esrf.fr)  
12  # 
13  #    This program is free software: you can redistribute it and/or modify 
14  #    it under the terms of the GNU Lesser General Public License as published 
15  #    by the Free Software Foundation, either version 3 of the License, or 
16  #    (at your option) any later version. 
17  # 
18  #    This program is distributed in the hope that it will be useful, 
19  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
20  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
21  #    GNU Lesser General Public License for more details. 
22  # 
23  #    You should have received a copy of the GNU General Public License 
24  #    and the GNU Lesser General Public License  along with this program.   
25  #    If not, see <http://www.gnu.org/licenses/>. 
26  # 
27   
28   
29  __authors__ = [ "Marie-Francoise Incardona", "Olof Svensson", "Jerome Kieffer" ] 
30  __contact__ = "svensson@esrf.fr" 
31  __license__ = "LGPLv3+" 
32  __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" 
33   
34  """ 
35  This class is used for executing and controlling external applications  
36  such as scripts. 
37  """ 
38   
39   
40  import os, subprocess, signal 
41   
42  from EDAction import EDAction 
43  from EDVerbose import EDVerbose 
44   
45   
46   
47 -class EDActionExecuteSystemCommand(EDAction):
48 """ 49 This class executes a process using the Python os.sytem command. 50 It is a temporary solution for the "==>[ERROR]: OSError: [Errno 10] No child processes" 51 problem with ALActionProcess (Python bug in subprocess, see bug #61). 52 """ 53 54
55 - def __init__(self, _strCommand):
56 """ 57 Initializes the class: the argument _strCommand should be 58 the complete command line, i.e. path to executable + command line arguments 59 """ 60 EDAction.__init__(self) 61 self.__strCommand = _strCommand 62 self.__strExecutionStatus = None 63 self.__subprocess = None 64 self.__iPID = None
65 66
67 - def process(self, _edPlugin=None):
68 """ 69 Executes the command line using the standard Python os.system command. 70 The result of the os.system command is converted into an str. 71 """ 72 EDVerbose.DEBUG("*** EDActionExecuteSystemCommand.process") 73 self.__subprocess = subprocess.Popen (self.__strCommand, shell=True) 74 self.__iPID = self.__subprocess.pid 75 executionStatus = self.__subprocess.wait() 76 if (executionStatus is None): 77 # If the status returned is None, return an empty string 78 self.__strExecutionStatus = str() 79 else: 80 self.__strExecutionStatus = str(executionStatus)
81 82
83 - def getExecutionStatus(self):
84 """ 85 Returns the string containing the execution status. 86 """ 87 return self.__strExecutionStatus
88 89
90 - def abort(self, _edObject=None):
91 """ 92 This method can be used to abort the process, for example when 93 the execution time has exceeded the maximum allowed execution time. 94 """ 95 EDVerbose.DEBUG("*** EDActionExecuteSystemCommand.abort") 96 os.kill(self.__iPID, signal.SIGKILL) 97 self.m_bIsAbort = True
98