MCPcopy Index your code
hub / github.com/dbcli/mycli / replay_checkpoint_file

Function replay_checkpoint_file

mycli/main_modes/batch.py:28–89  ·  view source on GitHub ↗
(
    batch_path: str,
    checkpoint_path: str | None,
    resume: bool,
    progress: bool = False,
)

Source from the content-addressed store, hash-verified

26
27
28def replay_checkpoint_file(
29 batch_path: str,
30 checkpoint_path: str | None,
31 resume: bool,
32 progress: bool = False,
33) -> int:
34 if not resume:
35 return 0
36
37 if checkpoint_path is None:
38 return 0
39
40 if not os.path.exists(checkpoint_path):
41 return 0
42
43 if batch_path == '-':
44 raise CheckpointReplayError('--resume is incompatible with reading from the standard input.')
45
46 completed_count = 0
47 if progress:
48 spinner = yaspin(text='replaying checkpoint', side='right', stream=sys.stderr)
49 spinner.start()
50 try:
51 with click.open_file(batch_path) as batch_h, click.open_file(checkpoint_path, mode='r', encoding='utf-8') as checkpoint_h:
52 try:
53 batch_gen = statements_from_filehandle(batch_h)
54 except ValueError as e:
55 if progress:
56 spinner.fail('✘')
57 raise CheckpointReplayError(f'Error reading --batch file: {batch_path}: {e}') from None
58 for checkpoint_statement, _checkpoint_counter in statements_from_filehandle(checkpoint_h):
59 try:
60 batch_statement, _batch_counter = next(batch_gen)
61 except StopIteration:
62 if progress:
63 spinner.fail('✘')
64 raise CheckpointReplayError('Checkpoint script longer than batch script.') from None
65 except ValueError as e:
66 if progress:
67 spinner.fail('✘')
68 raise CheckpointReplayError(f'Error reading --batch file: {batch_path}: {e}') from None
69 if checkpoint_statement != batch_statement:
70 if progress:
71 spinner.fail('✘')
72 raise CheckpointReplayError(f'Statement mismatch: {checkpoint_statement}.')
73 completed_count += 1
74 if progress:
75 spinner.ok('✔')
76 except ValueError as e:
77 if progress:
78 spinner.fail('✘')
79 raise CheckpointReplayError(f'Error reading --checkpoint file: {checkpoint_path}: {e}') from None
80 except FileNotFoundError as e:
81 if progress:
82 spinner.fail('✘')
83 raise CheckpointReplayError(f'FileNotFoundError: {e}') from None
84 except OSError as e:
85 if progress:

Callers 2

Calls 5

failMethod · 0.80
okMethod · 0.80
startMethod · 0.45

Tested by

no test coverage detected