Made several State() functions "private"
This commit is contained in:
parent
097360ca0a
commit
848ccc3ef1
1 changed files with 72 additions and 71 deletions
|
|
@ -268,10 +268,10 @@ class State():
|
||||||
self.working_dir = None
|
self.working_dir = None
|
||||||
|
|
||||||
# Start a background process to maintain layout
|
# Start a background process to maintain layout
|
||||||
self.init_tmux()
|
self._init_tmux()
|
||||||
exe.start_thread(self.fix_tmux_layout_loop)
|
exe.start_thread(self._fix_tmux_layout_loop)
|
||||||
|
|
||||||
def add_block_pair(self, source, destination):
|
def _add_block_pair(self, source, destination):
|
||||||
"""Add BlockPair object and run safety checks."""
|
"""Add BlockPair object and run safety checks."""
|
||||||
self.block_pairs.append(
|
self.block_pairs.append(
|
||||||
BlockPair(
|
BlockPair(
|
||||||
|
|
@ -281,6 +281,71 @@ class State():
|
||||||
working_dir=self.working_dir,
|
working_dir=self.working_dir,
|
||||||
))
|
))
|
||||||
|
|
||||||
|
def _fix_tmux_layout(self, forced=True):
|
||||||
|
"""Fix tmux layout based on cfg.ddrescue.TMUX_LAYOUT."""
|
||||||
|
layout = cfg.ddrescue.TMUX_LAYOUT
|
||||||
|
needs_fixed = tmux.layout_needs_fixed(self.panes, layout)
|
||||||
|
|
||||||
|
# Main layout fix
|
||||||
|
try:
|
||||||
|
tmux.fix_layout(self.panes, layout, forced=forced)
|
||||||
|
except RuntimeError:
|
||||||
|
# Assuming self.panes changed while running
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Source/Destination
|
||||||
|
if forced or needs_fixed:
|
||||||
|
self.update_top_panes()
|
||||||
|
|
||||||
|
# Return if Progress pane not present
|
||||||
|
if 'Progress' not in self.panes:
|
||||||
|
return
|
||||||
|
|
||||||
|
# SMART/Journal
|
||||||
|
if forced or needs_fixed:
|
||||||
|
height = tmux.get_pane_size(self.panes['Progress'])[1] - 2
|
||||||
|
p_ratios = [int((x/sum(PANE_RATIOS)) * height) for x in PANE_RATIOS]
|
||||||
|
if 'SMART' in self.panes:
|
||||||
|
tmux.resize_pane(self.panes['SMART'], height=p_ratios[0])
|
||||||
|
tmux.resize_pane(height=p_ratios[1])
|
||||||
|
if 'Journal' in self.panes:
|
||||||
|
tmux.resize_pane(self.panes['Journal'], height=p_ratios[2])
|
||||||
|
|
||||||
|
def _fix_tmux_layout_loop(self):
|
||||||
|
"""Fix tmux layout on a loop.
|
||||||
|
|
||||||
|
NOTE: This should be called as a thread.
|
||||||
|
"""
|
||||||
|
while True:
|
||||||
|
self._fix_tmux_layout(forced=False)
|
||||||
|
std.sleep(1)
|
||||||
|
|
||||||
|
def _init_tmux(self):
|
||||||
|
"""Initialize tmux layout."""
|
||||||
|
tmux.kill_all_panes()
|
||||||
|
|
||||||
|
# Source (placeholder)
|
||||||
|
self.panes['Source'] = tmux.split_window(
|
||||||
|
behind=True,
|
||||||
|
lines=2,
|
||||||
|
text=' ',
|
||||||
|
vertical=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Started
|
||||||
|
self.panes['Started'] = tmux.split_window(
|
||||||
|
lines=cfg.ddrescue.TMUX_SIDE_WIDTH,
|
||||||
|
target_id=self.panes['Source'],
|
||||||
|
text=std.color_string(
|
||||||
|
['Started', time.strftime("%Y-%m-%d %H:%M %Z")],
|
||||||
|
['BLUE', None],
|
||||||
|
sep='\n',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
# Source / Dest
|
||||||
|
self.update_top_panes()
|
||||||
|
|
||||||
def add_clone_block_pairs(self):
|
def add_clone_block_pairs(self):
|
||||||
"""Add device to device block pairs and set settings if necessary."""
|
"""Add device to device block pairs and set settings if necessary."""
|
||||||
source_sep = get_partition_separator(self.source.path.name)
|
source_sep = get_partition_separator(self.source.path.name)
|
||||||
|
|
@ -301,13 +366,13 @@ class State():
|
||||||
bp_dest = pathlib.Path(
|
bp_dest = pathlib.Path(
|
||||||
f'{self.destination.path}{dest_sep}{part_map[1]}',
|
f'{self.destination.path}{dest_sep}{part_map[1]}',
|
||||||
)
|
)
|
||||||
self.add_block_pair(bp_source, bp_dest)
|
self._add_block_pair(bp_source, bp_dest)
|
||||||
else:
|
else:
|
||||||
source_parts = select_disk_parts('Clone', self.source)
|
source_parts = select_disk_parts('Clone', self.source)
|
||||||
if self.source.path.samefile(source_parts[0].path):
|
if self.source.path.samefile(source_parts[0].path):
|
||||||
# Whole disk (or single partition via args), skip settings
|
# Whole disk (or single partition via args), skip settings
|
||||||
bp_dest = self.destination.path
|
bp_dest = self.destination.path
|
||||||
self.add_block_pair(self.source, bp_dest)
|
self._add_block_pair(self.source, bp_dest)
|
||||||
else:
|
else:
|
||||||
# New run, use new settings file
|
# New run, use new settings file
|
||||||
settings['Needs Format'] = True
|
settings['Needs Format'] = True
|
||||||
|
|
@ -333,7 +398,7 @@ class State():
|
||||||
bp_dest = pathlib.Path(
|
bp_dest = pathlib.Path(
|
||||||
f'{self.destination.path}{dest_sep}{dest_num}',
|
f'{self.destination.path}{dest_sep}{dest_num}',
|
||||||
)
|
)
|
||||||
self.add_block_pair(part, bp_dest)
|
self._add_block_pair(part, bp_dest)
|
||||||
|
|
||||||
# Add to settings file
|
# Add to settings file
|
||||||
source_num = re.sub(r'^.*?(\d+)$', r'\1', part.path.name)
|
source_num = re.sub(r'^.*?(\d+)$', r'\1', part.path.name)
|
||||||
|
|
@ -349,7 +414,7 @@ class State():
|
||||||
"""Add device to image file block pairs."""
|
"""Add device to image file block pairs."""
|
||||||
for part in source_parts:
|
for part in source_parts:
|
||||||
bp_dest = self.destination
|
bp_dest = self.destination
|
||||||
self.add_block_pair(part, bp_dest)
|
self._add_block_pair(part, bp_dest)
|
||||||
|
|
||||||
def confirm_selections(self, prompt, source_parts=None):
|
def confirm_selections(self, prompt, source_parts=None):
|
||||||
"""Show selection details and prompt for confirmation."""
|
"""Show selection details and prompt for confirmation."""
|
||||||
|
|
@ -433,44 +498,7 @@ class State():
|
||||||
if not std.ask(prompt):
|
if not std.ask(prompt):
|
||||||
raise std.GenericAbort()
|
raise std.GenericAbort()
|
||||||
|
|
||||||
def fix_tmux_layout(self, forced=True):
|
|
||||||
"""Fix tmux layout based on cfg.ddrescue.TMUX_LAYOUT."""
|
|
||||||
layout = cfg.ddrescue.TMUX_LAYOUT
|
|
||||||
needs_fixed = tmux.layout_needs_fixed(self.panes, layout)
|
|
||||||
|
|
||||||
# Main layout fix
|
|
||||||
try:
|
|
||||||
tmux.fix_layout(self.panes, layout, forced=forced)
|
|
||||||
except RuntimeError:
|
|
||||||
# Assuming self.panes changed while running
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Source/Destination
|
|
||||||
if forced or needs_fixed:
|
|
||||||
self.update_top_panes()
|
|
||||||
|
|
||||||
# Return if Progress pane not present
|
|
||||||
if 'Progress' not in self.panes:
|
|
||||||
return
|
|
||||||
|
|
||||||
# SMART/Journal
|
|
||||||
if forced or needs_fixed:
|
|
||||||
height = tmux.get_pane_size(self.panes['Progress'])[1] - 2
|
|
||||||
p_ratios = [int((x/sum(PANE_RATIOS)) * height) for x in PANE_RATIOS]
|
|
||||||
if 'SMART' in self.panes:
|
|
||||||
tmux.resize_pane(self.panes['SMART'], height=p_ratios[0])
|
|
||||||
tmux.resize_pane(height=p_ratios[1])
|
|
||||||
if 'Journal' in self.panes:
|
|
||||||
tmux.resize_pane(self.panes['Journal'], height=p_ratios[2])
|
|
||||||
|
|
||||||
def fix_tmux_layout_loop(self):
|
|
||||||
"""Fix tmux layout on a loop.
|
|
||||||
|
|
||||||
NOTE: This should be called as a thread.
|
|
||||||
"""
|
|
||||||
while True:
|
|
||||||
self.fix_tmux_layout(forced=False)
|
|
||||||
std.sleep(1)
|
|
||||||
|
|
||||||
def init_recovery(self, docopt_args):
|
def init_recovery(self, docopt_args):
|
||||||
"""Select source/dest and set env."""
|
"""Select source/dest and set env."""
|
||||||
|
|
@ -557,32 +585,6 @@ class State():
|
||||||
for pair in self.block_pairs:
|
for pair in self.block_pairs:
|
||||||
pair.safety_check()
|
pair.safety_check()
|
||||||
|
|
||||||
def init_tmux(self):
|
|
||||||
"""Initialize tmux layout."""
|
|
||||||
tmux.kill_all_panes()
|
|
||||||
|
|
||||||
# Source (placeholder)
|
|
||||||
self.panes['Source'] = tmux.split_window(
|
|
||||||
behind=True,
|
|
||||||
lines=2,
|
|
||||||
text=' ',
|
|
||||||
vertical=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Started
|
|
||||||
self.panes['Started'] = tmux.split_window(
|
|
||||||
lines=cfg.ddrescue.TMUX_SIDE_WIDTH,
|
|
||||||
target_id=self.panes['Source'],
|
|
||||||
text=std.color_string(
|
|
||||||
['Started', time.strftime("%Y-%m-%d %H:%M %Z")],
|
|
||||||
['BLUE', None],
|
|
||||||
sep='\n',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
# Source / Dest
|
|
||||||
self.update_top_panes()
|
|
||||||
|
|
||||||
def load_settings(self, discard_unused_settings=False):
|
def load_settings(self, discard_unused_settings=False):
|
||||||
"""Load settings from previous run, returns dict."""
|
"""Load settings from previous run, returns dict."""
|
||||||
settings = {}
|
settings = {}
|
||||||
|
|
@ -773,7 +775,6 @@ class State():
|
||||||
)
|
)
|
||||||
raise std.GenericAbort()
|
raise std.GenericAbort()
|
||||||
|
|
||||||
|
|
||||||
def safety_check_size(self):
|
def safety_check_size(self):
|
||||||
"""Run size safety check and abort if necessary."""
|
"""Run size safety check and abort if necessary."""
|
||||||
required_size = sum([pair.size for pair in self.block_pairs])
|
required_size = sum([pair.size for pair in self.block_pairs])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue