(params, commands=None, command_delay=0, quiet=False)
| 477 | |
| 478 | |
| 479 | def runcommands(params, commands=None, command_delay=0, quiet=False): |
| 480 | if commands is None: |
| 481 | commands = params.commands |
| 482 | |
| 483 | keep_running = True |
| 484 | first_command = True |
| 485 | timedelay = params.timedelay |
| 486 | |
| 487 | while keep_running: |
| 488 | for command in commands: |
| 489 | if first_command: |
| 490 | first_command = False |
| 491 | elif command_delay != 0: |
| 492 | time.sleep(command_delay) |
| 493 | |
| 494 | if not quiet: |
| 495 | logging.info('Executing [%s]...', command) |
| 496 | try: |
| 497 | result = do_command(params, command) |
| 498 | if result is not None: |
| 499 | print(result) |
| 500 | except CommandError as e: |
| 501 | msg = f'{e.command}: {e.message}' if e.command else f'{e.message}' |
| 502 | logging.error(msg) |
| 503 | except Error as e: |
| 504 | logging.error("Communication Error: %s", e.message) |
| 505 | except Exception as e: |
| 506 | logging.debug(e, exc_info=True) |
| 507 | logging.error('An unexpected error occurred: %s', sys.exc_info()[0]) |
| 508 | |
| 509 | if timedelay == 0: |
| 510 | keep_running = False |
| 511 | else: |
| 512 | logging.info("%s Waiting for %d seconds", datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S'), timedelay) |
| 513 | try: |
| 514 | time.sleep(timedelay) |
| 515 | except KeyboardInterrupt: |
| 516 | keep_running = False |
| 517 | |
| 518 | |
| 519 | def force_quit(): |
nothing calls this directly
no test coverage detected