Updated menu_settings() to use RecoveryState
This commit is contained in:
parent
5948d1a62f
commit
8461e581ea
1 changed files with 29 additions and 22 deletions
|
|
@ -262,7 +262,7 @@ class RecoveryState():
|
||||||
self.block_pairs = []
|
self.block_pairs = []
|
||||||
self.current_pass = 0
|
self.current_pass = 0
|
||||||
self.current_pass_str = '0: Initializing'
|
self.current_pass_str = '0: Initializing'
|
||||||
self.ddrescue_settings = DDRESCUE_SETTINGS.copy()
|
self.settings = DDRESCUE_SETTINGS.copy()
|
||||||
self.finished = False
|
self.finished = False
|
||||||
self.progress_out = '{}/progress.out'.format(global_vars['LogDir'])
|
self.progress_out = '{}/progress.out'.format(global_vars['LogDir'])
|
||||||
self.rescued = 0
|
self.rescued = 0
|
||||||
|
|
@ -569,7 +569,7 @@ def get_status_color(s, t_success=99, t_warn=90):
|
||||||
|
|
||||||
if s in ('Pending',) or str(s)[-2:] in (' b', 'Kb', 'Mb', 'Gb', 'Tb'):
|
if s in ('Pending',) or str(s)[-2:] in (' b', 'Kb', 'Mb', 'Gb', 'Tb'):
|
||||||
color = COLORS['CLEAR']
|
color = COLORS['CLEAR']
|
||||||
elif s in ('Skipped', 'Unknown', 'Working'):
|
elif s in ('Skipped', 'Unknown'):
|
||||||
color = COLORS['YELLOW']
|
color = COLORS['YELLOW']
|
||||||
elif p_recovered >= t_success:
|
elif p_recovered >= t_success:
|
||||||
color = COLORS['GREEN']
|
color = COLORS['GREEN']
|
||||||
|
|
@ -699,7 +699,7 @@ def menu_main(state):
|
||||||
elif selection == 'S':
|
elif selection == 'S':
|
||||||
# Set settings for pass
|
# Set settings for pass
|
||||||
settings = []
|
settings = []
|
||||||
for k, v in state.ddrescue_settings.items():
|
for k, v in state.settings.items():
|
||||||
if not v['Enabled']:
|
if not v['Enabled']:
|
||||||
continue
|
continue
|
||||||
if k[-1:] == '=':
|
if k[-1:] == '=':
|
||||||
|
|
@ -741,7 +741,7 @@ def menu_main(state):
|
||||||
state.set_pass_num()
|
state.set_pass_num()
|
||||||
|
|
||||||
elif selection == 'C':
|
elif selection == 'C':
|
||||||
menu_settings(source)
|
menu_settings(state)
|
||||||
elif selection == 'Q':
|
elif selection == 'Q':
|
||||||
if state.rescued_percent < 100:
|
if state.rescued_percent < 100:
|
||||||
print_warning('Recovery is less than 100%')
|
print_warning('Recovery is less than 100%')
|
||||||
|
|
@ -751,7 +751,7 @@ def menu_main(state):
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
def menu_settings(source):
|
def menu_settings(state):
|
||||||
"""Change advanced ddrescue settings."""
|
"""Change advanced ddrescue settings."""
|
||||||
title = '{GREEN}ddrescue TUI: Expert Settings{CLEAR}\n\n'.format(**COLORS)
|
title = '{GREEN}ddrescue TUI: Expert Settings{CLEAR}\n\n'.format(**COLORS)
|
||||||
title += '{YELLOW}These settings can cause {CLEAR}'.format(**COLORS)
|
title += '{YELLOW}These settings can cause {CLEAR}'.format(**COLORS)
|
||||||
|
|
@ -761,7 +761,7 @@ def menu_settings(source):
|
||||||
|
|
||||||
# Build menu
|
# Build menu
|
||||||
settings = []
|
settings = []
|
||||||
for k, v in sorted(source['Settings'].items()):
|
for k, v in sorted(state.settings.items()):
|
||||||
if not v.get('Hidden', False):
|
if not v.get('Hidden', False):
|
||||||
settings.append({'Base Name': k.replace('=', ''), 'Flag': k})
|
settings.append({'Base Name': k.replace('=', ''), 'Flag': k})
|
||||||
actions = [{'Name': 'Main Menu', 'Letter': 'M'}]
|
actions = [{'Name': 'Main Menu', 'Letter': 'M'}]
|
||||||
|
|
@ -771,9 +771,9 @@ def menu_settings(source):
|
||||||
for s in settings:
|
for s in settings:
|
||||||
s['Name'] = '{}{}{}'.format(
|
s['Name'] = '{}{}{}'.format(
|
||||||
s['Base Name'],
|
s['Base Name'],
|
||||||
' = ' if 'Value' in source['Settings'][s['Flag']] else '',
|
' = ' if 'Value' in state.settings[s['Flag']] else '',
|
||||||
source['Settings'][s['Flag']].get('Value', ''))
|
state.settings[s['Flag']].get('Value', ''))
|
||||||
if not source['Settings'][s['Flag']]['Enabled']:
|
if not state.settings[s['Flag']]['Enabled']:
|
||||||
s['Name'] = '{YELLOW}{name} (Disabled){CLEAR}'.format(
|
s['Name'] = '{YELLOW}{name} (Disabled){CLEAR}'.format(
|
||||||
name=s['Name'],
|
name=s['Name'],
|
||||||
**COLORS)
|
**COLORS)
|
||||||
|
|
@ -784,27 +784,27 @@ def menu_settings(source):
|
||||||
if selection.isnumeric():
|
if selection.isnumeric():
|
||||||
index = int(selection) - 1
|
index = int(selection) - 1
|
||||||
flag = settings[index]['Flag']
|
flag = settings[index]['Flag']
|
||||||
enabled = source['Settings'][flag]['Enabled']
|
enabled = state.settings[flag]['Enabled']
|
||||||
if 'Value' in source['Settings'][flag]:
|
if 'Value' in state.settings[flag]:
|
||||||
answer = choice(
|
answer = choice(
|
||||||
choices=['T', 'C'],
|
choices=['T', 'C'],
|
||||||
prompt='Toggle or change value for "{}"'.format(flag))
|
prompt='Toggle or change value for "{}"'.format(flag))
|
||||||
if answer == 'T':
|
if answer == 'T':
|
||||||
# Toggle
|
# Toggle
|
||||||
source['Settings'][flag]['Enabled'] = not enabled
|
state.settings[flag]['Enabled'] = not enabled
|
||||||
else:
|
else:
|
||||||
# Update value
|
# Update value
|
||||||
source['Settings'][flag]['Value'] = get_simple_string(
|
state.settings[flag]['Value'] = get_simple_string(
|
||||||
prompt='Enter new value')
|
prompt='Enter new value')
|
||||||
else:
|
else:
|
||||||
source['Settings'][flag]['Enabled'] = not enabled
|
state.settings[flag]['Enabled'] = not enabled
|
||||||
elif selection == 'M':
|
elif selection == 'M':
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
def read_map_file(map_path):
|
def read_map_file(map_path):
|
||||||
"""Read map file with ddrescuelog and return data as dict."""
|
"""Read map file with ddrescuelog and return data as dict."""
|
||||||
map_data = {}
|
map_data = {'full recovery': False}
|
||||||
try:
|
try:
|
||||||
result = run_program(['ddrescuelog', '-t', map_path])
|
result = run_program(['ddrescuelog', '-t', map_path])
|
||||||
except CalledProcessError:
|
except CalledProcessError:
|
||||||
|
|
@ -864,21 +864,28 @@ def run_ddrescue(state):
|
||||||
if bp.pass_done[state.current_pass]:
|
if bp.pass_done[state.current_pass]:
|
||||||
# Skip to next block-pair
|
# Skip to next block-pair
|
||||||
continue
|
continue
|
||||||
bp.status[state.current_pass] = 'Working'
|
|
||||||
update_progress(state)
|
update_progress(state)
|
||||||
|
|
||||||
# Set ddrescue cmd
|
# Set ddrescue cmd
|
||||||
cmd = [
|
cmd = ['ddrescue', bp.source_path, bp.dest_path, bp.map_path]
|
||||||
'ddrescue', *settings,
|
for k, v in state.settings.items():
|
||||||
bp.source_path, bp.dest_path, bp.map_path]
|
if not v['Enabled']:
|
||||||
|
continue
|
||||||
|
if 'Value' in v:
|
||||||
|
cmd.append('{}{}{}'.format(
|
||||||
|
k,
|
||||||
|
'' if k[-1:] == '=' else ' ',
|
||||||
|
v['Value']))
|
||||||
|
else:
|
||||||
|
cmd.append(k)
|
||||||
if state.mode == 'clone':
|
if state.mode == 'clone':
|
||||||
cmd.append('--force')
|
cmd.append('--force')
|
||||||
if current_pass == 0:
|
if state.current_pass == 0:
|
||||||
cmd.extend(['--no-trim', '--no-scrape'])
|
cmd.extend(['--no-trim', '--no-scrape'])
|
||||||
elif current_pass == 1:
|
elif state.current_pass == 1:
|
||||||
# Allow trimming
|
# Allow trimming
|
||||||
cmd.append('--no-scrape')
|
cmd.append('--no-scrape')
|
||||||
elif current_pass == 2:
|
elif state.current_pass == 2:
|
||||||
# Allow trimming and scraping
|
# Allow trimming and scraping
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue