5 import simplejson as json
10 from __future__ import with_statement
18 with open(p, 'r') as f:
23 print 'Unexpected content in cache file'
24 print 'rebuilding cache'
25 shutil.copy(p, p + '.bak')
27 # FIXME check if empty
28 print 'Corrupt cache file'
29 print 'rebuilding cache'
30 shutil.copy(p, p + '.bak')
39 def __setitem__(self, *args, **kwargs):
40 s = dict.__setitem__(self, *args, **kwargs)
45 with open(defaults.cache_lines, 'w') as fp:
49 l = load(defaults.cache_lines, dict)
58 def __init__(self, line):
60 behaves as dict of directions/stations of line
61 automatically saves cache on updates
63 if Stations.stations == None:
66 self.current_line = line
67 if line in Stations.stations:
68 self.update(Stations.stations[line])
69 # FIXME maybe cause problems in the future, race conditions
70 Stations.stations[line] = self
72 def __setitem__(self, *args, **kwargs):
73 u = dict.__setitem__(self, *args, **kwargs)
79 with open(defaults.cache_stations, 'w') as fp:
80 json.dump(Stations.stations, fp)
84 s = load(defaults.cache_stations, dict)