Skip to contentSkip to conversation

toaster: Allow toaster to start without pytz

PATCH New Paul Eggleton 1 participant 1 message Apr 9, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 toaster: Allow toaster to start without pytz

From: Alexandru DAMIAN <[email protected]>

This patch allows toaster to start without pytz.

Django can work with or without pytz, but in the time zone fix I mistakenly added a hard dependency on this module.

This patch eliminates the hard dependency.

---

v2: Fix authorship and indentation issues

 lib/toaster/toastermain/settings.py | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
lib/toaster/toastermain/settings.py +9 -5
index 6e9d85d..645f327 100644
@@ -64,15 +64,19 @@ else:
     for dirpath, dirnames, filenames in os.walk(ZONEINFOPATH):
         for fn in filenames:
             filepath = os.path.join(dirpath, fn)
+            zonename = 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
+                try:
+                    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
+            except ImportError:
+                zonefilelist[hashlib.md5(open(filepath).read()).hexdigest()] = zonename
 
     TIME_ZONE = zonefilelist[hashlib.md5(open('/etc/localtime').read()).hexdigest()]
 
Signature · 1 line
1.9.0