Fix bugs related to new UI design

This commit is contained in:
2Shirt 2023-06-11 19:57:34 -07:00
parent d545152d67
commit 375fc3fcd0
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
5 changed files with 37 additions and 40 deletions

View file

@ -662,12 +662,6 @@ class State():
# Set mode # Set mode
self.mode = set_mode(docopt_args) self.mode = set_mode(docopt_args)
# Progress pane
self.panes['Progress'] = tmux.split_window(
lines=cfg.ddrescue.TMUX_SIDE_WIDTH,
watch_file=f'{self.log_dir}/progress.out',
)
# Select source # Select source
self.source = select_disk_obj('source', disk_menu, docopt_args['<source>']) self.source = select_disk_obj('source', disk_menu, docopt_args['<source>'])
self.ui.set_title('Source', self.source.name) self.ui.set_title('Source', self.source.name)
@ -814,7 +808,7 @@ class State():
color = 'Normal' color = 'Normal'
# Ask user # Ask user
if not std.ask('Post results to osTicket?'): if not cli.ask('Post results to osTicket?'):
return return
# Init osTicket if necessary # Init osTicket if necessary
@ -1180,8 +1174,9 @@ class State():
) )
# Ticket Details # Ticket Details
# TODO: Fixme
if self.ost and self.ost.ticket_id: if self.ost and self.ost.ticket_id:
text = std.color_string( text = ansi.color_string(
[ [
self.ost.ticket_name, self.ost.ticket_name,
' ' if self.ost.note else '\n', ' ' if self.ost.note else '\n',

View file

@ -479,7 +479,7 @@ def cpu_stress_tests(state, test_objects, test_mode=False) -> None:
# Post results to osTicket # Post results to osTicket
if not state.ost.disabled: if not state.ost.disabled:
_failed = test_cooling_obj.failed or test_mprime_obj.failed _failed = test_cooling_obj.failed or test_mprime_obj.failed
std.print_info('Posting results to osTicket...') cli.print_info('Posting results to osTicket...')
state.cpu_max_temp = sensors.cpu_max_temp() state.cpu_max_temp = sensors.cpu_max_temp()
state.ost.post_response( state.ost.post_response(
hw_osticket.build_report(state.system, 'CPU'), hw_osticket.build_report(state.system, 'CPU'),
@ -873,7 +873,7 @@ def run_diags(state, menu, quick_mode=False, test_mode=False) -> None:
# Update top_text # Update top_text
if state.ost.ticket_id: if state.ost.ticket_id:
state.top_text += std.color_string( state.top_text += cli.color_string(
[f' #{state.ost.ticket_id}', state.ost.ticket_name], [f' #{state.ost.ticket_id}', state.ost.ticket_name],
[None, 'CYAN'], [None, 'CYAN'],
) )

View file

@ -4,12 +4,13 @@
import logging import logging
import re import re
from wk import std, osticket from wk import osticket
from wk.cfg.hw import ( from wk.cfg.hw import (
REGEX_BLOCK_GRAPH, REGEX_BLOCK_GRAPH,
REGEX_SMART_ATTRIBUTES, REGEX_SMART_ATTRIBUTES,
) )
from wk.hw import smart as hw_smart from wk.hw import smart as hw_smart
from wk.ui import cli
# STATIC VARIABLES # STATIC VARIABLES
@ -91,7 +92,7 @@ def build_report(dev, dev_type, num_disk_tests=None):
report.pop(-1) report.pop(-1)
# Done # Done
return std.strip_colors('\n'.join(report)) return cli.strip_colors('\n'.join(report))
def convert_report(original_report, start_index): def convert_report(original_report, start_index):
@ -101,7 +102,7 @@ def convert_report(original_report, start_index):
# Convert report # Convert report
for line in original_report[start_index:]: for line in original_report[start_index:]:
# Remove colors and leading spaces # Remove colors and leading spaces
line = std.strip_colors(line) line = cli.strip_colors(line)
line = re.sub(r'^\s+', '', line) line = re.sub(r'^\s+', '', line)
# Disk I/O Benchmark # Disk I/O Benchmark
@ -152,7 +153,7 @@ def post_disk_results(state, num_disk_tests):
return return
# Post disk results # Post disk results
std.print_info('Posting results to osTicket...') cli.print_info('Posting results to osTicket...')
for disk in state.disks: for disk in state.disks:
state.ost.post_response( state.ost.post_response(
build_report(disk, 'Disk', num_disk_tests), build_report(disk, 'Disk', num_disk_tests),
@ -181,7 +182,7 @@ def update_checkboxes(state, num_disk_tests):
return return
# Bail if values not confirmed # Bail if values not confirmed
if not std.ask('Update osTicket checkboxes using the data above?'): if not cli.ask('Update osTicket checkboxes using the data above?'):
return return
# CPU max temp and pass/fail # CPU max temp and pass/fail

View file

@ -8,6 +8,7 @@ import re
from wk import std from wk import std
from wk.exe import run_program from wk.exe import run_program
from wk.hw.disk import Disk from wk.hw.disk import Disk
from wk.ui import cli
# STATIC VARIABLES # STATIC VARIABLES
@ -193,13 +194,13 @@ def mount_disk(device_path=None):
# Containers # Containers
if vol.details['Content'] in ('Apple_APFS', 'Apple_CoreStorage'): if vol.details['Content'] in ('Apple_APFS', 'Apple_CoreStorage'):
result += f'{vol.details["Content"].replace("Apple_", "")} container' result += f'{vol.details["Content"].replace("Apple_", "")} container'
report.append(std.color_string(result, 'BLUE')) report.append(cli.color_string(result, 'BLUE'))
continue continue
# Unknown partitions # Unknown partitions
if not vol.details['mountpoint']: if not vol.details['mountpoint']:
result += 'Failed to mount' result += 'Failed to mount'
report.append(std.color_string(result, 'RED')) report.append(cli.color_string(result, 'RED'))
continue continue
# Volumes # Volumes

View file

@ -8,9 +8,9 @@ import time
import mariadb import mariadb
from wk import std
from wk.cfg.hw import TESTSTATION_FILE from wk.cfg.hw import TESTSTATION_FILE
from wk.cfg.osticket import SQL, STAFF from wk.cfg.osticket import SQL, STAFF
from wk.ui import ansi, cli
# STATIC_VARIABLES # STATIC_VARIABLES
@ -108,7 +108,7 @@ class osTicket():
for s in self.db_cursor: for s in self.db_cursor:
flag_value = s[0] flag_value = s[0]
except mariadb.Error as err_msg: except mariadb.Error as err_msg:
std.print_error(err_msg) cli.print_error(err_msg)
self.errors = True self.errors = True
# Done # Done
@ -132,7 +132,7 @@ class osTicket():
field_data = result[0] field_data = result[0]
except mariadb.Error as err_msg: except mariadb.Error as err_msg:
# Show error and return None # Show error and return None
std.print_error(err_msg) cli.print_error(err_msg)
# Done # Done
return field_data return field_data
@ -153,7 +153,7 @@ class osTicket():
try: try:
self.db_cursor.execute(sql_cmd) self.db_cursor.execute(sql_cmd)
except mariadb.Error as err_msg: except mariadb.Error as err_msg:
std.print_error(err_msg) cli.print_error(err_msg)
self.errors = True self.errors = True
def _verify_ticket_id(self): def _verify_ticket_id(self):
@ -169,13 +169,13 @@ class osTicket():
prompt = 'Please enter any additional information for this ticket' prompt = 'Please enter any additional information for this ticket'
# Instructions # Instructions
std.print_standard(prompt) cli.print_standard(prompt)
std.print_info(' (End note with an empty line)') cli.print_info(' (End note with an empty line)')
std.print_standard(' ') cli.print_standard(' ')
# Get note # Get note
while True: while True:
text = std.input_text('> ') text = cli.input_text('> ')
if not text: if not text:
break break
lines.append(text.strip()) lines.append(text.strip())
@ -217,7 +217,7 @@ class osTicket():
lines.append(f'[Note] {self.note}\n') lines.append(f'[Note] {self.note}\n')
lines.append(str(response)) lines.append(str(response))
response = '\n'.join(lines) response = '\n'.join(lines)
response = std.strip_colors(response) response = ansi.strip_colors(response)
response = response.replace("`", "'").replace("'", "\\'") response = response.replace("`", "'").replace("'", "\\'")
# Build SQL cmd # Build SQL cmd
@ -256,7 +256,7 @@ class osTicket():
def select_ticket(self): def select_ticket(self):
"""Set ticket number and name from osTicket DB.""" """Set ticket number and name from osTicket DB."""
std.print_standard('Connecting to osTicket...') cli.print_standard('Connecting to osTicket...')
# Bail if disabled # Bail if disabled
if self.disabled: if self.disabled:
@ -267,9 +267,9 @@ class osTicket():
try: try:
self._connect(silent=False) self._connect(silent=False)
except (mariadb.Error, RuntimeError): except (mariadb.Error, RuntimeError):
std.print_warning('Failed to connect to osTicket') cli.print_warning('Failed to connect to osTicket')
if not std.ask('Try again?'): if not cli.ask('Try again?'):
std.print_standard('Integration disabled for this session') cli.print_standard('Integration disabled for this session')
self.disabled = True self.disabled = True
return return
else: else:
@ -278,14 +278,14 @@ class osTicket():
# Main loop # Main loop
while self.ticket_id is None: while self.ticket_id is None:
std.print_standard(' ') cli.print_standard(' ')
_id = std.input_text('Enter ticket number (or leave blank to disable): ') _id = cli.input_text('Enter ticket number (or leave blank to disable): ')
_id = _id.strip() _id = _id.strip()
# Nothing entered # Nothing entered
if not _id: if not _id:
print(' ') print(' ')
if std.ask('Disable osTicket integration for this session?'): if cli.ask('Disable osTicket integration for this session?'):
self.disabled = True self.disabled = True
break break
@ -298,20 +298,20 @@ class osTicket():
# Invalid ticket selected # Invalid ticket selected
if _name is None: if _name is None:
std.print_error(f'Ticket #{_id} not found') cli.print_error(f'Ticket #{_id} not found')
continue continue
# Valid ticket selected, lookup subject # Valid ticket selected, lookup subject
_subject = self._get_ticket_field(_id, 'subject') _subject = self._get_ticket_field(_id, 'subject')
# Verify selection # Verify selection
std.print_colored( cli.print_colored(
['You have selected ticket', f'#{_id}', _name], ['You have selected ticket', f'#{_id}', _name],
[None, 'BLUE', None], [None, 'BLUE', None],
) )
std.print_colored(f' {_subject}', 'CYAN') cli.print_colored(f' {_subject}', 'CYAN')
std.print_standard(' ') cli.print_standard(' ')
if std.ask('Is this correct?'): if cli.ask('Is this correct?'):
self.ticket_id = _id self.ticket_id = _id
self.ticket_name = _name self.ticket_name = _name
@ -333,7 +333,7 @@ class osTicket():
# Compare to current temp # Compare to current temp
current_temp = self._get_flag(FLAG_MAX_TEMP) current_temp = self._get_flag(FLAG_MAX_TEMP)
if str(current_temp).isnumeric() and int(current_temp) > temp: if str(current_temp).isnumeric() and int(current_temp) > temp:
std.print_warning('Not replacing higher temp in osTicket') cli.print_warning('Not replacing higher temp in osTicket')
self._disconnect() self._disconnect()
return return
@ -373,7 +373,7 @@ class osTicket():
# Bail if flag checkbox set as FAILED # Bail if flag checkbox set as FAILED
if self._get_flag(real_flag_name) == str(FLAG_CODES['Fail']): if self._get_flag(real_flag_name) == str(FLAG_CODES['Fail']):
std.print_warning( cli.print_warning(
f'Not replacing osTicket {flag_name} checkbox FAILED value', f'Not replacing osTicket {flag_name} checkbox FAILED value',
) )
self._disconnect() self._disconnect()