Add ddrescue stats for each pass to OST post

This commit is contained in:
2Shirt 2023-07-09 15:33:44 -07:00
parent 456dce5685
commit 40aee20d23
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -348,7 +348,7 @@ class State():
self.ost = osticket.osTicket()
self.progress_out: pathlib.Path = self.log_dir.joinpath('progress.out')
self.mode: str = '?'
self.notes = []
self.notes: set = set()
self.source: hw_disk.Disk | None = None
self.working_dir: pathlib.Path | None = None
self.ui: tui.TUI = tui.TUI('Source')
@ -589,7 +589,8 @@ class State():
"""Generate report of overall and per block_pair results, returns list."""
report = []
stats_str = (
'\tnon-trimmed: {non-trimmed}, '
'... pass: {pass_name} -- '
'non-trimmed: {non-trimmed}, '
'non-scraped: {non-scraped}, '
'bad-sectors: {bad-sector}, '
'slow reads: {slow reads}, '
@ -619,7 +620,8 @@ class State():
stats = self.block_pairs[0].stats
if stats:
try:
report.append(stats_str.format(**stats))
for _name, _stats in stats.items():
report.append(stats_str.format(pass_name=_name, **_stats))
except KeyError:
# Ignore and omit stats
pass
@ -643,7 +645,8 @@ class State():
if not stats:
continue
try:
report.append(stats_str.format(**stats))
for _name, _stats in stats.items():
report.append(stats_str.format(pass_name=_name, **_stats))
except KeyError:
# Ignore and omit stats
pass
@ -651,7 +654,7 @@ class State():
# Notes
if self.notes:
report.append(' ')
report.extend(self.notes)
report.extend(sorted(self.notes))
# Done
return report
@ -1719,7 +1722,7 @@ def get_etoc() -> str:
return etoc
def get_stats() -> dict[str, Any]:
def get_stats(output: str | None = None) -> dict[str, Any]:
"""Get stats from ddrescue output, returns dict."""
output = tmux.capture_pane()
stats = {}
@ -2179,9 +2182,9 @@ def relocate_backup_gpt(state: State, dry_run: bool = True) -> None:
if proc.returncode:
cli.print_error('ERROR: Failed to relocate backup GPT.')
LOG.error('sfdisk result: %s, %s', proc.stdout, proc.stderr)
state.notes.append('NOTE: Failed to relocated backup GPT')
state.notes.add('WARNING: Failed to relocated backup GPT')
else:
state.notes.append('NOTE: Relocated backup GPT to the end of the disk.')
state.notes.add('NOTE: Relocated backup GPT to the end of the disk.')
def run_ddrescue(state, block_pair, pass_name, settings, dry_run=True) -> None:
@ -2251,6 +2254,10 @@ def run_ddrescue(state, block_pair, pass_name, settings, dry_run=True) -> None:
LOG.info('ddrescue cmd: %s', cmd)
return
# Stats
if pass_name not in block_pair.stats:
block_pair.stats[pass_name] = {}
# Start ddrescue and ddrescueview (if enabled)
proc = exe.popen_program(cmd)
if (
@ -2269,9 +2276,6 @@ def run_ddrescue(state, block_pair, pass_name, settings, dry_run=True) -> None:
# Update SMART pane
_update_smart_panes()
# Stats
block_pair.stats.update(get_stats())
# Check destination
warning_message = check_destination_health(state.destination)
if warning_message:
@ -2282,6 +2286,7 @@ def run_ddrescue(state, block_pair, pass_name, settings, dry_run=True) -> None:
_i += 1
# Update progress
block_pair.stats[pass_name].update(get_stats())
block_pair.update_progress(pass_name)
state.update_progress_pane('Active')
@ -2523,9 +2528,9 @@ def zero_fill_destination(state: State, dry_run: bool = True) -> None:
if proc.returncode:
cli.print_error('ERROR: Failed to zero-fill: {block_pair.destination}')
LOG.error('zero-fill error: %s, %s', proc.stdout, proc.stderr)
state.notes.append('NOTE: Failed to zero-fill destination')
state.notes.add('WARNING: Failed to zero-fill destination')
else:
state.notes.append('NOTE: Zero-filled gaps and extra space on destination.')
state.notes.add('NOTE: Zero-filled gaps and extra space on destination.')
if __name__ == '__main__':