convert AddFormatView to use same form as AddPartitionView
This commit is contained in:
parent
4a54ca9e50
commit
e7ba045434
|
@ -167,13 +167,13 @@ class FilesystemController(BaseController):
|
||||||
def add_format_handler(self, volume, spec, back):
|
def add_format_handler(self, volume, spec, back):
|
||||||
log.debug('add_format_handler')
|
log.debug('add_format_handler')
|
||||||
if spec['fstype'] is not None:
|
if spec['fstype'] is not None:
|
||||||
fs = self.model.add_filesystem(volume, spec['fstype'])
|
fs = self.model.add_filesystem(volume, spec['fstype'].label)
|
||||||
else:
|
else:
|
||||||
fs = volume.fs()
|
fs = volume.fs()
|
||||||
if spec['mountpoint']:
|
if spec['mount']:
|
||||||
if fs is None:
|
if fs is None:
|
||||||
raise Exception("{} is not formatted".format(volume.path))
|
raise Exception("{} is not formatted".format(volume.path))
|
||||||
self.model.add_mount(fs, spec['mountpoint'])
|
self.model.add_mount(fs, spec['mount'])
|
||||||
back()
|
back()
|
||||||
|
|
||||||
def connect_iscsi_disk(self, *args, **kwargs):
|
def connect_iscsi_disk(self, *args, **kwargs):
|
||||||
|
|
|
@ -20,8 +20,7 @@ configuration.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .add_format import AddFormatView
|
from .add_partition import AddFormatView, AddPartitionView
|
||||||
from .add_partition import AddPartitionView
|
|
||||||
from .disk_info import DiskInfoView
|
from .disk_info import DiskInfoView
|
||||||
from .disk_partition import DiskPartitionView
|
from .disk_partition import DiskPartitionView
|
||||||
from .filesystem import FilesystemView
|
from .filesystem import FilesystemView
|
||||||
|
|
|
@ -1,101 +0,0 @@
|
||||||
# Copyright 2015 Canonical, Ltd.
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
import logging
|
|
||||||
from urwid import connect_signal
|
|
||||||
|
|
||||||
from subiquitycore.ui.utils import Padding
|
|
||||||
from subiquitycore.ui.container import ListBox
|
|
||||||
from subiquitycore.ui.form import Form
|
|
||||||
from subiquitycore.view import BaseView
|
|
||||||
|
|
||||||
from subiquity.ui.mount import MountField
|
|
||||||
from subiquity.ui.views.filesystem.add_partition import FSTypeField
|
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger('subiquity.ui.filesystem.add_format')
|
|
||||||
|
|
||||||
|
|
||||||
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, volume, back):
|
|
||||||
self.model = model
|
|
||||||
self.controller = controller
|
|
||||||
self.volume = volume
|
|
||||||
self.back = back
|
|
||||||
|
|
||||||
self.form = AddFormatForm(model)
|
|
||||||
if self.volume.fs() is not None:
|
|
||||||
for i, fs_spec in enumerate(self.model.supported_filesystems):
|
|
||||||
if len(fs_spec) == 3:
|
|
||||||
fs = fs_spec[2]
|
|
||||||
if fs.label == self.volume.fs().fstype:
|
|
||||||
self.form.fstype.widget.index = i
|
|
||||||
self.form.fstype.enabled = False
|
|
||||||
connect_signal(self.form, 'submit', self.done)
|
|
||||||
connect_signal(self.form, 'cancel', self.cancel)
|
|
||||||
|
|
||||||
body = [
|
|
||||||
Padding.line_break(""),
|
|
||||||
self.form.as_rows(self),
|
|
||||||
Padding.line_break(""),
|
|
||||||
Padding.fixed_10(self.form.buttons)
|
|
||||||
]
|
|
||||||
format_box = Padding.center_50(ListBox(body))
|
|
||||||
super().__init__(format_box)
|
|
||||||
|
|
||||||
def cancel(self, button=None):
|
|
||||||
self.back()
|
|
||||||
|
|
||||||
def done(self, result):
|
|
||||||
""" format spec
|
|
||||||
|
|
||||||
{
|
|
||||||
'format' Str(ext4|btrfs..,
|
|
||||||
'mountpoint': Str
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
fstype = self.form.fstype.value
|
|
||||||
|
|
||||||
if fstype.is_mounted:
|
|
||||||
mount = self.form.mount.value
|
|
||||||
else:
|
|
||||||
mount = None
|
|
||||||
|
|
||||||
result = {
|
|
||||||
"fstype": fstype.label,
|
|
||||||
"mountpoint": mount,
|
|
||||||
}
|
|
||||||
if self.volume.fs() is not None:
|
|
||||||
result['fstype'] = None
|
|
||||||
|
|
||||||
log.debug("Add Format Result: {}".format(result))
|
|
||||||
self.controller.add_format_handler(self.volume, result, self.back)
|
|
|
@ -53,10 +53,14 @@ class PartitionForm(Form):
|
||||||
|
|
||||||
def __init__(self, model, max_size, initial={}):
|
def __init__(self, model, max_size, initial={}):
|
||||||
self.model = model
|
self.model = model
|
||||||
self.max_size = max_size
|
|
||||||
self.size_str = humanize_size(max_size)
|
|
||||||
super().__init__(initial)
|
super().__init__(initial)
|
||||||
self.size.caption = "Size (max {})".format(self.size_str)
|
if max_size is not None:
|
||||||
|
self.max_size = max_size
|
||||||
|
self.size_str = humanize_size(max_size)
|
||||||
|
self.size.caption = "Size (max {})".format(self.size_str)
|
||||||
|
else:
|
||||||
|
self.remove_field('partnum')
|
||||||
|
self.remove_field('size')
|
||||||
connect_signal(self.fstype.widget, 'select', self.select_fstype)
|
connect_signal(self.fstype.widget, 'select', self.select_fstype)
|
||||||
|
|
||||||
def select_fstype(self, sender, fs):
|
def select_fstype(self, sender, fs):
|
||||||
|
@ -121,3 +125,36 @@ class AddPartitionView(BaseView):
|
||||||
def done(self, form):
|
def done(self, form):
|
||||||
log.debug("Add Partition Result: {}".format(form.as_data()))
|
log.debug("Add Partition Result: {}".format(form.as_data()))
|
||||||
self.controller.add_disk_partition_handler(self.disk, form.as_data())
|
self.controller.add_disk_partition_handler(self.disk, form.as_data())
|
||||||
|
|
||||||
|
|
||||||
|
class AddFormatView(BaseView):
|
||||||
|
def __init__(self, model, controller, volume, back):
|
||||||
|
self.model = model
|
||||||
|
self.controller = controller
|
||||||
|
self.volume = volume
|
||||||
|
self.back = back
|
||||||
|
|
||||||
|
initial = {}
|
||||||
|
fs = self.volume.fs()
|
||||||
|
if fs is not None:
|
||||||
|
initial['fstype'] = self.model.fs_by_name[fs.fstype]
|
||||||
|
self.form = PartitionForm(model, None, initial)
|
||||||
|
|
||||||
|
connect_signal(self.form, 'submit', self.done)
|
||||||
|
connect_signal(self.form, 'cancel', self.cancel)
|
||||||
|
|
||||||
|
body = [
|
||||||
|
Padding.line_break(""),
|
||||||
|
self.form.as_rows(self),
|
||||||
|
Padding.line_break(""),
|
||||||
|
Padding.fixed_10(self.form.buttons)
|
||||||
|
]
|
||||||
|
format_box = Padding.center_50(ListBox(body))
|
||||||
|
super().__init__(format_box)
|
||||||
|
|
||||||
|
def cancel(self, button=None):
|
||||||
|
self.back()
|
||||||
|
|
||||||
|
def done(self, form):
|
||||||
|
log.debug("Add Partition Result: {}".format(form.as_data()))
|
||||||
|
self.controller.add_format_handler(self.volume, form.as_data(), self.back)
|
||||||
|
|
Loading…
Reference in New Issue