]> git.ipfire.org Git - people/ms/bricklayer.git/commitdiff
Add timezone selection
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 9 May 2021 11:28:40 +0000 (11:28 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 9 May 2021 11:29:39 +0000 (11:29 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/python/__init__.py
src/python/timezones.py [new file with mode: 0644]

index 95662b7a19b6a839cb29180537eef358376b3134..e7db9314243fe6a71c64f1481492cc298841542f 100644 (file)
@@ -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
index da174c06213cb0551854b2632248ab9add332a88..f2ebbdeb95757628e7ce6f9488077e80697fde8f 100644 (file)
@@ -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 (file)
index 0000000..661440d
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+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