Package list python-procrunner / 49966d6
Fix comment indentation Markus Gerstel 2 years ago
1 changed file(s) with 38 addition(s) and 38 deletion(s). Raw diff Collapse all Expand all
6060
6161 class _LineAggregator(object):
6262 """Buffer that can be filled with stream data and will aggregate complete
63 lines. Lines can be printed or passed to an arbitrary callback function.
64 The lines passed to the callback function are UTF-8 decoded and do not
65 contain a trailing newline character."""
63 lines. Lines can be printed or passed to an arbitrary callback function.
64 The lines passed to the callback function are UTF-8 decoded and do not
65 contain a trailing newline character."""
6666
6767 def __init__(self, print_line=False, callback=None):
6868 """Create aggregator object."""
7373
7474 def add(self, data):
7575 """Add a single character to buffer. If one or more full lines are found,
76 print them (if desired) and pass to callback function."""
76 print them (if desired) and pass to callback function."""
7777 data = self._decoder.decode(data)
7878 if not data:
7979 return
165165
166166 def get_output(self):
167167 """Retrieve the stored data in full.
168 This call may block if the reading thread has not yet terminated."""
168 This call may block if the reading thread has not yet terminated."""
169169 self._closing = True
170170 if not self.has_finished():
171171 if self._debug:
253253
254254 def _windows_resolve(command):
255255 """Try and find the full path and file extension of the executable to run.
256 This is so that e.g. calls to 'somescript' will point at 'somescript.cmd'
257 without the need to set shell=True in the subprocess.
258 If the executable contains periods it is a special case. Here the
259 win32api call will fail to resolve the extension automatically, and it
260 has do be done explicitly.
261
262 :param command: The command array to be run, with the first element being
263 the command with or w/o path, with or w/o extension.
264 :return: Returns the command array with the executable resolved with the
265 correct extension. If the executable cannot be resolved for any
266 reason the original command array is returned.
256 This is so that e.g. calls to 'somescript' will point at 'somescript.cmd'
257 without the need to set shell=True in the subprocess.
258 If the executable contains periods it is a special case. Here the
259 win32api call will fail to resolve the extension automatically, and it
260 has do be done explicitly.
261
262 :param command: The command array to be run, with the first element being
263 the command with or w/o path, with or w/o extension.
264 :return: Returns the command array with the executable resolved with the
265 correct extension. If the executable cannot be resolved for any
266 reason the original command array is returned.
267267 """
268268 try:
269269 import win32api
327327 ):
328328 """Run an external process.
329329
330 :param array command: Command line to be run, specified as array.
331 :param timeout: Terminate program execution after this many seconds.
332 :param boolean debug: Enable further debug messages.
333 :param stdin: Optional string that is passed to command stdin.
334 :param boolean print_stdout: Pass stdout through to sys.stdout.
335 :param boolean print_stderr: Pass stderr through to sys.stderr.
336 :param callback_stdout: Optional function which is called for each
337 stdout line.
338 :param callback_stderr: Optional function which is called for each
339 stderr line.
340 :param dict environment: The full execution environment for the command.
341 :param dict environment_override: Change environment variables from the
342 current values for command execution.
343 :param boolean win32resolve: If on Windows, find the appropriate executable
344 first. This allows running of .bat, .cmd, etc.
345 files without explicitly specifying their
346 extension.
347 :param string working_directory: If specified, run the executable from
348 within this working directory.
349 :return: A dictionary containing stdout, stderr (both as bytestrings),
350 runtime, exitcode, and more.
330 :param array command: Command line to be run, specified as array.
331 :param timeout: Terminate program execution after this many seconds.
332 :param boolean debug: Enable further debug messages.
333 :param stdin: Optional string that is passed to command stdin.
334 :param boolean print_stdout: Pass stdout through to sys.stdout.
335 :param boolean print_stderr: Pass stderr through to sys.stderr.
336 :param callback_stdout: Optional function which is called for each
337 stdout line.
338 :param callback_stderr: Optional function which is called for each
339 stderr line.
340 :param dict environment: The full execution environment for the command.
341 :param dict environment_override: Change environment variables from the
342 current values for command execution.
343 :param boolean win32resolve: If on Windows, find the appropriate executable
344 first. This allows running of .bat, .cmd, etc.
345 files without explicitly specifying their
346 extension.
347 :param string working_directory: If specified, run the executable from
348 within this working directory.
349 :return: A dictionary containing stdout, stderr (both as bytestrings),
350 runtime, exitcode, and more.
351351 """
352352
353353 time_start = time.strftime("%Y-%m-%d %H:%M:%S GMT", time.gmtime())
514514
515515 def run_process_dummy(command, **kwargs):
516516 """A stand-in function that returns a valid result dictionary indicating a
517 successful execution. The external process is not run."""
517 successful execution. The external process is not run."""
518518 warnings.warn(
519519 "procrunner.run_process_dummy() is deprecated", DeprecationWarning, stacklevel=2
520520 )