replaced get_departures with DataModel in pyside
[pywienerlinien] / gotovienna / config.py
1 from os import path
2 try:
3     import json
4 except ImportError:
5     import simplejson as json
6
7 class JsonConfig:
8     def __init__(self):
9         self.configfile = path.expanduser('~/.gotovienna/config.json')
10         self.conf = {}
11         if path.exists(self.configfile):
12             with open(self.configfile, 'r') as f:
13                 try:
14                     self.conf = json.load(f)
15                 except ValueError:
16                     print "Corrupt config"
17
18     def save(self):
19         with open(self.configfile, 'w') as f:
20             json.dump(self.conf, f)
21
22     def getGpsEnabled(self):
23         if self.conf.has_key('gps_enabled'):
24             return self.conf['gps_enabled']
25         return True
26
27     def setGpsEnabled(self, value):
28         self.conf['gps_enabled'] = value
29         self.save()
30
31     def getLastStationsUpdate(self):
32         if self.conf.has_key('last_stations_update'):
33             return self.conf['last_stations_update']
34         return 'Unknown'
35
36     def setLastStationsUpdate(self, date):
37         self.conf['last_stations_update'] = date
38         self.save()
39
40 config = JsonConfig()