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 update(self, *args, **kwargs):
33 a = dict.update(self, *args, **kwargs)
38 with open(defaults.cache_lines, 'w') as fp:
42 l = load(defaults.cache_lines, dict)
52 def __init__(self, line):
54 behaves as dict of directions/stations of line
55 automatically saves cache on updates
57 if Stations.stations == None:
60 self.current_line = line
61 if line in Stations.stations:
62 self.update(Stations.stations[line])
63 # FIXME maybe cause problems in the future, race conditions
64 Stations.stations[line] = self
66 def update(self, *args, **kwargs):
67 u = dict.update(self, *args, **kwargs)
74 with open(defaults.cache_stations, 'w') as fp:
75 json.dump(Stations.stations, fp)
79 s = load(defaults.cache_stations, dict)