1 from xml.sax import make_parser
2 from xml.sax.handler import ContentHandler
4 from os import environ, unlink, symlink
8 class parseTimezones(ContentHandler):
9 def __init__(self, timezones):
10 self.isPointsElement, self.isReboundsElement = 0, 0
11 self.timezones = timezones
13 def startElement(self, name, attrs):
15 self.timezones.append((attrs.get('name',""), attrs.get('zone',"")))
20 self.readTimezonesFromFile()
22 def readTimezonesFromFile(self):
23 parser = make_parser()
26 timezonesHandler = self.parseTimezones(self.timezones)
27 parser.setContentHandler(timezonesHandler)
28 parser.parse('/etc/timezone.xml')
32 if len(self.timezones) == 0:
33 self.timezones = [("UTC", "UTC")]
35 def activateTimezone(self, index):
36 if len(self.timezones) <= index:
39 environ['TZ'] = self.timezones[index][1]
41 unlink("/etc/localtime")
45 symlink("/usr/share/zoneinfo/%s" %(self.timezones[index][1]), "/etc/localtime")
51 from enigma import e_tzset
54 def getTimezoneList(self):
56 for x in self.timezones:
57 list.append(str(x[0]))
60 def getDefaultTimezone(self):
61 # TODO return something more useful - depending on country-settings?
62 t = "(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Vienna"
63 for (a,b) in self.timezones:
66 return self.timezones[0][0]
68 timezones = Timezones()