Fix comment indentation
Markus Gerstel
4 years ago
60 | 60 | |
61 | 61 | class _LineAggregator(object): |
62 | 62 | """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.""" | |
66 | 66 | |
67 | 67 | def __init__(self, print_line=False, callback=None): |
68 | 68 | """Create aggregator object.""" |
73 | 73 | |
74 | 74 | def add(self, data): |
75 | 75 | """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.""" | |
77 | 77 | data = self._decoder.decode(data) |
78 | 78 | if not data: |
79 | 79 | return |
165 | 165 | |
166 | 166 | def get_output(self): |
167 | 167 | """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.""" | |
169 | 169 | self._closing = True |
170 | 170 | if not self.has_finished(): |
171 | 171 | if self._debug: |
253 | 253 | |
254 | 254 | def _windows_resolve(command): |
255 | 255 | """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. | |
267 | 267 | """ |
268 | 268 | try: |
269 | 269 | import win32api |
327 | 327 | ): |
328 | 328 | """Run an external process. |
329 | 329 | |
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. | |
351 | 351 | """ |
352 | 352 | |
353 | 353 | time_start = time.strftime("%Y-%m-%d %H:%M:%S GMT", time.gmtime()) |
514 | 514 | |
515 | 515 | def run_process_dummy(command, **kwargs): |
516 | 516 | """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.""" | |
518 | 518 | warnings.warn( |
519 | 519 | "procrunner.run_process_dummy() is deprecated", DeprecationWarning, stacklevel=2 |
520 | 520 | ) |