"Fossies" - the Fresh Open Source Software Archive

Member "svnchecker-0.3/modules/Process.py" (11 Jul 2008, 1367 Bytes) of package /linux/privat/old/svnchecker-0.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "Process.py" see the Fossies "Dox" file reference documentation.

    1 # pylint: disable-msg=W0231
    2 
    3 # Copyright 2008 German Aerospace Center (DLR)
    4 #
    5 # Licensed under the Apache License, Version 2.0 (the "License");
    6 # you may not use this file except in compliance with the License.
    7 # You may obtain a copy of the License at
    8 #
    9 #     http://www.apache.org/licenses/LICENSE-2.0
   10 #
   11 # Unless required by applicable law or agreed to in writing, software
   12 # distributed under the License is distributed on an "AS IS" BASIS,
   13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14 # See the License for the specific language governing permissions and
   15 # limitations under the License.
   16 
   17 """ Execute a Process and return the output. """
   18 
   19 import subprocess
   20 
   21 class ProcessException(Exception):
   22     def __init__(self, command, exitCode, output):
   23         self.command = command
   24         self.output = output
   25         self.exitCode = exitCode
   26 
   27     def __str__(self):
   28         return "Command '%s' exited with exitCode %s:\n%s" % (self.command, self.exitCode, self.output)
   29 
   30     def __repr__(self):
   31         return self.__str__()
   32 
   33 
   34 def execute(command):
   35     process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
   36     output = process.communicate()[0]
   37     exitCode = process.returncode
   38 
   39     if (exitCode == 0):
   40         return output
   41     else:
   42         raise ProcessException(command, exitCode, output)