1 from __future__ import with_statement
6 import simplejson as json
15 with open(p, 'r') as f:
20 print 'Unexpected content in cache file'
21 print 'rebuilding cache'
22 shutil.copy(p, p + '.bak')
24 # FIXME check if empty
25 print 'Corrupt cache file'
26 print 'rebuilding cache'
27 shutil.copy(p, p + '.bak')
36 def __setitem__(self, *args, **kwargs):
37 s = dict.__setitem__(self, *args, **kwargs)
42 with open(defaults.cache_lines, 'w') as fp:
46 l = load(defaults.cache_lines, dict)
55 def __init__(self, line):
57 behaves as dict of directions/stations of line
58 automatically saves cache on updates
60 if Stations.stations == None:
63 self.current_line = line
64 if line in Stations.stations:
65 self.update(Stations.stations[line])
66 # FIXME maybe cause problems in the future, race conditions
67 Stations.stations[line] = self
69 def __setitem__(self, *args, **kwargs):
70 u = dict.__setitem__(self, *args, **kwargs)
76 with open(defaults.cache_stations, 'w') as fp:
77 json.dump(Stations.stations, fp)
81 s = load(defaults.cache_stations, dict)