Patchwork [bitbake-devel,1/9] toaster: do not load all available timezones

login
register
mail settings
Submitter Alexandru DAMIAN
Date April 9, 2014, 1:17 p.m.
Message ID <c93e5ca809d9c335b0cf35dcad4705487414c71b.1397049329.git.alexandru.damian@intel.com>
Download mbox | patch
Permalink /patch/70373/
State New
Headers show

Comments

Alexandru DAMIAN - April 9, 2014, 1:17 p.m.
From: Alexandru DAMIAN <alexandru.damian@intel.com>

This patch makes sure that we only load pytz-recognized
timezones. Pytz is used to transform the timezone information
for the database queries, and needs to be able to deal with
the TIME_ZONE value that we set up.

[YOCTO #6093]

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

Patch

diff --git a/lib/toaster/toastermain/settings.py b/lib/toaster/toastermain/settings.py
index e26ee3c..6e9d85d 100644
--- a/lib/toaster/toastermain/settings.py
+++ b/lib/toaster/toastermain/settings.py
@@ -64,7 +64,15 @@  else:
     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()
+            try:
+                import pytz
+                from pytz.exceptions import UnknownTimeZoneError
+                zonename = filepath.lstrip(ZONEINFOPATH).strip()
+                if pytz.timezone(zonename) is not None:
+                    zonefilelist[hashlib.md5(open(filepath).read()).hexdigest()] = zonename
+            except UnknownTimeZoneError, ValueError:
+                # we expect timezone failures here, just move over
+                pass
 
     TIME_ZONE = zonefilelist[hashlib.md5(open('/etc/localtime').read()).hexdigest()]