[anaconda][master/rhel7-branch] [PATCH 1/3] Add dialog box to warn about formatting DASDs. (#1064423)
Vratislav Podzimek
vpodzime at redhat.com
Tue Feb 25 12:02:17 UTC 2014
On Tue, 2014-02-25 at 04:30 -0500, Samantha N. Bueno wrote:
> A GtkDialog box which shows the progress of dasdfmt as it is run
> against unformatted DASDs.
>
> Resolves: rhbz#1064423
> ---
> po/POTFILES.in | 2 +
> pyanaconda/ui/gui/spokes/lib/dasdfmt.glade | 211 +++++++++++++++++++++++++++++
> pyanaconda/ui/gui/spokes/lib/dasdfmt.py | 111 +++++++++++++++
> 3 files changed, 324 insertions(+)
> create mode 100644 pyanaconda/ui/gui/spokes/lib/dasdfmt.glade
> create mode 100644 pyanaconda/ui/gui/spokes/lib/dasdfmt.py
> diff --git a/pyanaconda/ui/gui/spokes/lib/dasdfmt.py b/pyanaconda/ui/gui/spokes/lib/dasdfmt.py
> new file mode 100644
> index 0000000..802855c
> --- /dev/null
> +++ b/pyanaconda/ui/gui/spokes/lib/dasdfmt.py
> @@ -0,0 +1,111 @@
> +# DASD format dialog
> +#
> +# Copyright (C) 2014 Red Hat, Inc.
> +#
> +# This copyrighted material is made available to anyone wishing to use,
> +# modify, copy, or redistribute it subject to the terms and conditions of
> +# the GNU General Public License v.2, or (at your option) any later version.
> +# This program is distributed in the hope that it will be useful, but WITHOUT
> +# ANY WARRANTY expressed or implied, including the implied warranties of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
> +# Public License for more details. You should have received a copy of the
> +# GNU General Public License along with this program; if not, write to the
> +# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> +# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
> +# source code or documentation are not subject to the GNU General Public
> +# License and may only be used or replicated with the express permission of
> +# Red Hat, Inc.
> +#
> +# Red Hat Author(s): Samantha N. Bueno <sbueno at redhat.com>
> +# Chris Lumens <clumens at redhat.com>
> +#
> +
> +from pyanaconda.threads import threadMgr, AnacondaThread
> +from pyanaconda.ui.communication import hubQ
> +from pyanaconda.ui.gui import GUIObject
> +from pyanaconda.ui.gui.utils import gtk_call_once
> +from pyanaconda import constants
> +from pyanaconda.i18n import _
> +
> +from blivet import storageInitialize
> +from blivet.devicelibs.dasd import format_dasd
> +from blivet.errors import DasdFormatError
> +
> +import logging
> +log = logging.getLogger("anaconda")
> +
> +__all__ = ["DasdFormatDialog"]
> +
> +class DasdFormatDialog(GUIObject):
> + builderObjects = ["unformattedDasdDialog"]
> + mainWidgetName = "unformattedDasdDialog"
> + uiFile = "spokes/lib/dasdfmt.glade"
> +
> + def __init__(self, data, storage, to_format):
> + GUIObject.__init__(self, data)
> +
> + self.storage = storage
> + self.to_format = to_format
> +
> + self._notebook = self.builder.get_object("formatNotebook")
> + self._cancel_button = self.builder.get_object("udCancelButton")
> + self._ok_button = self.builder.get_object("udOKButton")
> + self._label = self.builder.get_object("udLabel")
> +
> + def run(self):
> + rc = self.window.run()
> + self.window.destroy()
> + return rc
> +
> + def run_dasdfmt(self, *args):
> + """
> + Loop through our disks and run dasdfmt against them. After that loop has
> + finished, launch stage two of this operation (finish_dasdfmt).
> + """
> + for disk in self.to_format:
> + try:
> + self._label.set_text(_("Formatting /dev/%s. This may take a moment." % disk))
This shoudl be called with gtk_call_once as it is called from a non-main
thread.
> + format_dasd(disk)
> + except DasdFormatError as err:
> + # Log errors if formatting fails, but don't halt the installer
> + log.error(str(err))
> + continue
> +
> + gtk_call_once(self.finish_dasdfmt)
Should this be called even when the dialog is exited by clicking the
link button? If not, have a look at the NTPConfig dialog that uses an
epoch to discard outdated actions.
> +
> + def dasdfmt(self, *args):
> + """
> + This is the handler that gets called from the GtkDialog and sets things
> + in motion. We launch the *actual* call to run dasdfmt from a thread.
> + """
> + # Run through all of the formatting
> + self._cancel_button.set_sensitive(True)
> + self._ok_button.set_sensitive(False)
> + self._notebook.set_current_page(0)
> +
> + # Loop through all of our unformatted DASDs and format them
> + threadMgr.add(AnacondaThread(name=constants.THREAD_DASDFMT,
> + target=self.run_dasdfmt, args=(self,)))
> +
> + def finish_dasdfmt(self):
> + """
> + This is the second stage of the dasdfmt operation; now that formatting
> + is complete, we need to reinitialize storage so that the newly
> + formatted devices are added properly to the devicetree.
> + """
> + protectedNames = map(lambda d: d.name, self.storage.protectedDevices)
> + threadMgr.add(AnacondaThread(name=constants.THREAD_STORAGE, target=storageInitialize,
> + args=(self.storage, self.data, protectedNames)))
I believe threadMgr.add returns the thread name (at least on master). So
you can store it and use it in the following wait call. Might make the
code a bit clearer.
> +
> + threadMgr.wait(constants.THREAD_STORAGE)
> + self._notebook.set_current_page(1)
> + self._ok_button.set_sensitive(True)
> +
> + def return_to_hub_link_clicked(self, label, uri):
> + """
> + The user clicked on the link that takes them back to the hub. We need
> + to emit a special response ID indicating the user did not press OK.
> +
> + NOTE: There is no button with response_id=2.
> + """
> + self.window.response(2)
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
More information about the anaconda-patches
mailing list