diff --git a/subiquity/controllers/filesystem.py b/subiquity/controllers/filesystem.py index 4e1ed768..a28eac4e 100644 --- a/subiquity/controllers/filesystem.py +++ b/subiquity/controllers/filesystem.py @@ -161,11 +161,9 @@ class FilesystemController(BaseController): def add_disk_format_handler(self, disk, spec): log.debug('add_disk_format_handler') - current_disk = self.model.get_disk(disk) - log.debug('format spec: {}'.format(spec)) - log.debug('disk.freespace: {}'.format(current_disk.freespace)) - current_disk.format_device(spec['fstype'], spec['mountpoint']) - log.debug("FS Table: {}".format(current_disk.get_fs_table())) + fs = self.model.add_filesystem(disk, spec['fstype']) + if spec['mountpoint']: + self.model.add_mount(fs, spec['mountpoint']) self.prev_view() def connect_iscsi_disk(self, *args, **kwargs): @@ -231,9 +229,8 @@ class FilesystemController(BaseController): self.signal.prev_signal() @view - def create_swap_entire_device(self, disk): - log.debug('create_swap_entire_device') - log.debug("formatting whole {}".format(disk)) + def format_entire(self, disk): + log.debug("format_entire {}".format(disk)) footer = ("Format or mount whole disk.") self.ui.set_footer(footer) afv_view = AddFormatView(self.model, self, disk) diff --git a/subiquity/models/filesystem.py b/subiquity/models/filesystem.py index 1c0e6e77..f037101d 100644 --- a/subiquity/models/filesystem.py +++ b/subiquity/models/filesystem.py @@ -667,6 +667,8 @@ class Disk: @property def used(self): + if self._fs is not None: + return self.size r = 0 for p in self._partitions: r += p.size diff --git a/subiquity/ui/views/filesystem/add_format.py b/subiquity/ui/views/filesystem/add_format.py index 5641d0d5..2a09f484 100644 --- a/subiquity/ui/views/filesystem/add_format.py +++ b/subiquity/ui/views/filesystem/add_format.py @@ -33,25 +33,27 @@ class AddFormatForm(Form): def __init__(self, model): self.model = model super().__init__() + connect_signal(self.fstype.widget, 'select', self.select_fstype) fstype = FSTypeField("Format") mount = MountField("Mount") + def select_fstype(self, sender, fs): + self.mount.enabled = fs.is_mounted + def validate_mount(self): return self.model.validate_mount(self.mount.value) class AddFormatView(BaseView): - def __init__(self, model, controller, selected_disk): + def __init__(self, model, controller, disk): self.model = model self.controller = controller - self.selected_disk = selected_disk - self.disk_obj = self.model.get_disk(selected_disk) + self.disk = disk self.form = AddFormatForm(model) connect_signal(self.form, 'submit', self.done) connect_signal(self.form, 'cancel', self.cancel) - connect_signal(self.form.fstype.widget, 'select', self.select_fstype) body = [ Padding.line_break(""), @@ -62,9 +64,6 @@ class AddFormatView(BaseView): format_box = Padding.center_50(ListBox(body)) super().__init__(format_box) - def select_fstype(self, sender, fs): - self.form.mount.enabled = fs.is_mounted - def cancel(self, button): self.controller.prev_view() @@ -89,4 +88,4 @@ class AddFormatView(BaseView): } log.debug("Add Format Result: {}".format(result)) - self.controller.add_disk_format_handler(self.disk_obj.devpath, result) + self.controller.add_disk_format_handler(self.disk, result) diff --git a/subiquity/ui/views/filesystem/disk_partition.py b/subiquity/ui/views/filesystem/disk_partition.py index c2c05c51..74cb8e9d 100644 --- a/subiquity/ui/views/filesystem/disk_partition.py +++ b/subiquity/ui/views/filesystem/disk_partition.py @@ -118,7 +118,7 @@ class DiskPartitionView(BaseView): if len(self.disk._partitions) == 0 and \ self.disk.available: return Color.menu_button( - menu_btn(label=text, on_press=self.create_swap)) + menu_btn(label=text, on_press=self.format_entire)) def add_partition_w(self): """ Handles presenting the add partition widget button @@ -140,8 +140,8 @@ class DiskPartitionView(BaseView): def add_partition(self, result): self.controller.add_disk_partition(self.disk) - def create_swap(self, result): - self.controller.create_swap_entire_device(self.selected_disk) + def format_entire(self, result): + self.controller.format_entire(self.disk) def done(self, result): ''' Return to FilesystemView '''