Patchwork [bitbake-devel,02/14] toaster: fix timezone detection

login
register
mail settings
Submitter Alexandru DAMIAN
Date March 31, 2014, 4:47 p.m.
Message ID <53e5cdf5b6cd715e8b1ed57c52abbce2184de75e.1396284354.git.alexandru.damian@intel.com>
Download mbox | patch
Permalink /patch/69707/
State New
Headers show

Comments

Alexandru DAMIAN - March 31, 2014, 4:47 p.m.
From: Alexandru DAMIAN <alexandru.damian@intel.com>

This patch replaces faulty timezone detection with a version
that simply reads the TZ environment variable if it is set.

If the TZ is not set, we do a reverse match search among known
timezone definitions and take the first match.

    [YOCTO #5499]

Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
---
 lib/toaster/toastermain/settings.py | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

Patch

diff --git a/lib/toaster/toastermain/settings.py b/lib/toaster/toastermain/settings.py
index 51fa3cc..e26ee3c 100644
--- a/lib/toaster/toastermain/settings.py
+++ b/lib/toaster/toastermain/settings.py
@@ -50,9 +50,23 @@  ALLOWED_HOSTS = []
 # although not all choices may be available on all operating systems.
 # In a Windows environment this must be set to your system time zone.
 
-# Always use local computer's time zone
-import time
-TIME_ZONE = time.tzname[0]
+# Always use local computer's time zone, find
+import os, hashlib
+if 'TZ' in os.environ:
+    TIME_ZONE = os.environ['TZ']
+else:
+    # need to read the /etc/localtime file which is the libc standard
+    # and do a reverse-mapping to /usr/share/zoneinfo/;
+    # since the timezone may match any number of identical timezone definitions,
+
+    zonefilelist = {}
+    ZONEINFOPATH = '/usr/share/zoneinfo/'
+    for dirpath, dirnames, filenames in os.walk(ZONEINFOPATH):
+        for fn in filenames:
+            filepath = os.path.join(dirpath, fn)
+            zonefilelist[hashlib.md5(open(filepath).read()).hexdigest()] = filepath.lstrip(ZONEINFOPATH).strip()
+
+    TIME_ZONE = zonefilelist[hashlib.md5(open('/etc/localtime').read()).hexdigest()]
 
 # Language code for this installation. All choices can be found here:
 # http://www.i18nguy.com/unicode/language-identifiers.html