Add settings menu
This commit is contained in:
parent
310a2eb63a
commit
7d851d2222
1 changed files with 70 additions and 25 deletions
|
|
@ -10,18 +10,18 @@ from functions.data import *
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
|
||||||
# STATIC VARIABLES
|
# STATIC VARIABLES
|
||||||
DDRESCUE_SETTINGS = [
|
DDRESCUE_SETTINGS = {
|
||||||
{'Flag': '--binary-prefixes', 'Enabled': True, 'Hidden': True},
|
'--binary-prefixes': {'Enabled': True, 'Hidden': True},
|
||||||
{'Flag': '--data-preview', 'Enabled': True, 'Hidden': True},
|
'--data-preview': {'Enabled': True, 'Hidden': True},
|
||||||
{'Flag': '--idirect', 'Enabled': True},
|
'--idirect': {'Enabled': True},
|
||||||
{'Flag': '--max-read-rate', 'Enabled': False, 'Value': '128MiB'},
|
'--odirect': {'Enabled': True},
|
||||||
{'Flag': '--min-read-rate', 'Enabled': True, 'Value': '64KiB'},
|
'--max-read-rate': {'Enabled': False, 'Value': '128MiB'},
|
||||||
{'Flag': '--odirect', 'Enabled': True},
|
'--min-read-rate': {'Enabled': True, 'Value': '64KiB'},
|
||||||
{'Flag': '--reopen-on-error', 'Enabled': True},
|
'--reopen-on-error': {'Enabled': True},
|
||||||
{'Flag': '--retry-passes=', 'Enabled': True, 'Value': '0'},
|
'--retry-passes=': {'Enabled': True, 'Value': '0'},
|
||||||
{'Flag': '--timeout=', 'Enabled': True, 'Value': '5m'},
|
'--timeout=': {'Enabled': True, 'Value': '5m'},
|
||||||
{'Flag': '-vvvv', 'Enabled': True, 'Hidden': True},
|
'-vvvv': {'Enabled': True, 'Hidden': True},
|
||||||
]
|
}
|
||||||
USAGE = """ {script_name} clone [source [destination]]
|
USAGE = """ {script_name} clone [source [destination]]
|
||||||
{script_name} image [source [destination]]
|
{script_name} image [source [destination]]
|
||||||
(e.g. {script_name} clone /dev/sda /dev/sdb)
|
(e.g. {script_name} clone /dev/sda /dev/sdb)
|
||||||
|
|
@ -229,15 +229,15 @@ def menu_main(source):
|
||||||
# Set settings for pass
|
# Set settings for pass
|
||||||
settings = []
|
settings = []
|
||||||
# TODO move to new function and replace with real code
|
# TODO move to new function and replace with real code
|
||||||
for s in source['Settings']:
|
for k, v in source['Settings'].items():
|
||||||
if not s['Enabled']:
|
if not v['Enabled']:
|
||||||
continue
|
continue
|
||||||
if s['Flag'][-1:] == '=':
|
if k[-1:] == '=':
|
||||||
settings.append('{Flag}{Value}'.format(**s))
|
settings.append('{}{}'.format(k, v['Value']))
|
||||||
else:
|
else:
|
||||||
settings.append(s['Flag'])
|
settings.append(k)
|
||||||
if 'Value' in s:
|
if 'Value' in v:
|
||||||
settings.append(s['Value'])
|
settings.append(v['Value'])
|
||||||
for opt in main_options:
|
for opt in main_options:
|
||||||
if 'Retry' in opt['Base Name'] and opt['Enabled']:
|
if 'Retry' in opt['Base Name'] and opt['Enabled']:
|
||||||
settings.extend(['--retrim', '--try-again'])
|
settings.extend(['--retrim', '--try-again'])
|
||||||
|
|
@ -278,12 +278,7 @@ def menu_main(source):
|
||||||
update_progress(source)
|
update_progress(source)
|
||||||
pause()
|
pause()
|
||||||
elif selection == 'C':
|
elif selection == 'C':
|
||||||
# TODO Move to new function and replace with real code
|
menu_settings(source)
|
||||||
print_warning(
|
|
||||||
'These settings can cause {RED}SERIOUS damage{YELLOW} to drives'.format(
|
|
||||||
**COLORS))
|
|
||||||
print_standard('Please read the manual before making any changes')
|
|
||||||
pause()
|
|
||||||
elif selection == 'Q':
|
elif selection == 'Q':
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
@ -471,6 +466,56 @@ def menu_select_path(skip_device={}):
|
||||||
print_error('Invalid path "{}"'.format(m_path))
|
print_error('Invalid path "{}"'.format(m_path))
|
||||||
return s_path
|
return s_path
|
||||||
|
|
||||||
|
def menu_settings(source):
|
||||||
|
"""Change advanced ddrescue settings."""
|
||||||
|
title = '{GREEN}ddrescue TUI: Expert Settings{CLEAR}\n\n'.format(**COLORS)
|
||||||
|
title += '{YELLOW}These settings can cause {CLEAR}'.format(**COLORS)
|
||||||
|
title += '{RED}MAJOR DAMAGE{CLEAR}{YELLOW} to drives{CLEAR}\n'.format(
|
||||||
|
**COLORS)
|
||||||
|
title += 'Please read the manual before making any changes'
|
||||||
|
|
||||||
|
# Build menu
|
||||||
|
settings = []
|
||||||
|
for k, v in sorted(source['Settings'].items()):
|
||||||
|
if not v.get('Hidden', False):
|
||||||
|
settings.append({'Base Name': k.replace('=', ''), 'Flag': k})
|
||||||
|
actions = [{'Name': 'Main Menu', 'Letter': 'M'}]
|
||||||
|
|
||||||
|
# Show menu
|
||||||
|
while True:
|
||||||
|
for s in settings:
|
||||||
|
s['Name'] = '{}{}{}'.format(
|
||||||
|
s['Base Name'],
|
||||||
|
' = ' if 'Value' in source['Settings'][s['Flag']] else '',
|
||||||
|
source['Settings'][s['Flag']].get('Value', ''))
|
||||||
|
if not source['Settings'][s['Flag']]['Enabled']:
|
||||||
|
s['Name'] = '{YELLOW}{name} (Disabled){CLEAR}'.format(
|
||||||
|
name = s['Name'],
|
||||||
|
**COLORS)
|
||||||
|
selection = menu_select(
|
||||||
|
title = title,
|
||||||
|
main_entries = settings,
|
||||||
|
action_entries = actions)
|
||||||
|
if selection.isnumeric():
|
||||||
|
index = int(selection) - 1
|
||||||
|
flag = settings[index]['Flag']
|
||||||
|
enabled = source['Settings'][flag]['Enabled']
|
||||||
|
if 'Value' in source['Settings'][flag]:
|
||||||
|
answer = choice(
|
||||||
|
choices = ['Toggle flag', 'Change value'],
|
||||||
|
prompt = 'Please make a selection for "{}"'.format(flag))
|
||||||
|
if answer == 'Toggle flag':
|
||||||
|
# Toggle
|
||||||
|
source['Settings'][flag]['Enabled'] = not enabled
|
||||||
|
else:
|
||||||
|
# Update value
|
||||||
|
source['Settings'][flag]['Value'] = get_simple_string(
|
||||||
|
prompt = 'Enter new value')
|
||||||
|
else:
|
||||||
|
source['Settings'][flag]['Enabled'] = not enabled
|
||||||
|
elif selection == 'M':
|
||||||
|
break
|
||||||
|
|
||||||
def select_dest_path(provided_path=None, skip_device={}):
|
def select_dest_path(provided_path=None, skip_device={}):
|
||||||
dest = {}
|
dest = {}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue