invent proper signalPowerdB enums and use them
[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                 
25                 try:
26                         timezonesHandler = self.parseTimezones(self.timezones)
27                         parser.setContentHandler(timezonesHandler)
28                         parser.parse('/etc/timezone.xml')
29                 except:
30                         pass
31                 
32                 if len(self.timezones) == 0:
33                         self.timezones = [("UTC", "UTC")]
34                 
35         def activateTimezone(self, index):
36                 if len(self.timezones) <= index:
37                         return
38                 
39                 os.environ['TZ'] = self.timezones[index][1]
40                 try:
41                         time.tzset()
42                 except:
43                         from enigma import e_tzset
44                         e_tzset()
45                 
46         def getTimezoneList(self):
47                 list = []
48                 for x in self.timezones:
49                         list.append(str(x[0]))
50                 return list
51         
52         def getDefaultTimezone(self):
53                 # TODO return something more useful - depending on country-settings?
54                 t = "(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Vienna"
55                 for (a,b) in self.timezones:
56                         if a == t:
57                                 return a
58                 return self.timezones[0][0]
59
60 timezones = Timezones()