[anaconda][master/rhel7-branch][PATCH 1/3] Add dialog box to warn about formatting DASDs. (#1064423)
Vratislav Podzimek
vpodzime at redhat.com
Wed Feb 26 09:17:52 UTC 2014
On Wed, 2014-02-26 at 00:07 -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 | 132 ++++++++++++++++++
> 3 files changed, 345 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..933fcaa
> --- /dev/null
> +++ b/pyanaconda/ui/gui/spokes/lib/dasdfmt.py
> @@ -0,0 +1,132 @@
> +# 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.gui import GUIObject
> +from pyanaconda.ui.gui.utils import gtk_call_once
> +from pyanaconda import constants
> +from pyanaconda.i18n import _
> +import threading
> +
> +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")
> +
> + # epoch is increased when a dasd is formatted
> + self._epoch = 0
> + self._epoch_lock = threading.Lock()
> +
> + def run(self):
> + rc = self.window.run()
> + self.window.destroy()
> +
> + if rc == 2:
> + # User clicked uri to return to hub. We need to catch this here so
> + # that we can halt all further dialog actions
> + self._epoch_lock.acquire()
> + self._epoch += 1
> + self._epoch_lock.release()
The threading.Lock() objects have support for the with block. So you can
reduce these three lines into:
with self._epoch_lock:
self._epoch += 1
I see it's not this way in the NTPConfigDialog. We could have it nice at
least here. :)
> + return rc
> +
> + def run_dasdfmt(self, epoch_started, *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))
Leftover ;)
> + gtk_call_once(self._label.set_text, _("Formatting /dev/%s. This may take a moment" % disk))
> + 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, epoch_started)
> +
> + 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._epoch,)))
> +
> + def finish_dasdfmt(self, epoch_started):
> + """
> + 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.
> + """
> + self._epoch_lock.acquire()
> + protectedNames = [d.name for d in self.storage.protectedDevices]
> + threadMgr.add(AnacondaThread(name=constants.THREAD_STORAGE, target=storageInitialize,
> + args=(self.storage, self.data, protectedNames)))
> +
> + threadMgr.wait(constants.THREAD_STORAGE)
> +
> + if epoch_started == self._epoch:
> + # we only want to change anything on the dialog if we are in the
> + # same epoch as it; the only time we should not be running these
> + # commands is if a user clicks return_to_hub
> + self._notebook.set_current_page(1)
> + self._cancel_button.set_sensitive(False)
> + self._ok_button.set_sensitive(True)
> + self._epoch_lock.release()
> +
> + 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