|
39 | 39 | # |
40 | 40 | # Returns: |
41 | 41 | # |
42 | | -# ReturnObject( |
| 42 | +# subprocess.CompletedProcess( |
43 | 43 | # args=('/bin/ls', '/some/path/containing spaces'), |
44 | 44 | # returncode=2, |
45 | 45 | # stdout=b'', |
46 | 46 | # stderr=b'/bin/ls: cannot access /some/path/containing spaces: No such file or directory\n' |
47 | 47 | # ) |
48 | | -# |
49 | | -# which also offers (albeit deprecated) |
50 | | -# |
51 | | -# result.runtime == 0.12990689277648926 |
52 | | -# result.time_end == '2017-11-12 19:54:49 GMT' |
53 | | -# result.time_start == '2017-11-12 19:54:49 GMT' |
54 | | -# result.timeout == False |
55 | 48 |
|
56 | 49 | __version__ = "2.3.1" |
57 | 50 |
|
@@ -307,114 +300,6 @@ def _windows_resolve(command, path=None): |
307 | 300 | return command |
308 | 301 |
|
309 | 302 |
|
310 | | -class ReturnObject(subprocess.CompletedProcess): |
311 | | - """ |
312 | | - A subprocess.CompletedProcess-like object containing the executed |
313 | | - command, stdout and stderr (both as bytestrings), and the exitcode. |
314 | | - The check_returncode() function raises an exception if the process |
315 | | - exited with a non-zero exit code. |
316 | | - """ |
317 | | - |
318 | | - def __init__(self, exitcode=None, command=None, stdout=None, stderr=None, **kw): |
319 | | - super().__init__( |
320 | | - args=command, returncode=exitcode, stdout=stdout, stderr=stderr |
321 | | - ) |
322 | | - self._extras = { |
323 | | - "timeout": kw.get("timeout"), |
324 | | - "runtime": kw.get("runtime"), |
325 | | - "time_start": kw.get("time_start"), |
326 | | - "time_end": kw.get("time_end"), |
327 | | - } |
328 | | - |
329 | | - def __getitem__(self, key): |
330 | | - warnings.warn( |
331 | | - "dictionary access to a procrunner return object is deprecated", |
332 | | - DeprecationWarning, |
333 | | - stacklevel=2, |
334 | | - ) |
335 | | - if key in self._extras: |
336 | | - return self._extras[key] |
337 | | - if not hasattr(self, key): |
338 | | - raise KeyError(f"Unknown attribute {key}") |
339 | | - return getattr(self, key) |
340 | | - |
341 | | - def __eq__(self, other): |
342 | | - """Override equality operator to account for added fields""" |
343 | | - if type(other) is type(self): |
344 | | - return self.__dict__ == other.__dict__ |
345 | | - return False |
346 | | - |
347 | | - def __hash__(self): |
348 | | - """This object is not immutable, so mark it as unhashable""" |
349 | | - return None |
350 | | - |
351 | | - @property |
352 | | - def cmd(self): |
353 | | - warnings.warn( |
354 | | - "procrunner return object .cmd is deprecated, use .args", |
355 | | - DeprecationWarning, |
356 | | - stacklevel=2, |
357 | | - ) |
358 | | - return self.args |
359 | | - |
360 | | - @property |
361 | | - def command(self): |
362 | | - warnings.warn( |
363 | | - "procrunner return object .command is deprecated, use .args", |
364 | | - DeprecationWarning, |
365 | | - stacklevel=2, |
366 | | - ) |
367 | | - return self.args |
368 | | - |
369 | | - @property |
370 | | - def exitcode(self): |
371 | | - warnings.warn( |
372 | | - "procrunner return object .exitcode is deprecated, use .returncode", |
373 | | - DeprecationWarning, |
374 | | - stacklevel=2, |
375 | | - ) |
376 | | - return self.returncode |
377 | | - |
378 | | - @property |
379 | | - def timeout(self): |
380 | | - warnings.warn( |
381 | | - "procrunner return object .timeout is deprecated", |
382 | | - DeprecationWarning, |
383 | | - stacklevel=2, |
384 | | - ) |
385 | | - return self._extras["timeout"] |
386 | | - |
387 | | - @property |
388 | | - def runtime(self): |
389 | | - warnings.warn( |
390 | | - "procrunner return object .runtime is deprecated", |
391 | | - DeprecationWarning, |
392 | | - stacklevel=2, |
393 | | - ) |
394 | | - return self._extras["runtime"] |
395 | | - |
396 | | - @property |
397 | | - def time_start(self): |
398 | | - warnings.warn( |
399 | | - "procrunner return object .time_start is deprecated", |
400 | | - DeprecationWarning, |
401 | | - stacklevel=2, |
402 | | - ) |
403 | | - return self._extras["time_start"] |
404 | | - |
405 | | - @property |
406 | | - def time_end(self): |
407 | | - warnings.warn( |
408 | | - "procrunner return object .time_end is deprecated", |
409 | | - DeprecationWarning, |
410 | | - stacklevel=2, |
411 | | - ) |
412 | | - return self._extras["time_end"] |
413 | | - |
414 | | - def update(self, dictionary): |
415 | | - self._extras.update(dictionary) |
416 | | - |
417 | | - |
418 | 303 | def _deprecate_argument_calling(f): |
419 | 304 | @functools.wraps(f) |
420 | 305 | def wrapper(*args, **kwargs): |
@@ -445,7 +330,7 @@ def run( |
445 | 330 | win32resolve=True, |
446 | 331 | working_directory=None, |
447 | 332 | raise_timeout_exception=False, |
448 | | -): |
| 333 | +) -> subprocess.CompletedProcess: |
449 | 334 | """ |
450 | 335 | Run an external process. |
451 | 336 |
|
@@ -480,7 +365,6 @@ def run( |
480 | 365 | as a subprocess.CompletedProcess object. |
481 | 366 | """ |
482 | 367 |
|
483 | | - time_start = time.strftime("%Y-%m-%d %H:%M:%S GMT", time.gmtime()) |
484 | 368 | logger.debug("Starting external process: %s", command) |
485 | 369 |
|
486 | 370 | if stdin is None: |
@@ -655,23 +539,6 @@ def run( |
655 | 539 | cmd=command, timeout=timeout, output=stdout, stderr=stderr |
656 | 540 | ) |
657 | 541 |
|
658 | | - time_end = time.strftime("%Y-%m-%d %H:%M:%S GMT", time.gmtime()) |
659 | | - result = ReturnObject( |
660 | | - exitcode=p.returncode, |
661 | | - command=command, |
662 | | - stdout=stdout, |
663 | | - stderr=stderr, |
664 | | - timeout=timeout_encountered, |
665 | | - runtime=runtime, |
666 | | - time_start=time_start, |
667 | | - time_end=time_end, |
| 542 | + return subprocess.CompletedProcess( |
| 543 | + args=command, returncode=p.returncode, stdout=stdout, stderr=stderr |
668 | 544 | ) |
669 | | - if stdin is not None: |
670 | | - result.update( |
671 | | - { |
672 | | - "stdin_bytes_sent": stdin.bytes_sent(), |
673 | | - "stdin_bytes_remain": stdin.bytes_remaining(), |
674 | | - } |
675 | | - ) |
676 | | - |
677 | | - return result |
0 commit comments