small fix
[enigma2.git] / lib / python / Components / Timezones.py
index 6f71187b9d1dab74d13eccffbc795a1cfd3bafc9..f3e24ee6c766eb4cd502c0efa47e050b1a52d849 100644 (file)
@@ -1,7 +1,7 @@
 from xml.sax import make_parser
 from xml.sax.handler import ContentHandler
 
-import os
+from os import environ, unlink, symlink
 import time
 
 class Timezones:
@@ -21,16 +21,35 @@ class Timezones:
 
        def readTimezonesFromFile(self):
                parser = make_parser()
-               timezonesHandler = self.parseTimezones(self.timezones)
-               parser.setContentHandler(timezonesHandler)
-               parser.parse('/etc/timezone.xml')
+               
+               try:
+                       timezonesHandler = self.parseTimezones(self.timezones)
+                       parser.setContentHandler(timezonesHandler)
+                       parser.parse('/etc/timezone.xml')
+               except:
+                       pass
+               
+               if len(self.timezones) == 0:
+                       self.timezones = [("UTC", "UTC")]
                
        def activateTimezone(self, index):
-               os.environ['TZ'] = self.timezones[index][1]
+               if len(self.timezones) <= index:
+                       return
+               
+               environ['TZ'] = self.timezones[index][1]
+               try:
+                       unlink("/etc/localtime")
+               except OSError:
+                       pass
+               try:
+                       symlink("/usr/share/zoneinfo/%s" %(self.timezones[index][1]), "/etc/localtime")
+               except OSError:
+                       pass
                try:
                        time.tzset()
                except:
-                       print "Timezone NOT set because your python has problems with time.tzset()"
+                       from enigma import e_tzset
+                       e_tzset()
                
        def getTimezoneList(self):
                list = []
@@ -40,6 +59,10 @@ class Timezones:
        
        def getDefaultTimezone(self):
                # TODO return something more useful - depending on country-settings?
-               return 27
+               t = "(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Vienna"
+               for (a,b) in self.timezones:
+                       if a == t:
+                               return a
+               return self.timezones[0][0]
 
 timezones = Timezones()