1 from xml.sax import make_parser
2 from xml.sax.handler import ContentHandler
10 class parseTimezones(ContentHandler):
11 def __init__(self, timezones):
12 self.isPointsElement, self.isReboundsElement = 0, 0
13 self.timezones = timezones
15 def startElement(self, name, attrs):
17 self.timezones.append((attrs.get('name',""), attrs.get('zone',"")))
22 self.readTimezonesFromFile()
24 def readTimezonesFromFile(self):
25 parser = make_parser()
28 timezonesHandler = self.parseTimezones(self.timezones)
29 parser.setContentHandler(timezonesHandler)
30 parser.parse('/etc/timezone.xml')
34 if len(self.timezones) == 0:
35 self.timezones = [("UTC", "UTC")]
37 def activateTimezone(self, index):
38 if len(self.timezones) <= index:
41 os.environ['TZ'] = self.timezones[index][1]
47 def getTimezoneList(self):
49 for x in self.timezones:
50 list.append(str(x[0]))
53 def getDefaultTimezone(self):
54 # TODO return something more useful - depending on country-settings?
55 return "(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Vienna"
57 timezones = Timezones()