Merge pull request #127 from CanonicalLtd/hide_menu_options_as_needed
Hide menu options as needed
This commit is contained in:
commit
d2bec60d54
|
@ -16,6 +16,7 @@
|
|||
import json
|
||||
import logging
|
||||
import re
|
||||
from os.path import realpath
|
||||
|
||||
from .blockdev import Blockdev, Raiddev, Bcachedev, sort_actions
|
||||
import math
|
||||
|
@ -121,6 +122,14 @@ class FilesystemModel(ModelPolicy):
|
|||
"10",
|
||||
]
|
||||
|
||||
# th following blocktypes cannot be partitioned
|
||||
no_partition_blocktypes = [
|
||||
"bcache",
|
||||
"lvm_partition",
|
||||
"lvm_volgroup",
|
||||
"raid",
|
||||
]
|
||||
|
||||
def __init__(self, prober, opts):
|
||||
self.opts = opts
|
||||
self.prober = prober
|
||||
|
@ -470,6 +479,9 @@ class FilesystemModel(ModelPolicy):
|
|||
if not mountpoint.startswith('/'):
|
||||
raise ValueError('Does not start with /')
|
||||
|
||||
# remove redundent // and ..
|
||||
mountpoint = realpath(mountpoint)
|
||||
|
||||
# /usr/include/linux/limits.h:PATH_MAX
|
||||
if len(mountpoint) > 4095:
|
||||
raise ValueError('Path exceeds PATH_MAX')
|
||||
|
|
|
@ -345,6 +345,7 @@ class AddPartitionView(ViewPolicy):
|
|||
log.exception('Invalid mount point')
|
||||
self.mountpoint.set_error('Error: {}'.format(str(e)))
|
||||
log.debug("Invalid mountpoint, try again")
|
||||
return
|
||||
|
||||
log.debug("Add Partition Result: {}".format(result))
|
||||
self.signal.emit_signal('filesystem:finish-add-disk-partition',
|
||||
|
@ -409,9 +410,12 @@ class DiskPartitionView(ViewPolicy):
|
|||
changes to the button depending on if existing
|
||||
partitions exist or not.
|
||||
"""
|
||||
return Pile([self.add_partition_w(),
|
||||
menus = [
|
||||
self.add_partition_w(),
|
||||
self.create_swap_w(),
|
||||
self.show_disk_info_w()])
|
||||
self.show_disk_info_w(),
|
||||
]
|
||||
return Pile([m for m in menus if m])
|
||||
|
||||
def show_disk_info_w(self):
|
||||
""" Runs hdparm against device and displays its output
|
||||
|
@ -430,11 +434,11 @@ class DiskPartitionView(ViewPolicy):
|
|||
"""
|
||||
text = ("Format or create swap on entire "
|
||||
"device (unusual, advanced)")
|
||||
if len(self.disk_obj.partitions) == 0:
|
||||
if len(self.disk_obj.partitions) == 0 and \
|
||||
self.disk_obj.available:
|
||||
return Color.menu_button(menu_btn(label=text,
|
||||
on_press=self.create_swap),
|
||||
focus_map='menu_button focus')
|
||||
return Color.info_minor(Text(text))
|
||||
|
||||
def add_partition_w(self):
|
||||
""" Handles presenting the add partition widget button
|
||||
|
@ -444,6 +448,9 @@ class DiskPartitionView(ViewPolicy):
|
|||
if len(self.disk_obj.partitions) > 0:
|
||||
text = "Add partition (max size {})".format(
|
||||
_humanize_size(self.disk_obj.freespace))
|
||||
|
||||
if self.disk_obj.available and \
|
||||
self.disk_obj.blocktype not in self.model.no_partition_blocktypes:
|
||||
return Color.menu_button(menu_btn(label=text,
|
||||
on_press=self.add_partition),
|
||||
focus_map='menu_button focus')
|
||||
|
|
Loading…
Reference in New Issue