(params, commands=None, command_delay=0, quiet=False)
| 574 | |
| 575 | |
| 576 | def runcommands(params, commands=None, command_delay=0, quiet=False): |
| 577 | if commands is None: |
| 578 | commands = params.commands |
| 579 | |
| 580 | keep_running = True |
| 581 | first_command = True |
| 582 | timedelay = params.timedelay |
| 583 | |
| 584 | while keep_running: |
| 585 | for command in commands: |
| 586 | if first_command: |
| 587 | first_command = False |
| 588 | elif command_delay != 0: |
| 589 | time.sleep(command_delay) |
| 590 | |
| 591 | if not quiet: |
| 592 | logging.info('Executing [%s]...', command) |
| 593 | try: |
| 594 | result = do_command(params, command) |
| 595 | if result is not None: |
| 596 | print(result) |
| 597 | except CommandError as e: |
| 598 | msg = f'{e.command}: {e.message}' if e.command else f'{e.message}' |
| 599 | logging.error(msg) |
| 600 | except Error as e: |
| 601 | logging.error("Communication Error: %s", e.message) |
| 602 | except Exception as e: |
| 603 | logging.debug(e, exc_info=True) |
| 604 | logging.error('An unexpected error occurred: %s', sys.exc_info()[0]) |
| 605 | |
| 606 | if timedelay == 0: |
| 607 | keep_running = False |
| 608 | else: |
| 609 | logging.info("%s Waiting for %d seconds", datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S'), timedelay) |
| 610 | try: |
| 611 | time.sleep(timedelay) |
| 612 | except KeyboardInterrupt: |
| 613 | keep_running = False |
| 614 | |
| 615 | |
| 616 | def force_quit(): |
nothing calls this directly
no test coverage detected