Add support for tech notes in ddrescue-tui

Addresses issue #11
This commit is contained in:
2Shirt 2022-02-19 18:42:59 -07:00
parent b3f4a31ed2
commit 147c35f0c6
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
2 changed files with 43 additions and 19 deletions

View file

@ -79,6 +79,7 @@ REGEX_REMAINING_TIME = re.compile(
LOG = logging.getLogger(__name__)
MENU_ACTIONS = (
'Start',
'Add Tech Note',
f'Change settings {std.color_string("(experts only)", "YELLOW")}',
f'Detect drives {std.color_string("(experts only)", "YELLOW")}',
'Quit')
@ -615,12 +616,11 @@ class State():
# Header
report.append(f'{self.mode.title()} Results:')
report.append(' ')
report.append(f'Source: {self.source.description}')
report.append(f'... Source: {self.source.description}')
if self.mode == 'Clone':
report.append(f'Destination: {self.destination.description}')
report.append(f'... Destination: {self.destination.description}')
else:
report.append(f'Destination: {self.destination}/')
report.append(f'... Destination: {self.destination}/')
# Overall
report.append(' ')
@ -1174,17 +1174,26 @@ class State():
)
# Ticket Details
if self.ost and self.ost.ticket_id and not self.panes.get('Ticket', None):
self.panes['Ticket'] = tmux.split_window(
behind=True,
lines=2,
text=std.color_string(
[self.ost.ticket_name, '\n', f'Ticket #{self.ost.ticket_id}'],
['CYAN', None, None],
if self.ost and self.ost.ticket_id:
text = std.color_string(
[
self.ost.ticket_name,
' ' if self.ost.note else '\n',
f'Ticket #{self.ost.ticket_id}',
f'\n{self.ost.note.splitlines()[0]}' if self.ost.note else '',
],
['CYAN', None, None, 'YELLOW'],
sep='',
),
vertical=True,
)
)
if self.panes.get('Ticket', None):
tmux.respawn_pane(self.panes['Ticket'], text=text)
else:
self.panes['Ticket'] = tmux.split_window(
behind=True,
lines=2,
text=text,
vertical=True,
)
# Functions
@ -1885,6 +1894,9 @@ def main():
state = State()
if not args['--force-local-map']:
state.ost.select_ticket()
if state.ost.disabled:
main_menu.actions['Add Tech Note']['Disabled'] = True
main_menu.actions['Add Tech Note']['Hidden'] = True
try:
state.init_recovery(args)
except (FileNotFoundError, std.GenericAbort):
@ -1909,6 +1921,13 @@ def main():
if 'Detect drives' in selection[0]:
detect_drives(state)
# Tech Note
if 'Tech Note' in selection[0]:
state.ost.add_note(
'Please enter any additional information about this recovery',
)
state.update_top_panes()
# Start recovery
if 'Start' in selection:
std.clear_screen()

View file

@ -161,12 +161,14 @@ class osTicket(): # pylint: disable=invalid-name
LOG.error('Ticket ID not set')
raise RuntimeError('Ticket ID not set')
def add_note(self):
def add_note(self, prompt=None):
"""Add note to be included in osTicket replies."""
lines = []
if not prompt:
prompt = 'Please enter any additional information for this ticket'
# Instructions
std.print_standard('Please enter the additional information for this ticket')
std.print_standard(prompt)
std.print_info(' (End note with an empty line)')
std.print_standard(' ')
@ -178,9 +180,12 @@ class osTicket(): # pylint: disable=invalid-name
lines.append(text.strip())
# Save note
self.note = lines.pop(0)
for line in lines:
self.note += f'\n...{line}'
if lines:
self.note = lines.pop(0)
for line in lines:
self.note += f'\n...{line}'
else:
self.note = None
def init(self):
"""Revert to defaults."""