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__) LOG = logging.getLogger(__name__)
MENU_ACTIONS = ( MENU_ACTIONS = (
'Start', 'Start',
'Add Tech Note',
f'Change settings {std.color_string("(experts only)", "YELLOW")}', f'Change settings {std.color_string("(experts only)", "YELLOW")}',
f'Detect drives {std.color_string("(experts only)", "YELLOW")}', f'Detect drives {std.color_string("(experts only)", "YELLOW")}',
'Quit') 'Quit')
@ -615,12 +616,11 @@ class State():
# Header # Header
report.append(f'{self.mode.title()} Results:') 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': if self.mode == 'Clone':
report.append(f'Destination: {self.destination.description}') report.append(f'... Destination: {self.destination.description}')
else: else:
report.append(f'Destination: {self.destination}/') report.append(f'... Destination: {self.destination}/')
# Overall # Overall
report.append(' ') report.append(' ')
@ -1174,17 +1174,26 @@ class State():
) )
# Ticket Details # Ticket Details
if self.ost and self.ost.ticket_id and not self.panes.get('Ticket', None): if self.ost and self.ost.ticket_id:
self.panes['Ticket'] = tmux.split_window( text = std.color_string(
behind=True, [
lines=2, self.ost.ticket_name,
text=std.color_string( ' ' if self.ost.note else '\n',
[self.ost.ticket_name, '\n', f'Ticket #{self.ost.ticket_id}'], f'Ticket #{self.ost.ticket_id}',
['CYAN', None, None], f'\n{self.ost.note.splitlines()[0]}' if self.ost.note else '',
],
['CYAN', None, None, 'YELLOW'],
sep='', 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 # Functions
@ -1885,6 +1894,9 @@ def main():
state = State() state = State()
if not args['--force-local-map']: if not args['--force-local-map']:
state.ost.select_ticket() 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: try:
state.init_recovery(args) state.init_recovery(args)
except (FileNotFoundError, std.GenericAbort): except (FileNotFoundError, std.GenericAbort):
@ -1909,6 +1921,13 @@ def main():
if 'Detect drives' in selection[0]: if 'Detect drives' in selection[0]:
detect_drives(state) 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 # Start recovery
if 'Start' in selection: if 'Start' in selection:
std.clear_screen() std.clear_screen()

View file

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