From 146244d3fd5132293119506ae743a06b644b6890 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 20 Sep 2018 12:02:08 -0600 Subject: [PATCH] Adjusted osTicket post formatting --- .bin/Scripts/functions/hw_diags.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/.bin/Scripts/functions/hw_diags.py b/.bin/Scripts/functions/hw_diags.py index 0653203b..d56ab469 100644 --- a/.bin/Scripts/functions/hw_diags.py +++ b/.bin/Scripts/functions/hw_diags.py @@ -373,6 +373,16 @@ def osticket_set_drive_result(ticket_id, passed): except: ost_db['Errors'] = True +def pad_with_dots(s, left_pad=True): + """Replace ' ' padding with '..' for osTicket posts.""" + s = str(s).replace(' ', '..') + if '.' in s: + if left_pad: + s = '.' + s + else: + s = s + '.' + return s + def post_drive_results(ticket_number): """Post drive test results to osTicket.""" tested = False @@ -454,22 +464,17 @@ def post_drive_results(ticket_number): for attrib in sorted(ATTRIBUTES['SMART'].keys()): if attrib in s_table: # Pad attributewith dots for osTicket - hex_str = '{:>2}'.format(str(hex(int(attrib))).upper()[2:]) - hex_str = hex_str.replace(' ', '..') - if '.' in hex_str: - hex_str = '.' + hex_str - dec_str = '{:>3}'.format(attrib) - dec_str = dec_str.replace(' ', '..') - if '.' in dec_str: - dec_str = '.' + dec_str - report.append('{:>2}/{:>3}: {} {} ({})'.format( + hex_str = str(hex(int(attrib))).upper()[2:] + hex_str = pad_with_dots('{:>2}'.format(hex_str)) + dec_str = pad_with_dots('{:>3}'.format(attrib)) + val_str = '{:<20}'.format(s_table[attrib]['raw']['string']) + val_str = pad_with_dots(val_str, left_pad=False) + report.append('{:>2}/{:>3}: {} ({})'.format( hex_str, dec_str, - s_table[attrib]['raw']['string'], - '..'*24+'.', + val_str, s_table[attrib]['name'], )) - report[-1] = report[-1].strip().replace(' ', '.') report[-1] = report[-1].replace('_', ' ') report.append('')