timezone selection works now. tzset doesn't exist, so we cannot activate the timezone...
[enigma2.git] / lib / python / Components / Timezones.py
1 from xml.sax import make_parser
2 from xml.sax.handler import ContentHandler
3
4 import os
5 import time
6
7 class Timezones:
8         class parseTimezones(ContentHandler):
9                 def __init__(self, timezones):
10                         self.isPointsElement, self.isReboundsElement = 0, 0
11                         self.timezones = timezones
12         
13                 def startElement(self, name, attrs):
14                         if (name == "zone"):
15                                 self.timezones.append((attrs.get('name',""), attrs.get('zone',"")))
16         
17         def __init__(self):
18                 self.timezones = []
19                 
20                 self.readTimezonesFromFile()
21
22         def readTimezonesFromFile(self):
23                 parser = make_parser()
24                 timezonesHandler = self.parseTimezones(self.timezones)
25                 parser.setContentHandler(timezonesHandler)
26                 parser.parse('/etc/timezone.xml')
27                 
28         def activateTimezone(self, index):
29                 os.environ['TZ'] = self.timezones[index][1]
30                 # FIXME we need a tzset
31                 #time.tzset()
32                 
33         def getTimezoneList(self):
34                 list = []
35                 for x in self.timezones:
36                         list.append(str(x[0]))
37                 return list
38         
39         def getDefaultTimezone(self):
40                 # TODO return something more useful - depending on country-settings?
41                 return 27
42
43 timezones = Timezones()