diff options
author | Chris Lumens <clumens@redhat.com> | 2013-02-08 15:51:19 -0500 |
---|---|---|
committer | Chris Lumens <clumens@redhat.com> | 2013-02-11 11:24:33 -0500 |
commit | c4736b84bd2d6a5c01eb8112ae71501e11354343 (patch) | |
tree | cdee285e9ded99fe856ab61b178a7a74d366e5fd /pyanaconda | |
parent | cff1355f85b3847dddcb4766c1ce37011c331b44 (diff) | |
download | anaconda-c4736b84bd2d6a5c01eb8112ae71501e11354343.tar.gz anaconda-c4736b84bd2d6a5c01eb8112ae71501e11354343.tar.xz anaconda-c4736b84bd2d6a5c01eb8112ae71501e11354343.zip |
Add a new selectorFromDevice method to the accordion.
This allows creating a new MountpointSelector using a Device as a template,
or modifying an existing MountpointSelector. It also consolidates a lot of
the specifics of doing that creation.
Diffstat (limited to 'pyanaconda')
-rw-r--r-- | pyanaconda/ui/gui/spokes/custom.py | 69 | ||||
-rw-r--r-- | pyanaconda/ui/gui/spokes/lib/accordion.py | 75 |
2 files changed, 74 insertions, 70 deletions
diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py index 747407672..dea3dce8d 100644 --- a/pyanaconda/ui/gui/spokes/custom.py +++ b/pyanaconda/ui/gui/spokes/custom.py @@ -22,8 +22,6 @@ # TODO: # - Add a way for users to specify the names of subvols. -# - We should either remove boot disk selection from the cart we show from here -# or re-partition when it gets changed to make a best-effort at keeping up. # - Deleting an LV is not reflected in available space in the bottom left. # - this is only true for preexisting LVs # - Device descriptions, suggested sizes, etc. should be moved out into a support file. @@ -531,24 +529,6 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker): fsCombo.append_text(obj.name) self._fs_types.append(obj.name) - def _mountpointName(self, mountpoint): - # If there's a mount point, apply a kind of lame scheme to it to figure - # out what the name should be. Basically, just look for the last directory - # in the mount point's path and capitalize the first letter. So "/boot" - # becomes "Boot", and "/usr/local" becomes "Local". - if mountpoint == "/": - return "Root" - elif mountpoint != None: - try: - lastSlash = mountpoint.rindex("/") - except ValueError: - # No slash in the mount point? I suppose that's possible. - return None - - return mountpoint[lastSlash+1:].capitalize() - else: - return None - @property def _clearpartDevices(self): return [d for d in self._devices if d.name in self.data.clearpart.drives and d.partitioned] @@ -741,8 +721,8 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker): (root.name != self.translated_new_install_name and not device.format.exists): continue - selector = page.addDevice(self._mountpointName(mountpoint) or device.format.name, Size(spec="%f MB" % device.size), mountpoint, self.on_selector_clicked) - selector._device = device + selector = page.addSelector(device, self.on_selector_clicked, + mountpoint=mountpoint) selector._root = root for device in root.swaps: @@ -750,10 +730,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker): (root.name != self.translated_new_install_name and not device.format.exists): continue - selector = page.addDevice("Swap", - Size(spec="%f MB" % device.size), - None, self.on_selector_clicked) - selector._device = device + selector = page.addSelector(device, self.on_selector_clicked) selector._root = root page.show_all() @@ -768,8 +745,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker): page.pageTitle = _("Unknown") for u in sorted(self.unusedDevices, key=lambda d: d.name): - selector = page.addDevice(u.name, Size(spec="%f MB" % u.size), u.format.name, self.on_selector_clicked) - selector._device = u + page.addSelector(u, self.on_selector_clicked) page.show_all() self._accordion.addPage(page, cb=self.on_page_clicked) @@ -835,16 +811,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker): devices.extend(self.bootLoaderDevices) for _device in devices: - mountpoint = getattr(_device.format, "mountpoint", "") or "" - - if _device.format.type == "swap": - name = "Swap" - else: - name = self._mountpointName(mountpoint) or _device.format.name - - selector = page.addDevice(name, Size(spec="%f MB" % _device.size), - mountpoint, self.on_selector_clicked) - selector._device = _device + page.addSelector(_device, self.on_selector_clicked) page.show_all() @@ -857,7 +824,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker): for selector in page._members: if selector._device.type.startswith("btrfs"): - selector.props.size = str(Size(spec="%f MB" % selector._device.size)).upper() + selectorFromDevice(selector._device, selector=selector) def _replace_device(self, *args, **kwargs): """ Create a replacement device and update the device selector. """ @@ -871,8 +838,8 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker): max_id = max([d.id for d in self._devices]) # update the selector with the new device and its size - selector._device = self.__storage.devicetree.getDeviceByID(max_id) - selector.props.size = str(Size(spec="%f MB" % selector._device.size)).upper() + selectorFromDevice(self.__storage.devicetree.getDeviceByID(max_id), + selector=selector) def _save_right_side(self, selector): """ Save settings from RHS and apply changes to the device. @@ -1118,10 +1085,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker): # you can't change the type of an existing device, so we # don't need to concern ourselves with adding a new # selector to the new page - selector.props.mountpoint = (mountpoint or - selector._device.format.name) - selector.props.name = (self._mountpointName(mountpoint) or - selector._device.format.name) + selectorFromDevice(device, selector=selector) self._devices = self.__storage.devices # update size props of all btrfs devices' selectors @@ -1186,7 +1150,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker): log.debug("updating selector size to '%s'" % str(Size(spec="%f MB" % device.size)).upper()) # update the selector's size property - selector.props.size = str(Size(spec="%f MB" % device.size)).upper() + selectorFromDevice(device, selector=selector) # update size props of all btrfs devices' selectors self._update_btrfs_selectors() @@ -1290,10 +1254,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker): # either update the existing selector or add a new one if new_selector: - new_selector.props.mountpoint = mountpoint or "" - new_selector.props.name = (self._mountpointName(mountpoint) - or device.format.name) - new_selector._device = device + selectorFromDevice(device, selector=new_selector) else: self.add_new_selector(device) @@ -1313,9 +1274,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker): log.debug("updating mountpoint to %s" % mountpoint) device.format.mountpoint = mountpoint if old_mountpoint: - selector.props.mountpoint = mountpoint - selector.props.name = (self._mountpointName(mountpoint) - or selector._device.format.name) + selectorFromDevice(device, selector=selector) else: # add an entry to the new page but do not remove any entries # from other pages since we haven't altered the filesystem @@ -1432,7 +1391,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker): # We want to preserve the state of the customize expander so that it's # open should you open it and then look at some other device instead. - expander.set_expanded(selector.customizeIsOpen) + expander.set_expanded(selector._customizeIsOpen) device = selector._device if device.type == "luks/dm-crypt": @@ -1672,7 +1631,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker): if not self._current_selector: return - self._current_selector.customizeIsOpen = not self._current_selector.customizeIsOpen + self._current_selector._customizeIsOpen = not self._current_selector._customizeIsOpen def on_add_clicked(self, button): self._save_right_side(self._current_selector) diff --git a/pyanaconda/ui/gui/spokes/lib/accordion.py b/pyanaconda/ui/gui/spokes/lib/accordion.py index adb6e4a3e..aab671291 100644 --- a/pyanaconda/ui/gui/spokes/lib/accordion.py +++ b/pyanaconda/ui/gui/spokes/lib/accordion.py @@ -23,18 +23,73 @@ import gettext _ = lambda x: gettext.ldgettext("anaconda", x) +from blivet.size import Size + from pyanaconda.product import productName, productVersion from gi.repository.AnacondaWidgets import MountpointSelector from gi.repository import Gtk __all__ = ["DATA_DEVICE", "SYSTEM_DEVICE", + "selectorFromDevice", "Accordion", "Page", "UnknownPage", "CreateNewPage"] DATA_DEVICE = 0 SYSTEM_DEVICE = 1 +def mountpointName(mountpoint): + # If there's a mount point, apply a kind of lame scheme to it to figure + # out what the name should be. Basically, just look for the last directory + # in the mount point's path and capitalize the first letter. So "/boot" + # becomes "Boot", and "/usr/local" becomes "Local". + if mountpoint == "/": + return "Root" + elif mountpoint != None: + try: + lastSlash = mountpoint.rindex("/") + except ValueError: + # No slash in the mount point? I suppose that's possible. + return None + + return mountpoint[lastSlash+1:].capitalize() + else: + return None + +def selectorFromDevice(device, selector=None, mountpoint=""): + """Create a MountpointSelector from a Device object template. This + method should be used whenever constructing a new selector, or when + setting a bunch of attributes on an existing selector. For just + changing the name or size, it's probably fine to do it by hand. + + This method returns the selector created. + + If given a selector parameter, attributes will be set on that object + instead of creating a new one. The optional mountpoint parameter + allows for specifying the mountpoint if it cannot be determined from + the device (like for a Root specifying an existing installation). + """ + mp = mountpoint or getattr(device.format, "mountpoint", "") + + if device.format.type == "swap": + name = "Swap" + else: + name = mountpointName(mp) or device.format.name + + size = Size(spec="%f MB" % device.size) + + if not selector: + selector = MountpointSelector(name, str(size).upper(), mp) + selector._root = None + selector._customizeIsOpen = False + else: + selector.props.name = name + selector.props.size = str(size).upper() + selector.props.mountpoint = mp + + selector._device = device + return selector + # An Accordion is a box that goes on the left side of the custom partitioning spoke. It # stores multiple expanders which are here called Pages. These Pages correspond to # individual installed OSes on the system plus some special ones. When one Page is @@ -146,18 +201,13 @@ class Page(Gtk.Box): label.set_margin_left(24) return label - def addDevice(self, name, size, mountpoint, cb): - selector = MountpointSelector(name, str(size).upper(), mountpoint or "") + def addSelector(self, device, cb, mountpoint=""): + selector = selectorFromDevice(device, mountpoint=mountpoint) selector.connect("button-press-event", self._onSelectorClicked, cb) selector.connect("key-release-event", self._onSelectorClicked, cb) - #selector.connect("focus-in-event", self._onSelectorClicked, cb) self._members.append(selector) - selector._device = None - selector._root = None - selector.customizeIsOpen = False - - if self._mountpointType(mountpoint) == DATA_DEVICE: + if self._mountpointType(selector.props.mountpoint) == DATA_DEVICE: self._dataBox.add(selector) else: self._systemBox.add(selector) @@ -203,15 +253,10 @@ class UnknownPage(Page): self._members = [] self.pageTitle = "" - def addDevice(self, name, size, mountpoint, cb): - selector = MountpointSelector(name, str(size).upper(), mountpoint or "") + def addSelector(self, device, cb, mountpoint=""): + selector = selectorFromDevice(device, mountpoint=mountpoint) selector.connect("button-press-event", self._onSelectorClicked, cb) selector.connect("key-release-event", self._onSelectorClicked, cb) - #selector.connect("focus-in-event", self._onSelectorClicked, cb) - - selector._device = None - selector._root = None - selector.customizeIsOpen = False self._members.append(selector) self.add(selector) |