(params, commands=None, command_delay=0, quiet=False)
| 602 | |
| 603 | |
| 604 | def runcommands(params, commands=None, command_delay=0, quiet=False): |
| 605 | if commands is None: |
| 606 | commands = params.commands |
| 607 | |
| 608 | keep_running = True |
| 609 | first_command = True |
| 610 | timedelay = params.timedelay |
| 611 | |
| 612 | while keep_running: |
| 613 | for command in commands: |
| 614 | if first_command: |
| 615 | first_command = False |
| 616 | elif command_delay != 0: |
| 617 | time.sleep(command_delay) |
| 618 | |
| 619 | if not quiet: |
| 620 | logging.info('Executing [%s]...', command) |
| 621 | try: |
| 622 | result = do_command(params, command) |
| 623 | if result is not None: |
| 624 | print(result) |
| 625 | except CommandError as e: |
| 626 | msg = f'{e.command}: {e.message}' if e.command else f'{e.message}' |
| 627 | logging.error(msg) |
| 628 | except Error as e: |
| 629 | logging.error("Communication Error: %s", e.message) |
| 630 | except Exception as e: |
| 631 | logging.debug(e, exc_info=True) |
| 632 | logging.error('An unexpected error occurred: %s', sys.exc_info()[0]) |
| 633 | |
| 634 | if timedelay == 0: |
| 635 | keep_running = False |
| 636 | else: |
| 637 | logging.info("%s Waiting for %d seconds", datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S'), timedelay) |
| 638 | try: |
| 639 | time.sleep(timedelay) |
| 640 | except KeyboardInterrupt: |
| 641 | keep_running = False |
| 642 | |
| 643 | |
| 644 | def force_quit(): |
nothing calls this directly
no test coverage detected