| 62 | return run_batch_parser |
| 63 | |
| 64 | def execute(self, params, **kwargs): |
| 65 | dry_run = kwargs.get('dry_run', False) |
| 66 | command_delay = kwargs.get('delay') or 0 |
| 67 | quiet = kwargs.get('quiet', False) |
| 68 | pattern_list = kwargs.get('batch-file-patterns', []) |
| 69 | if len(pattern_list) == 0: |
| 70 | logging.warning(f'Please specify one or more batch files to run') |
| 71 | return |
| 72 | |
| 73 | if dry_run: |
| 74 | print('The following files and commands would be run:') |
| 75 | for pattern in pattern_list: |
| 76 | for filepath in glob(pattern): |
| 77 | filepath = normpath(filepath) |
| 78 | if dry_run: |
| 79 | print(f'{filepath}:') |
| 80 | elif not quiet: |
| 81 | logging.info(f'Running Keeper Commander batch file {filepath}...') |
| 82 | |
| 83 | with open(filepath, encoding='utf-8') as f: |
| 84 | lines = f.readlines() |
| 85 | commands = [c.strip() for c in lines if not c.startswith('#')] |
| 86 | if len(commands) > 0: |
| 87 | if dry_run: |
| 88 | print(' ' + '\n '.join(commands)) |
| 89 | else: |
| 90 | cli.runcommands(params, commands=commands, command_delay=command_delay, quiet=quiet) |
| 91 | else: |
| 92 | if dry_run: |
| 93 | print('No commands') |
| 94 | else: |
| 95 | logging.warning(f'No commands to execute in batch file {filepath}') |
| 96 | |
| 97 | |
| 98 | class SleepCommand(Command): |