2015-06-24 20:22:21 +00:00
|
|
|
# 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
|
2015-07-01 21:20:17 +00:00
|
|
|
from urwid import (WidgetWrap, ListBox, Pile, BoxAdapter, Text, Columns)
|
2015-06-24 20:22:21 +00:00
|
|
|
from subiquity.ui.lists import SimpleList
|
|
|
|
from subiquity.ui.buttons import confirm_btn, cancel_btn
|
|
|
|
from subiquity.ui.utils import Padding, Color
|
|
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger('subiquity.filesystemView')
|
|
|
|
|
|
|
|
|
|
|
|
class FilesystemView(WidgetWrap):
|
|
|
|
def __init__(self, model, cb):
|
|
|
|
self.model = model
|
|
|
|
self.cb = cb
|
|
|
|
self.items = []
|
|
|
|
self.body = [
|
2015-07-01 21:20:17 +00:00
|
|
|
Padding.center_79(Text("FILE SYSTEM")),
|
2015-06-30 20:08:16 +00:00
|
|
|
Padding.center_79(self._build_partition_list()),
|
|
|
|
Padding.line_break(""),
|
2015-07-01 21:20:17 +00:00
|
|
|
Padding.center_79(Text("AVAILABLE DISKS")),
|
2015-06-24 20:22:21 +00:00
|
|
|
Padding.center_79(self._build_model_inputs()),
|
|
|
|
Padding.line_break(""),
|
|
|
|
Padding.center_79(self._build_additional_options()),
|
|
|
|
Padding.line_break(""),
|
|
|
|
Padding.center_20(self._build_buttons()),
|
|
|
|
]
|
|
|
|
super().__init__(ListBox(self.body))
|
|
|
|
|
2015-06-30 20:08:16 +00:00
|
|
|
def _build_partition_list(self):
|
2015-07-01 21:20:17 +00:00
|
|
|
pl = []
|
2015-06-30 20:08:16 +00:00
|
|
|
if len(self.model.get_partitions()) == 0:
|
|
|
|
pl.append(Color.info_minor(
|
|
|
|
Text("No disks or partitions mounted")))
|
|
|
|
return Pile(pl)
|
|
|
|
for part in self.model.get_partitions():
|
|
|
|
pl.append(Text(part))
|
|
|
|
return Pile(pl)
|
|
|
|
|
2015-06-24 20:22:21 +00:00
|
|
|
def _build_buttons(self):
|
|
|
|
buttons = [
|
|
|
|
Color.button_secondary(cancel_btn(on_press=self.cancel),
|
|
|
|
focus_map='button_secondary focus'),
|
|
|
|
]
|
|
|
|
return Pile(buttons)
|
|
|
|
|
|
|
|
def _build_model_inputs(self):
|
2015-06-30 18:04:19 +00:00
|
|
|
self.model.probe_storage()
|
2015-07-01 21:20:17 +00:00
|
|
|
disks = self.model.get_available_disks()
|
|
|
|
col_1 = []
|
|
|
|
col_2 = []
|
2015-06-25 21:50:13 +00:00
|
|
|
|
2015-07-01 21:20:17 +00:00
|
|
|
for disk in disks:
|
|
|
|
col_1.append(
|
|
|
|
Color.button_primary(confirm_btn(label=disk,
|
|
|
|
on_press=self.confirm),
|
|
|
|
focus_map='button_primary focus'))
|
2015-06-30 18:04:19 +00:00
|
|
|
disk_sz = self.model.get_disk_size(disk)
|
2015-06-24 20:22:21 +00:00
|
|
|
|
2015-07-01 21:20:17 +00:00
|
|
|
col_2.append(Text(disk_sz))
|
|
|
|
|
|
|
|
col_1 = BoxAdapter(SimpleList(col_1),
|
|
|
|
height=len(col_1))
|
|
|
|
col_2 = BoxAdapter(SimpleList(col_2, is_selectable=False),
|
|
|
|
height=len(col_2))
|
2015-07-03 00:53:18 +00:00
|
|
|
return Columns([(15, col_1), col_2], 2)
|
2015-06-24 20:22:21 +00:00
|
|
|
|
|
|
|
def _build_additional_options(self):
|
|
|
|
opts = []
|
|
|
|
for opt in self.model.additional_options:
|
|
|
|
opts.append(
|
|
|
|
Color.button_secondary(confirm_btn(label=opt,
|
|
|
|
on_press=self.confirm),
|
|
|
|
focus_map='button_secondary focus'))
|
|
|
|
return Pile(opts)
|
|
|
|
|
|
|
|
def confirm(self, button):
|
|
|
|
return self.cb(button.label)
|
|
|
|
|
|
|
|
def cancel(self, button):
|
|
|
|
return self.cb(None)
|