From: Michael Tremer Date: Sun, 9 May 2021 11:28:40 +0000 (+0000) Subject: Add timezone selection X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=10fa0a33663c7d0a389f09c1802f53d8071867a3;p=people%2Fms%2Fbricklayer.git Add timezone selection Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 95662b7..e7db931 100644 --- a/Makefile.am +++ b/Makefile.am @@ -51,5 +51,6 @@ dist_pkgpython_PYTHON = \ src/python/logger.py \ src/python/packages.py \ src/python/step.py \ + src/python/timezones.py \ src/python/tui.py \ src/python/util.py diff --git a/src/python/__init__.py b/src/python/__init__.py index da174c0..f2ebbde 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -31,6 +31,7 @@ from . import i18n from . import logger from . import packages from . import step +from . import timezones from . import tui from . import util from .i18n import _ @@ -62,6 +63,9 @@ class Bricklayer(object): # Set the default swap size to 1 GiB "swap-size": 1024 ** 3, + + # Default timezone + "timezone" : "UTC", } # Read OS information @@ -85,6 +89,7 @@ class Bricklayer(object): steps = ( step.UnattendedWarning, step.Welcome, + timezones.SelectTimezone, disk.SelectDisk, disk.CalculatePartitionLayout, step.RootPassword, diff --git a/src/python/timezones.py b/src/python/timezones.py new file mode 100644 index 0000000..661440d --- /dev/null +++ b/src/python/timezones.py @@ -0,0 +1,50 @@ +############################################################################### +# # +# Bricklayer - An Installer for IPFire # +# Copyright (C) 2021 IPFire Development Team # +# # +# This program is free software; you can redistribute it and/or # +# modify it under the terms of the GNU General Public License # +# as published by the Free Software Foundation; either version 2 # +# of the License, or (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty 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, see . # +# # +############################################################################### + +import logging +import pytz + +from . import step +from .i18n import _ + +# Setup logging +log = logging.getLogger("bricklayer.timezones") + +class SelectTimezone(step.InteractiveStep): + def run(self, tui): + # Get a list of all available timezones + timezones = { + tz : tz for tz in sorted(pytz.all_timezones) + } + + # Which timezone is currently selected? + timezone = self.bricklayer.settings.get("timezone", "UTC") + + timezone = tui.select( + _("Timezone"), + _("Please select the timezone:"), + timezones, default=timezone, + height=10, + ) + + log.info("Selected timezone: %s" % timezone) + + # Save in settings + self.bricklayer.settings["timezone"] = timezone