from xml.sax import make_parser
from xml.sax.handler import ContentHandler
+import os
+import time
+
+from enigma import *
+
class Timezones:
class parseTimezones(ContentHandler):
def __init__(self, timezones):
self.timezones = timezones
def startElement(self, name, attrs):
- print "Name: " + str(name)
if (name == "zone"):
- self.timezones[attrs.get('name',"")] = attrs.get('zone',"")
- #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
- #tpos = attrs.get('position',"")
- #tname = attrs.get('name',"")
- #self.satellites[tpos] = tname
- #self.satList.append( (tname, tpos) )
- #self.parsedSat = int(tpos)
+ self.timezones.append((attrs.get('name',""), attrs.get('zone',"")))
def __init__(self):
- self.timezones = {}
+ self.timezones = []
self.readTimezonesFromFile()
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):
+ if len(self.timezones) <= index:
+ return
+
+ os.environ['TZ'] = self.timezones[index][1]
+ try:
+ time.tzset()
+ except:
+ etimezone()
+
+ def getTimezoneList(self):
+ list = []
+ for x in self.timezones:
+ list.append(str(x[0]))
+ return list
+
+ def getDefaultTimezone(self):
+ # TODO return something more useful - depending on country-settings?
+ return 27
timezones = Timezones()