Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timezone: for kickstart allow also timezones not offered by GUI #5345

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pyanaconda/modules/timezone/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from pyanaconda.anaconda_loggers import get_module_logger
from pyanaconda.modules.common.errors.installation import TimezoneConfigurationError
from pyanaconda.modules.common.task import Task
from pyanaconda.timezone import is_valid_timezone
from pyanaconda.timezone import is_valid_timezone, is_valid_ui_timezone

from blivet import arch

Expand Down Expand Up @@ -60,7 +60,11 @@ def run(self):

def _correct_timezone(self):
"""Ensure the timezone is valid."""
if not is_valid_timezone(self._timezone):
if is_valid_timezone(self._timezone):
if not is_valid_ui_timezone(self._timezone):
log.warning("Timezone specification %s set in kickstart is "
"not offered by installer GUI.", self._timezone)
else:
# this should never happen, but for pity's sake
log.warning("Timezone %s set in kickstart is not valid, "
"falling back to default (America/New_York).", self._timezone)
Expand Down
21 changes: 19 additions & 2 deletions pyanaconda/timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ def get_all_regions_and_timezones():
return result


def is_valid_timezone(timezone):
def is_valid_ui_timezone(timezone):
"""
Check if a given string is an existing timezone.
Check if a given string is a timezone specification offered by GUI.

:type timezone: str
:rtype: bool
Expand All @@ -162,6 +162,23 @@ def is_valid_timezone(timezone):
return timezone in pytz.common_timezones + etc_zones


def is_valid_timezone(timezone):
"""
Check if a given string is a valid timezone specification.

This includes also deprecated/backward timezones linked to other timezones
in tz database (eg Japan -> Asia/Tokyo). Both the tzdata package (installed
system) and TimezoneMap widget (installer GUI) should support them and be
able link them to the correct timezone specification using the data from
"backward" file.

:type timezone: str
:rtype: bool
"""

return is_valid_ui_timezone(timezone) or timezone in pytz.all_timezones


def get_timezone(timezone):
"""
Return a tzinfo object for a given timezone name.
Expand Down
11 changes: 9 additions & 2 deletions pyanaconda/ui/gui/spokes/datetime_spoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
from pyanaconda.threading import threadMgr, AnacondaThread
from pyanaconda.core.i18n import _, CN_
from pyanaconda.core.async_utils import async_action_wait, async_action_nowait
from pyanaconda.timezone import NTP_SERVICE, get_all_regions_and_timezones, get_timezone, is_valid_timezone
from pyanaconda.timezone import NTP_SERVICE, get_all_regions_and_timezones, get_timezone, \
is_valid_timezone, is_valid_ui_timezone
from pyanaconda.localization import get_xlated_timezone, resolve_date_format
from pyanaconda.core.timer import Timer

Expand Down Expand Up @@ -557,8 +558,14 @@ def _initialize(self):

self._update_datetime_timer = None
kickstart_timezone = self._timezone_module.Timezone
if is_valid_timezone(kickstart_timezone):
if is_valid_ui_timezone(kickstart_timezone):
self._set_timezone(kickstart_timezone)
elif is_valid_timezone(kickstart_timezone):
log.warning("Timezone specification %s is not offered by installer GUI.",
kickstart_timezone)
# Try to get the correct linked timezone via TimezoneMap selection
self._tzmap.set_timezone(kickstart_timezone)

elif not flags.flags.automatedInstall:
log.warning("%s is not a valid timezone, falling back to default (%s)",
kickstart_timezone, DEFAULT_TZ)
Expand Down
Loading