Added EToC line to ddrescue-tui side-pane
* Is not shown in main menu
This commit is contained in:
parent
c96ffc5f59
commit
fa05c93bf8
3 changed files with 87 additions and 0 deletions
|
|
@ -1,7 +1,9 @@
|
|||
# Wizard Kit: Functions - ddrescue-tui
|
||||
|
||||
import datetime
|
||||
import pathlib
|
||||
import psutil
|
||||
import pytz
|
||||
import re
|
||||
import signal
|
||||
import stat
|
||||
|
|
@ -262,6 +264,7 @@ class RecoveryState():
|
|||
self.resumed = False
|
||||
self.started = False
|
||||
self.status = 'Inactive'
|
||||
self.timezone = pytz.timezone(LINUX_TIME_ZONE)
|
||||
self.total_size = 0
|
||||
if mode not in ('clone', 'image'):
|
||||
raise GenericError('Unsupported mode')
|
||||
|
|
@ -1324,6 +1327,64 @@ def update_sidepane(state):
|
|||
output.extend(bp.status)
|
||||
output.append(' ')
|
||||
|
||||
# EToC
|
||||
etoc = 'Unknown'
|
||||
if re.search(r'(In Progress|NEEDS ATTENTION)', state.status):
|
||||
if not output[-1].strip():
|
||||
# Last line is empty
|
||||
output.pop()
|
||||
output.append('─────────────────────')
|
||||
output.append('{BLUE}Estimated Pass Finish{CLEAR}'.format(**COLORS))
|
||||
if 'In Progress' in state.status:
|
||||
etoc_delta = None
|
||||
text = ''
|
||||
|
||||
# Capture main tmux pane
|
||||
try:
|
||||
text = tmux_capture_pane()
|
||||
except Exception:
|
||||
# Ignore
|
||||
pass
|
||||
|
||||
# Search for EToC delta
|
||||
matches = re.findall(r'remaining time:.*$', text, re.MULTILINE)
|
||||
if matches:
|
||||
r = REGEX_REMAINING_TIME.search(matches[-1])
|
||||
if r.group('na'):
|
||||
etoc = 'N/A'
|
||||
else:
|
||||
etoc = r.string
|
||||
days = r.group('days') if r.group('days') else 0
|
||||
hours = r.group('hours') if r.group('hours') else 0
|
||||
minutes = r.group('minutes') if r.group('minutes') else 0
|
||||
seconds = r.group('seconds') if r.group('seconds') else 0
|
||||
try:
|
||||
etoc_delta = datetime.timedelta(
|
||||
days=int(days),
|
||||
hours=int(hours),
|
||||
minutes=int(minutes),
|
||||
seconds=int(seconds),
|
||||
)
|
||||
except Exception:
|
||||
# Ignore and leave as raw string
|
||||
pass
|
||||
|
||||
# Calc finish time if EToC delta found
|
||||
if etoc_delta:
|
||||
try:
|
||||
now = datetime.datetime.now(tz=state.timezone)
|
||||
etoc = now + etoc_delta
|
||||
etoc = etoc.strftime('%Y-%m-%d %H:%M %Z')
|
||||
except Exception:
|
||||
# Ignore and leave as current string
|
||||
pass
|
||||
|
||||
# Finally add EToC
|
||||
if 'N/A' in etoc.upper():
|
||||
output.append('{YELLOW}N/A{CLEAR}'.format(**COLORS))
|
||||
else:
|
||||
output.append(etoc)
|
||||
|
||||
# Add line-endings
|
||||
output = ['{}\n'.format(line) for line in output]
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,21 @@ def create_file(filepath):
|
|||
f.write('')
|
||||
|
||||
|
||||
def tmux_capture_pane(pane_id=None):
|
||||
"""Capture text from target, or current, pane, returns str."""
|
||||
cmd = ['tmux', 'capture-pane', '-p']
|
||||
if pane_id:
|
||||
cmd.extend(['-t', pane_id])
|
||||
text = ''
|
||||
|
||||
# Capture
|
||||
result = run_program(cmd, check=False, encoding='utf-8', errors='ignore')
|
||||
text = result.stdout
|
||||
|
||||
# Done
|
||||
return str(text)
|
||||
|
||||
|
||||
def tmux_get_pane_size(pane_id=None):
|
||||
"""Get target, or current, pane size, returns tuple."""
|
||||
x = -1
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
# Wizard Kit: Settings - ddrescue-tui
|
||||
|
||||
import re
|
||||
|
||||
from collections import OrderedDict
|
||||
|
||||
# General
|
||||
|
|
@ -33,6 +35,15 @@ DDRESCUE_SETTINGS = {
|
|||
'--timeout': {'Enabled': True, 'Value': '5m', },
|
||||
'-vvvv': {'Enabled': True, 'Hidden': True, },
|
||||
}
|
||||
REGEX_REMAINING_TIME = re.compile(
|
||||
r'remaining time:'
|
||||
r'\s*((?P<days>\d+)d)?'
|
||||
r'\s*((?P<hours>\d+)h)?'
|
||||
r'\s*((?P<minutes>\d+)m)?'
|
||||
r'\s*((?P<seconds>\d+)s)?'
|
||||
r'\s*(?P<na>n/a)?',
|
||||
re.IGNORECASE
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Reference in a new issue