11 with open(p, 'r') as f:
16 print 'Unexpected content in cache file'
17 print 'rebuilding cache'
18 shutil.copy(p, p + '.bak')
20 # FIXME check if empty
21 print 'Corrupt cache file'
22 print 'rebuilding cache'
23 shutil.copy(p, p + '.bak')
32 def __setitem__(self, *args, **kwargs):
33 s = dict.__setitem__(self, *args, **kwargs)
38 with open(defaults.cache_lines, 'w') as fp:
42 l = load(defaults.cache_lines, dict)
51 def __init__(self, line):
53 behaves as dict of directions/stations of line
54 automatically saves cache on updates
56 if Stations.stations == None:
59 self.current_line = line
60 if line in Stations.stations:
61 self.update(Stations.stations[line])
62 # FIXME maybe cause problems in the future, race conditions
63 Stations.stations[line] = self
65 def __setitem__(self, *args, **kwargs):
66 u = dict.__setitem__(self, *args, **kwargs)
72 with open(defaults.cache_stations, 'w') as fp:
73 json.dump(Stations.stations, fp)
77 s = load(defaults.cache_stations, dict)