Move build_block_pair_report() to block_pair.py
This commit is contained in:
parent
6bef46bb4d
commit
42720d322b
2 changed files with 56 additions and 55 deletions
|
|
@ -12,7 +12,7 @@ import subprocess
|
||||||
from wk import cfg, exe, std
|
from wk import cfg, exe, std
|
||||||
from wk.clone import menus
|
from wk.clone import menus
|
||||||
from wk.hw import disk as hw_disk
|
from wk.hw import disk as hw_disk
|
||||||
from wk.ui import cli
|
from wk.ui import ansi, cli
|
||||||
|
|
||||||
|
|
||||||
# STATIC VARIABLES
|
# STATIC VARIABLES
|
||||||
|
|
@ -315,6 +315,60 @@ def add_image_block_pairs(state) -> None:
|
||||||
state.add_block_pair(part, state.destination)
|
state.add_block_pair(part, state.destination)
|
||||||
|
|
||||||
|
|
||||||
|
def build_block_pair_report(block_pairs, settings) -> list:
|
||||||
|
"""Build block pair report, returns list."""
|
||||||
|
report = []
|
||||||
|
notes = []
|
||||||
|
if block_pairs:
|
||||||
|
report.append(ansi.color_string('Block Pairs', 'GREEN'))
|
||||||
|
else:
|
||||||
|
# Bail early
|
||||||
|
return report
|
||||||
|
|
||||||
|
# Show block pair mapping
|
||||||
|
if settings and settings['Create Boot Partition']:
|
||||||
|
if settings['Table Type'] == 'GPT':
|
||||||
|
report.append(f'{" —— ":<9} --> EFI System Partition')
|
||||||
|
report.append(f'{" —— ":<9} --> Microsoft Reserved Partition')
|
||||||
|
elif settings['Table Type'] == 'MBR':
|
||||||
|
report.append(f'{" —— ":<9} --> System Reserved')
|
||||||
|
for pair in block_pairs:
|
||||||
|
report.append(f'{pair.source.name:<9} --> {pair.destination.name}')
|
||||||
|
|
||||||
|
# Show resume messages as necessary
|
||||||
|
if settings:
|
||||||
|
if not settings['First Run']:
|
||||||
|
notes.append(
|
||||||
|
ansi.color_string(
|
||||||
|
['NOTE:', 'Clone settings loaded from previous run.'],
|
||||||
|
['BLUE', None],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
if settings['Needs Format'] and settings['Table Type']:
|
||||||
|
msg = f'Destination will be formatted using {settings["Table Type"]}'
|
||||||
|
notes.append(
|
||||||
|
ansi.color_string(
|
||||||
|
['NOTE:', msg],
|
||||||
|
['BLUE', None],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
if any(pair.get_rescued_size() > 0 for pair in block_pairs):
|
||||||
|
notes.append(
|
||||||
|
ansi.color_string(
|
||||||
|
['NOTE:', 'Resume data loaded from map file(s).'],
|
||||||
|
['BLUE', None],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add notes to report
|
||||||
|
if notes:
|
||||||
|
report.append(' ')
|
||||||
|
report.extend(notes)
|
||||||
|
|
||||||
|
# Done
|
||||||
|
return report
|
||||||
|
|
||||||
|
|
||||||
def build_sfdisk_partition_line(table_type, dev_path, size, details) -> str:
|
def build_sfdisk_partition_line(table_type, dev_path, size, details) -> str:
|
||||||
"""Build sfdisk partition line using passed details, returns str."""
|
"""Build sfdisk partition line using passed details, returns str."""
|
||||||
line = f'{dev_path} : size={size}'
|
line = f'{dev_path} : size={size}'
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ from wk.clone.block_pair import (
|
||||||
BlockPair,
|
BlockPair,
|
||||||
add_clone_block_pairs,
|
add_clone_block_pairs,
|
||||||
add_image_block_pairs,
|
add_image_block_pairs,
|
||||||
|
build_block_pair_report,
|
||||||
prep_destination,
|
prep_destination,
|
||||||
)
|
)
|
||||||
from wk.clone.image import mount_raw_image
|
from wk.clone.image import mount_raw_image
|
||||||
|
|
@ -694,60 +695,6 @@ class State():
|
||||||
|
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
def build_block_pair_report(block_pairs, settings) -> list:
|
|
||||||
"""Build block pair report, returns list."""
|
|
||||||
report = []
|
|
||||||
notes = []
|
|
||||||
if block_pairs:
|
|
||||||
report.append(ansi.color_string('Block Pairs', 'GREEN'))
|
|
||||||
else:
|
|
||||||
# Bail early
|
|
||||||
return report
|
|
||||||
|
|
||||||
# Show block pair mapping
|
|
||||||
if settings and settings['Create Boot Partition']:
|
|
||||||
if settings['Table Type'] == 'GPT':
|
|
||||||
report.append(f'{" —— ":<9} --> EFI System Partition')
|
|
||||||
report.append(f'{" —— ":<9} --> Microsoft Reserved Partition')
|
|
||||||
elif settings['Table Type'] == 'MBR':
|
|
||||||
report.append(f'{" —— ":<9} --> System Reserved')
|
|
||||||
for pair in block_pairs:
|
|
||||||
report.append(f'{pair.source.name:<9} --> {pair.destination.name}')
|
|
||||||
|
|
||||||
# Show resume messages as necessary
|
|
||||||
if settings:
|
|
||||||
if not settings['First Run']:
|
|
||||||
notes.append(
|
|
||||||
ansi.color_string(
|
|
||||||
['NOTE:', 'Clone settings loaded from previous run.'],
|
|
||||||
['BLUE', None],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
if settings['Needs Format'] and settings['Table Type']:
|
|
||||||
msg = f'Destination will be formatted using {settings["Table Type"]}'
|
|
||||||
notes.append(
|
|
||||||
ansi.color_string(
|
|
||||||
['NOTE:', msg],
|
|
||||||
['BLUE', None],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
if any(pair.get_rescued_size() > 0 for pair in block_pairs):
|
|
||||||
notes.append(
|
|
||||||
ansi.color_string(
|
|
||||||
['NOTE:', 'Resume data loaded from map file(s).'],
|
|
||||||
['BLUE', None],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
# Add notes to report
|
|
||||||
if notes:
|
|
||||||
report.append(' ')
|
|
||||||
report.extend(notes)
|
|
||||||
|
|
||||||
# Done
|
|
||||||
return report
|
|
||||||
|
|
||||||
|
|
||||||
def build_directory_report(path: pathlib.Path) -> list[str]:
|
def build_directory_report(path: pathlib.Path) -> list[str]:
|
||||||
"""Build directory report, returns list."""
|
"""Build directory report, returns list."""
|
||||||
path_str = f'{path}/'
|
path_str = f'{path}/'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue