util/ProcessLogger.py
changeset 3892 1675b5533e9e
parent 3816 032bf4f225d0
equal deleted inserted replaced
3891:0f375805097a 3892:1675b5533e9e
    26 import os
    26 import os
    27 import sys
    27 import sys
    28 import subprocess
    28 import subprocess
    29 import ctypes
    29 import ctypes
    30 import time
    30 import time
       
    31 import shlex
    31 from threading import Timer, Lock, Thread, Semaphore, Condition
    32 from threading import Timer, Lock, Thread, Semaphore, Condition
    32 import signal
    33 import signal
    33 
    34 
    34 _debug = os.path.exists("BEREMIZ_DEBUG")
    35 _debug = os.path.exists("BEREMIZ_DEBUG")
    35 
    36 
    80                  endlog=None, keyword=None, kill_it=False, cwd=None,
    81                  endlog=None, keyword=None, kill_it=False, cwd=None,
    81                  encoding=None, output_encoding=None, env=None):
    82                  encoding=None, output_encoding=None, env=None):
    82         self.logger = logger
    83         self.logger = logger
    83         if not isinstance(Command, list):
    84         if not isinstance(Command, list):
    84             self.Command_str = Command
    85             self.Command_str = Command
    85             self.Command = []
    86             self.Command = shlex.split(Command)
    86             for i, word in enumerate(Command.replace("'", '"').split('"')):
    87         else:
    87                 if i % 2 == 0:
    88             self.Command = Command
    88                     word = word.strip()
       
    89                     if len(word) > 0:
       
    90                         self.Command.extend(word.split())
       
    91                 else:
       
    92                     self.Command.append(word)
       
    93         else:
       
    94             self.Command = [x if type(x)==str else x.decode() for x in Command]
       
    95             self.Command_str = subprocess.list2cmdline(self.Command)
    89             self.Command_str = subprocess.list2cmdline(self.Command)
    96 
    90 
    97         fsencoding = sys.getfilesystemencoding()
    91         fsencoding = sys.getfilesystemencoding()
    98         self.output_encoding = output_encoding
    92         self.output_encoding = output_encoding
    99 
    93