9 if path.exists(path, typ):
11 with open(path, 'r') as f:
16 print 'Unexpected content in cache file'
17 print 'rebuilding cache'
18 shutil.copy(path, path + '.bak')
20 print 'Corrupt cache file'
21 print 'rebuilding cache'
22 shutil.copy(path, path + '.bak')
27 def __init__(self, lines=[]):
28 l = load(defaults.cache_line)
29 if l and type(l) == list:
34 for line in self.lines:
38 def __iadd__(self, y):
44 def __getitem__(self, y):
48 return len(self.lines)
51 return str(self.lines)
53 def __setitem__(self, i, y):
59 def __init__(self, line=False):
61 if line=False behaves as dict of all lines/stations
62 if line behaves as dict of directions/stations of line
64 if not Stations.stations:
65 s = load(defaults.cache_line, dict)
67 Stations.stations = st
69 self.current_line = line
71 self.dict = Stations.stations
72 elif line in Stations.stations:
73 self.dict = Stations.stations[line]
75 Stations.stations[line] = {}
76 self.dict = Stations.stations[line]
79 def __getitem__(self, *args, **kwargs):
80 return self.dict.__getitem__(self, *args, **kwargs)