(mycli: 'MyCli', cli_args: 'CliArgs')
| 130 | |
| 131 | |
| 132 | def main_batch_with_progress_bar(mycli: 'MyCli', cli_args: 'CliArgs') -> int: |
| 133 | goal_statements = 0 |
| 134 | if cli_args.batch is None: |
| 135 | return 1 |
| 136 | if not sys.stdin.isatty() and cli_args.batch != '-': |
| 137 | click.secho('Ignoring STDIN since --batch was also given.', err=True, fg='yellow') |
| 138 | if os.path.exists(cli_args.batch) and not os.path.isfile(cli_args.batch): |
| 139 | click.secho('--progress is only compatible with a plain file.', err=True, fg='red') |
| 140 | return 1 |
| 141 | try: |
| 142 | completed_statement_count = replay_checkpoint_file(cli_args.batch, cli_args.checkpoint, cli_args.resume, progress=True) |
| 143 | batch_count_h = click.open_file(cli_args.batch) |
| 144 | with yaspin(text='validating batch ', side='right', stream=sys.stderr) as spinner: |
| 145 | for _statement, _counter in statements_from_filehandle(batch_count_h): |
| 146 | goal_statements += 1 |
| 147 | spinner.ok('✔') |
| 148 | batch_count_h.close() |
| 149 | batch_h = click.open_file(cli_args.batch) |
| 150 | batch_gen = statements_from_filehandle(batch_h) |
| 151 | except (OSError, FileNotFoundError): |
| 152 | click.secho(f'Failed to open --batch file: {cli_args.batch}', err=True, fg='red') |
| 153 | return 1 |
| 154 | except ValueError as e: |
| 155 | click.secho(f'Error reading --batch file: {cli_args.batch}: {e}', err=True, fg='red') |
| 156 | return 1 |
| 157 | except CheckpointReplayError as e: |
| 158 | name = cli_args.checkpoint if cli_args.checkpoint else 'None' |
| 159 | click.secho(f'Error replaying --checkpoint file: {name}: {e}', err=True, fg='red') |
| 160 | return 1 |
| 161 | try: |
| 162 | if goal_statements: |
| 163 | pb_style = prompt_toolkit.styles.Style.from_dict({'bar-a': 'reverse'}) |
| 164 | custom_formatters = [ |
| 165 | progress_bar_formatters.Bar(start='running queries [', end=']', sym_a=' ', sym_b=' ', sym_c=' '), |
| 166 | progress_bar_formatters.Text(' '), |
| 167 | progress_bar_formatters.Progress(), |
| 168 | progress_bar_formatters.Text(' '), |
| 169 | progress_bar_formatters.Text('eta ', style='class:time-left'), |
| 170 | progress_bar_formatters.TimeLeft(), |
| 171 | progress_bar_formatters.Text(' ', style='class:time-left'), |
| 172 | ] |
| 173 | err_output = prompt_toolkit.output.create_output(stdout=sys.stderr, always_prefer_tty=True) |
| 174 | with ProgressBar(style=pb_style, formatters=custom_formatters, output=err_output) as pb: |
| 175 | for _pb_counter in pb(range(goal_statements)): |
| 176 | statement, statement_counter = next(batch_gen) |
| 177 | if statement_counter < completed_statement_count: |
| 178 | continue |
| 179 | dispatch_batch_statements(mycli, cli_args, statement, statement_counter) |
| 180 | except (ValueError, StopIteration, IOError, OSError, pymysql.err.Error) as e: |
| 181 | click.secho(str(e), err=True, fg='red') |
| 182 | return 1 |
| 183 | finally: |
| 184 | batch_h.close() |
| 185 | return 0 |
| 186 | |
| 187 | |
| 188 | def main_batch_without_progress_bar(mycli: 'MyCli', cli_args: 'CliArgs') -> int: |
no test coverage detected