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 psutil
|
||||||
import pytz
|
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
|
from wk.hw import obj as hw_obj
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -281,12 +281,14 @@ class BlockPair():
|
||||||
|
|
||||||
|
|
||||||
class State():
|
class State():
|
||||||
|
# pylint: disable=too-many-instance-attributes,too-many-public-methods
|
||||||
"""Object for tracking hardware diagnostic data."""
|
"""Object for tracking hardware diagnostic data."""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.block_pairs = []
|
self.block_pairs = []
|
||||||
self.destination = None
|
self.destination = None
|
||||||
self.log_dir = None
|
self.log_dir = None
|
||||||
self.mode = None
|
self.mode = None
|
||||||
|
self.ost = osticket.osTicket()
|
||||||
self.panes = {}
|
self.panes = {}
|
||||||
self.source = None
|
self.source = None
|
||||||
self.working_dir = None
|
self.working_dir = None
|
||||||
|
|
@ -759,6 +761,33 @@ class State():
|
||||||
"""Check if all block_pairs completed pass_name, returns bool."""
|
"""Check if all block_pairs completed pass_name, returns bool."""
|
||||||
return all([p.pass_complete(pass_name) for p in self.block_pairs])
|
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):
|
def prep_destination(self, source_parts, dry_run=True):
|
||||||
"""Prep destination as necessary."""
|
"""Prep destination as necessary."""
|
||||||
# TODO: Split into Linux and macOS
|
# TODO: Split into Linux and macOS
|
||||||
|
|
@ -1693,6 +1722,9 @@ def main():
|
||||||
if std.ask('Are you sure you want to quit?'):
|
if std.ask('Are you sure you want to quit?'):
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# osTicket
|
||||||
|
state.post_to_osticket()
|
||||||
|
|
||||||
# Save results to log
|
# Save results to log
|
||||||
std.print_standard(' ')
|
std.print_standard(' ')
|
||||||
std.print_report(state.generate_report())
|
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(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 = response.replace("`", "'").replace("'", "\\'")
|
response = response.replace("`", "'").replace("'", "\\'")
|
||||||
|
|
||||||
# Build SQL cmd
|
# Build SQL cmd
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue