[PATCH 1/2] Don't crash if someone gives us bad timezone

Chris Lumens clumens at redhat.com
Mon Aug 27 18:07:33 UTC 2012


> diff --git a/pyanaconda/ui/gui/spokes/datetime_spoke.py b/pyanaconda/ui/gui/spokes/datetime_spoke.py
> index 4d345df..2fcb333 100644
> --- a/pyanaconda/ui/gui/spokes/datetime_spoke.py
> +++ b/pyanaconda/ui/gui/spokes/datetime_spoke.py
> @@ -23,6 +23,9 @@ import gettext
>  _ = lambda x: gettext.ldgettext("anaconda", x)
>  N_ = lambda x: x
>  
> +import logging
> +log = logging.getLogger("anaconda")
> +
>  from gi.repository import AnacondaWidgets, GLib, Gtk
>  
>  from pyanaconda.ui.gui import GUIObject
> @@ -310,10 +313,12 @@ class DatetimeSpoke(NormalSpoke):
>              self._set_amPm_part_sensitive(False)
>  
>          self._update_datetime_timer_id = None
> -        if self.data.timezone.timezone:
> +        if timezone.is_valid_timezone(self.data.timezone.timezone):
>              self._tzmap.set_timezone(self.data.timezone.timezone)
>          else:
> -            self._tzmap.set_timezone("Europe/Prague")
> +            log.warning("%s is not a valid timezone, falling back to default "\
> +                        "(America/New_Yor)")

Typo here - New_Yor.

> @@ -321,7 +326,13 @@ class DatetimeSpoke(NormalSpoke):
>      @property
>      def status(self):
>          if self.data.timezone.timezone:
> -            return _("%s timezone") % self.data.timezone.timezone
> +            if timezone.is_valid_timezone(self.data.timezone.timezone):
> +                valid_str = ""
> +            else:
> +                valid_str = " " + _("(not valid)")
> +
> +            return _("%s timezone%s") % (self.data.timezone.timezone, valid_str)
> +
>          else:
>              return _("%s timezone") % self._tzmap.get_timezone()

Hm, I don't know for sure but I think this is going to be a difficult
string for translators to deal with.  Do we really need to tell the user
what invalid timezone was provided here?  If we don't need to, we can
just have an error string like "Invalid timezone given" and then it's a
much easier translation.

In general, pasting together strings results in problems for
translators.

- Chris


More information about the anaconda-patches mailing list