diff --git a/subiquity/controllers/filesystem.py b/subiquity/controllers/filesystem.py index f8c4e40f..5f9b9c89 100644 --- a/subiquity/controllers/filesystem.py +++ b/subiquity/controllers/filesystem.py @@ -19,10 +19,9 @@ import os from subiquitycore.controller import BaseController from subiquitycore.ui.dummy import DummyView -from subiquity.models.filesystem import align_up, humanize_size +from subiquity.models.filesystem import align_up from subiquity.ui.views import ( BcacheView, - DiskInfoView, DiskPartitionView, FilesystemView, FormatEntireView, @@ -285,57 +284,6 @@ class FilesystemController(BaseController): next_device = available[next_idx] self.show_disk_information(next_device) - def show_disk_information(self, disk): - """ Show disk information, requires sudo/root - """ - bus = disk._info.raw.get('ID_BUS', None) - major = disk._info.raw.get('MAJOR', None) - if bus is None and major == '253': - bus = 'virtio' - - devpath = disk._info.raw.get('DEVPATH', disk.path) - rotational = '1' - try: - dev = os.path.basename(devpath) - rfile = '/sys/class/block/{}/queue/rotational'.format(dev) - rotational = open(rfile, 'r').read().strip() - except (PermissionError, FileNotFoundError, IOError): - log.exception('WARNING: Failed to read file {}'.format(rfile)) - pass - - dinfo = { - 'bus': bus, - 'devname': disk.path, - 'devpath': devpath, - 'model': disk.model, - 'serial': disk.serial, - 'size': disk.size, - 'humansize': humanize_size(disk.size), - 'vendor': disk._info.vendor, - 'rotational': 'true' if rotational == '1' else 'false', - } - if dinfo['serial'] is None: - dinfo['serial'] = 'unknown' - if dinfo['model'] is None: - dinfo['model'] = 'unknown' - if dinfo['vendor'] is None: - dinfo['vendor'] = 'unknown' - - template = """\n -{devname}:\n - Vendor: {vendor} - Model: {model} - SerialNo: {serial} - Size: {humansize} ({size}B) - Bus: {bus} - Rotational: {rotational} - Path: {devpath} -""" - result = template.format(**dinfo) - log.debug('calling DiskInfoView()') - disk_info_view = DiskInfoView(self.model, self, disk, result) - self.ui.set_body(disk_info_view) - def is_uefi(self): if self.opts.dry_run: return self.opts.uefi diff --git a/subiquity/models/filesystem.py b/subiquity/models/filesystem.py index 4daf73c6..73de6c61 100644 --- a/subiquity/models/filesystem.py +++ b/subiquity/models/filesystem.py @@ -231,6 +231,42 @@ class Disk(_Device): d.model = info.model return d + def info_for_display(self): + bus = self._info.raw.get('ID_BUS', None) + major = self._info.raw.get('MAJOR', None) + if bus is None and major == '253': + bus = 'virtio' + + devpath = self._info.raw.get('DEVPATH', self.path) + # XXX probert should be doing this!! + rotational = '1' + try: + dev = os.path.basename(devpath) + rfile = '/sys/class/block/{}/queue/rotational'.format(dev) + rotational = open(rfile, 'r').read().strip() + except (PermissionError, FileNotFoundError, IOError): + log.exception('WARNING: Failed to read file {}'.format(rfile)) + pass + + dinfo = { + 'bus': bus, + 'devname': self.path, + 'devpath': devpath, + 'model': self.model, + 'serial': self.serial, + 'size': self.size, + 'humansize': humanize_size(self.size), + 'vendor': self._info.vendor, + 'rotational': 'true' if rotational == '1' else 'false', + } + if dinfo['serial'] is None: + dinfo['serial'] = 'unknown' + if dinfo['model'] is None: + dinfo['model'] = 'unknown' + if dinfo['vendor'] is None: + dinfo['vendor'] = 'unknown' + return dinfo + def reset(self): self.preserve = False self.name = '' diff --git a/subiquity/ui/views/__init__.py b/subiquity/ui/views/__init__.py index 4c52bae7..46a00c3c 100644 --- a/subiquity/ui/views/__init__.py +++ b/subiquity/ui/views/__init__.py @@ -17,7 +17,6 @@ from .filesystem import (FilesystemView, PartitionView, FormatEntireView, DiskPartitionView, - DiskInfoView, GuidedDiskSelectionView, GuidedFilesystemView) from .bcache import BcacheView diff --git a/subiquity/ui/views/filesystem/__init__.py b/subiquity/ui/views/filesystem/__init__.py index b5334b35..5a1401d2 100644 --- a/subiquity/ui/views/filesystem/__init__.py +++ b/subiquity/ui/views/filesystem/__init__.py @@ -20,7 +20,6 @@ configuration. """ -from .disk_info import DiskInfoView from .disk_partition import DiskPartitionView from .filesystem import FilesystemView from .guided import GuidedDiskSelectionView, GuidedFilesystemView diff --git a/subiquity/ui/views/filesystem/disk_info.py b/subiquity/ui/views/filesystem/disk_info.py index ac6af281..0ed20933 100644 --- a/subiquity/ui/views/filesystem/disk_info.py +++ b/subiquity/ui/views/filesystem/disk_info.py @@ -17,49 +17,35 @@ import logging from urwid import Text from subiquitycore.ui.buttons import done_btn -from subiquitycore.ui.container import ListBox -from subiquitycore.ui.utils import button_pile, Padding -from subiquitycore.view import BaseView +from subiquitycore.ui.utils import button_pile +from subiquitycore.ui.stretchy import Stretchy log = logging.getLogger('subiquity.ui.filesystem.disk_info') -class DiskInfoView(BaseView): - - footer = _('Select next or previous disks with n and p') - - def __init__(self, model, controller, disk, hdinfo): +class DiskInfoStretchy(Stretchy): + def __init__(self, parent, disk): log.debug('DiskInfoView: {}'.format(disk)) - self.model = model - self.controller = controller - self.disk = disk - self.title = _("Information on {}").format(disk.label) - hdinfo = hdinfo.split("\n") - body = [] - for h in hdinfo: - body.append(Text(h)) - body.append(self._build_buttons()) - super().__init__(Padding.center_79(ListBox(body))) + self.parent = parent + dinfo = disk.info_for_display() + template = """\ +{devname}:\n + Vendor: {vendor} + Model: {model} + SerialNo: {serial} + Size: {humansize} ({size}B) + Bus: {bus} + Rotational: {rotational} + Path: {devpath}""" + result = template.format(**dinfo) + widgets = [ + Text(result), + Text(""), + button_pile([done_btn(_("Close"), on_press=self.close)]), + ] + title = _("Info for {}").format(disk.label) + super().__init__(title, widgets, 0, 2) - def _build_buttons(self): - return button_pile([done_btn(_("Done"), on_press=self.done)]) - - def keypress(self, size, key): - if key in ['tab', 'n', 'N', 'j', 'J']: - log.debug('keypress: [{}]'.format(key)) - self.controller.show_disk_information_next(self.disk) - return None - if key in ['shift tab', 'p', 'P', 'k', 'K']: - log.debug('keypress: [{}]'.format(key)) - self.controller.show_disk_information_prev(self.disk) - return None - - return super().keypress(size, key) - - def done(self, result): - ''' Return to FilesystemView ''' - self.controller.partition_disk(self.disk) - - def cancel(self, button=None): - self.controller.partition_disk(self.disk) + def close(self, button=None): + self.parent.remove_overlay() diff --git a/subiquity/ui/views/filesystem/filesystem.py b/subiquity/ui/views/filesystem/filesystem.py index aa94b838..8f4eaad0 100644 --- a/subiquity/ui/views/filesystem/filesystem.py +++ b/subiquity/ui/views/filesystem/filesystem.py @@ -267,6 +267,10 @@ class DeviceList(WidgetWrap): def _device_action(self, sender, action, device): log.debug('_device_action %s %s', action, device) + if action == DeviceAction.INFO: + from .disk_info import DiskInfoStretchy + self.parent.show_stretchy_overlay( + DiskInfoStretchy(self.parent, device)) def _partition_action(self, sender, action, part): log.debug('_partition_action %s %s', action, part)