Commit 0fd96045 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Add output_callback to sfdisk

parent 2ec4b0fd
......@@ -57,7 +57,7 @@ class DiskUsageASIS(Plugin):
sfdisk.create_partition(-1, 500, 'EFI System')
sfdisk.create_partition(-1, 500, 'Linux filesystem')
sfdisk.create_partition(-1, -1, 'Linux filesystem')
sfdisk.write_partitions(disk, output_callback=ili_state.output_callback)
# Add the block devices to the installer
ili_state.output_callback('Adding block devices')
......@@ -19,7 +19,8 @@ import re
import subprocess
from typing import Dict, List
from idmslinux_installer.util.asyncsubprocess import AsyncSubprocess
from idmslinux_installer.util.asyncsubprocess import (AsyncSubprocess,
class Sfdisk:
......@@ -76,9 +77,13 @@ class Sfdisk:
'type': part_type,
def write_partitions(self, device: str):
def write_partitions(self, device: str, output_callback: OutputCallback = None):
"""Write out partitions to a disk device."""
# If we didn't get an output_callback, set it to our own class method
if not output_callback:
output_callback = self._default_output_callback
# Generate partition lines
partition_lines: List[str] = [
'%s,%s,%s\n' % (_sanitize_parm(x['start']), _sanitize_parm(x['size']), self.partition_types[x['type']])
......@@ -86,14 +91,18 @@ class Sfdisk:
# Run sfdisk
proc = AsyncSubprocess(['sfdisk', '--wipe', 'always', '--label', 'gpt', device],
proc = AsyncSubprocess(['sfdisk', '--wipe', 'always', '--wipe-partitions', 'always', '--label', 'gpt', device],
input_lines=partition_lines, output_callback=output_callback)
# Raise an exception if we didn't get a positive response back
if proc.retcode != 0:
raise OSError(f'Failed to write partitions to device {device} return code {proc.retcode}')
def _default_output_callback(self, line: str):
print(f'grub: {line}')
def _sanitize_parm(pos: int) -> str:
"""Sanitize sfdisk start/size parameter."""
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment