5 import simplejson as json
14 with open(p, 'r') as f:
19 print 'Unexpected content in cache file'
20 print 'rebuilding cache'
21 shutil.copy(p, p + '.bak')
23 # FIXME check if empty
24 print 'Corrupt cache file'
25 print 'rebuilding cache'
26 shutil.copy(p, p + '.bak')
35 def __setitem__(self, *args, **kwargs):
36 s = dict.__setitem__(self, *args, **kwargs)
41 with open(defaults.cache_lines, 'w') as fp:
45 l = load(defaults.cache_lines, dict)
54 def __init__(self, line):
56 behaves as dict of directions/stations of line
57 automatically saves cache on updates
59 if Stations.stations == None:
62 self.current_line = line
63 if line in Stations.stations:
64 self.update(Stations.stations[line])
65 # FIXME maybe cause problems in the future, race conditions
66 Stations.stations[line] = self
68 def __setitem__(self, *args, **kwargs):
69 u = dict.__setitem__(self, *args, **kwargs)
75 with open(defaults.cache_stations, 'w') as fp:
76 json.dump(Stations.stations, fp)
80 s = load(defaults.cache_stations, dict)