Started integrating osTicket functions in ddrescue
This commit is contained in:
parent
ceee0495eb
commit
2f2bfacbb7
2 changed files with 34 additions and 1 deletions
|
|
@ -21,7 +21,7 @@ from docopt import docopt
|
|||
import psutil
|
||||
import pytz
|
||||
|
||||
from wk import cfg, debug, exe, io, log, net, std, tmux
|
||||
from wk import cfg, debug, exe, io, log, net, osticket, std, tmux
|
||||
from wk.hw import obj as hw_obj
|
||||
|
||||
|
||||
|
|
@ -281,12 +281,14 @@ class BlockPair():
|
|||
|
||||
|
||||
class State():
|
||||
# pylint: disable=too-many-instance-attributes,too-many-public-methods
|
||||
"""Object for tracking hardware diagnostic data."""
|
||||
def __init__(self):
|
||||
self.block_pairs = []
|
||||
self.destination = None
|
||||
self.log_dir = None
|
||||
self.mode = None
|
||||
self.ost = osticket.osTicket()
|
||||
self.panes = {}
|
||||
self.source = None
|
||||
self.working_dir = None
|
||||
|
|
@ -759,6 +761,33 @@ class State():
|
|||
"""Check if all block_pairs completed pass_name, returns bool."""
|
||||
return all([p.pass_complete(pass_name) for p in self.block_pairs])
|
||||
|
||||
def post_to_osticket(self):
|
||||
"""Post results to osTicket."""
|
||||
color = 'Diags'
|
||||
percent = self.get_percent_recovered()
|
||||
report = self.generate_report()
|
||||
report[0] = f'ddrescue-tui {report[0]}'
|
||||
if percent < 90:
|
||||
color = 'Diags FAIL'
|
||||
elif percent < 95:
|
||||
color = 'Normal'
|
||||
|
||||
# Ask user
|
||||
if not std.ask('Post results to osTicket?'):
|
||||
return
|
||||
|
||||
# Init osTicket if necessary
|
||||
if not self.ost.ticket_id:
|
||||
self.ost.init()
|
||||
self.ost.select_ticket()
|
||||
|
||||
# Bail if user changed their mind
|
||||
if not self.ost.ticket_id:
|
||||
return
|
||||
|
||||
# Post report
|
||||
self.ost.post_response('\n'.join(report), color=color)
|
||||
|
||||
def prep_destination(self, source_parts, dry_run=True):
|
||||
"""Prep destination as necessary."""
|
||||
# TODO: Split into Linux and macOS
|
||||
|
|
@ -1693,6 +1722,9 @@ def main():
|
|||
if std.ask('Are you sure you want to quit?'):
|
||||
break
|
||||
|
||||
# osTicket
|
||||
state.post_to_osticket()
|
||||
|
||||
# Save results to log
|
||||
std.print_standard(' ')
|
||||
std.print_report(state.generate_report())
|
||||
|
|
|
|||
|
|
@ -212,6 +212,7 @@ class osTicket(): # pylint: disable=invalid-name
|
|||
lines.append(f'[Note] {self.note}\n')
|
||||
lines.append(str(response))
|
||||
response = '\n'.join(lines)
|
||||
response = std.strip_colors(response)
|
||||
response = response.replace("`", "'").replace("'", "\\'")
|
||||
|
||||
# Build SQL cmd
|
||||
|
|
|
|||
Loading…
Reference in a new issue