1 from __future__ import with_statement
6 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')
34 def __setitem__(self, *args, **kwargs):
35 s = dict.__setitem__(self, *args, **kwargs)
40 with open(defaults.cache_lines, 'w') as fp:
44 l = load(defaults.cache_lines, dict)
53 def __init__(self, line):
55 behaves as dict of directions/stations of line
56 automatically saves cache on updates
58 if Stations.stations == None:
61 self.current_line = line
62 if line in Stations.stations:
63 self.update(Stations.stations[line])
64 # FIXME maybe cause problems in the future, race conditions
65 Stations.stations[line] = self
67 def __setitem__(self, *args, **kwargs):
68 u = dict.__setitem__(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)