| OLD | NEW |
| 1 #!/usr/bin/python2.5 | 1 #!/usr/bin/python2.5 |
| 2 | 2 |
| 3 # Copyright (C) 2007 Google Inc. | 3 # Copyright (C) 2007 Google Inc. |
| 4 # | 4 # |
| 5 # Licensed under the Apache License, Version 2.0 (the "License"); | 5 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 # you may not use this file except in compliance with the License. | 6 # you may not use this file except in compliance with the License. |
| 7 # You may obtain a copy of the License at | 7 # You may obtain a copy of the License at |
| 8 # | 8 # |
| 9 # http://www.apache.org/licenses/LICENSE-2.0 | 9 # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 # | 10 # |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 e = MissingValue(column_name=column_name, reason=reason, context=context, | 164 e = MissingValue(column_name=column_name, reason=reason, context=context, |
| 165 context2=self._context) | 165 context2=self._context) |
| 166 self._Report(e) | 166 self._Report(e) |
| 167 | 167 |
| 168 def InvalidValue(self, column_name, value, reason=None, context=None, | 168 def InvalidValue(self, column_name, value, reason=None, context=None, |
| 169 type=TYPE_ERROR): | 169 type=TYPE_ERROR): |
| 170 e = InvalidValue(column_name=column_name, value=value, reason=reason, | 170 e = InvalidValue(column_name=column_name, value=value, reason=reason, |
| 171 context=context, context2=self._context, type=type) | 171 context=context, context2=self._context, type=type) |
| 172 self._Report(e) | 172 self._Report(e) |
| 173 | 173 |
| 174 def DuplicateID(self, column_name, value, context=None): | 174 def DuplicateID(self, column_names, values, context=None, type=TYPE_ERROR): |
| 175 e = DuplicateID(column_name=column_name, value=value, | 175 if isinstance(column_names, tuple): |
| 176 context=context, context2=self._context) | 176 column_names = '(' + ', '.join(column_names) + ')' |
| 177 if isinstance(values, tuple): |
| 178 values = '(' + ', '.join(values) + ')' |
| 179 e = DuplicateID(column_name=column_names, value=values, |
| 180 context=context, context2=self._context, type=type) |
| 177 self._Report(e) | 181 self._Report(e) |
| 178 | 182 |
| 179 def UnusedStop(self, stop_id, stop_name, context=None): | 183 def UnusedStop(self, stop_id, stop_name, context=None): |
| 180 e = UnusedStop(stop_id=stop_id, stop_name=stop_name, | 184 e = UnusedStop(stop_id=stop_id, stop_name=stop_name, |
| 181 context=context, context2=self._context, type=TYPE_WARNING) | 185 context=context, context2=self._context, type=TYPE_WARNING) |
| 182 self._Report(e) | 186 self._Report(e) |
| 183 | 187 |
| 184 def UsedStation(self, stop_id, stop_name, context=None): | 188 def UsedStation(self, stop_id, stop_name, context=None): |
| 185 e = UsedStation(stop_id=stop_id, stop_name=stop_name, | 189 e = UsedStation(stop_id=stop_id, stop_name=stop_name, |
| 186 context=context, context2=self._context, type=TYPE_ERROR) | 190 context=context, context2=self._context, type=TYPE_ERROR) |
| (...skipping 2254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2441 yield (self.service_id, date, unicode(exception_type)) | 2445 yield (self.service_id, date, unicode(exception_type)) |
| 2442 | 2446 |
| 2443 def GetCalendarDatesFieldValuesTuples(self): | 2447 def GetCalendarDatesFieldValuesTuples(self): |
| 2444 """Return a list of date execeptions""" | 2448 """Return a list of date execeptions""" |
| 2445 result = [] | 2449 result = [] |
| 2446 for date_tuple in self.GenerateCalendarDatesFieldValuesTuples(): | 2450 for date_tuple in self.GenerateCalendarDatesFieldValuesTuples(): |
| 2447 result.append(date_tuple) | 2451 result.append(date_tuple) |
| 2448 result.sort() # helps with __eq__ | 2452 result.sort() # helps with __eq__ |
| 2449 return result | 2453 return result |
| 2450 | 2454 |
| 2451 def SetDateHasService(self, date, has_service=True): | 2455 def SetDateHasService(self, date, has_service=True, problems=None): |
| 2456 if date in self.date_exceptions and problems: |
| 2457 problems.DuplicateID(('service_id', 'date'), |
| 2458 (self.service_id, date), |
| 2459 type=TYPE_WARNING) |
| 2452 self.date_exceptions[date] = has_service and 1 or 2 | 2460 self.date_exceptions[date] = has_service and 1 or 2 |
| 2453 | 2461 |
| 2454 def ResetDateToNormalService(self, date): | 2462 def ResetDateToNormalService(self, date): |
| 2455 if date in self.date_exceptions: | 2463 if date in self.date_exceptions: |
| 2456 del self.date_exceptions[date] | 2464 del self.date_exceptions[date] |
| 2457 | 2465 |
| 2458 def SetStartDate(self, start_date): | 2466 def SetStartDate(self, start_date): |
| 2459 """Set the first day of service as a string in YYYYMMDD format""" | 2467 """Set the first day of service as a string in YYYYMMDD format""" |
| 2460 self.start_date = start_date | 2468 self.start_date = start_date |
| 2461 | 2469 |
| (...skipping 1506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3968 periods = {} | 3976 periods = {} |
| 3969 | 3977 |
| 3970 # process calendar.txt | 3978 # process calendar.txt |
| 3971 if self._HasFile(file_name): | 3979 if self._HasFile(file_name): |
| 3972 has_useful_contents = False | 3980 has_useful_contents = False |
| 3973 for (row, row_num, cols) in \ | 3981 for (row, row_num, cols) in \ |
| 3974 self._ReadCSV(file_name, | 3982 self._ReadCSV(file_name, |
| 3975 ServicePeriod._FIELD_NAMES, | 3983 ServicePeriod._FIELD_NAMES, |
| 3976 ServicePeriod._FIELD_NAMES_REQUIRED): | 3984 ServicePeriod._FIELD_NAMES_REQUIRED): |
| 3977 context = (file_name, row_num, row, cols) | 3985 context = (file_name, row_num, row, cols) |
| 3986 self._problems.SetFileContext(*context) |
| 3978 | 3987 |
| 3979 period = ServicePeriod(field_list=row) | 3988 period = ServicePeriod(field_list=row) |
| 3980 | 3989 |
| 3981 if period.service_id in periods: | 3990 if period.service_id in periods: |
| 3982 self._problems.DuplicateID('service_id', period.service_id) | 3991 self._problems.DuplicateID('service_id', period.service_id) |
| 3983 continue | 3992 else: |
| 3984 | 3993 periods[period.service_id] = (period, context) |
| 3985 periods[period.service_id] = (period, context) | 3994 self._problems.ClearContext() |
| 3986 | 3995 |
| 3987 # process calendar_dates.txt | 3996 # process calendar_dates.txt |
| 3988 if self._HasFile(file_name_dates): | 3997 if self._HasFile(file_name_dates): |
| 3989 # ['service_id', 'date', 'exception_type'] | 3998 # ['service_id', 'date', 'exception_type'] |
| 3990 fields = ServicePeriod._FIELD_NAMES_CALENDAR_DATES | 3999 fields = ServicePeriod._FIELD_NAMES_CALENDAR_DATES |
| 3991 for (row, row_num, cols) in self._ReadCSV(file_name_dates, | 4000 for (row, row_num, cols) in self._ReadCSV(file_name_dates, |
| 3992 fields, fields): | 4001 fields, fields): |
| 3993 context = (file_name_dates, row_num, row, cols) | 4002 context = (file_name_dates, row_num, row, cols) |
| 4003 self._problems.SetFileContext(*context) |
| 3994 | 4004 |
| 3995 service_id = row[0] | 4005 service_id = row[0] |
| 3996 | 4006 |
| 3997 period = None | 4007 period = None |
| 3998 if service_id in periods: | 4008 if service_id in periods: |
| 3999 period = periods[service_id][0] | 4009 period = periods[service_id][0] |
| 4000 else: | 4010 else: |
| 4001 period = ServicePeriod(service_id) | 4011 period = ServicePeriod(service_id) |
| 4002 periods[period.service_id] = (period, context) | 4012 periods[period.service_id] = (period, context) |
| 4003 | 4013 |
| 4004 exception_type = row[2] | 4014 exception_type = row[2] |
| 4005 if exception_type == u'1': | 4015 if exception_type == u'1': |
| 4006 period.SetDateHasService(row[1], True) | 4016 period.SetDateHasService(row[1], True, self._problems) |
| 4007 elif exception_type == u'2': | 4017 elif exception_type == u'2': |
| 4008 period.SetDateHasService(row[1], False) | 4018 period.SetDateHasService(row[1], False, self._problems) |
| 4009 else: | 4019 else: |
| 4010 self._problems.InvalidValue('exception_type', exception_type) | 4020 self._problems.InvalidValue('exception_type', exception_type) |
| 4021 self._problems.ClearContext() |
| 4011 | 4022 |
| 4012 # Now insert the periods into the schedule object, so that they're | 4023 # Now insert the periods into the schedule object, so that they're |
| 4013 # validated with both calendar and calendar_dates info present | 4024 # validated with both calendar and calendar_dates info present |
| 4014 for period, context in periods.values(): | 4025 for period, context in periods.values(): |
| 4015 self._problems.SetFileContext(*context) | 4026 self._problems.SetFileContext(*context) |
| 4016 self._schedule.AddServicePeriodObject(period, self._problems) | 4027 self._schedule.AddServicePeriodObject(period, self._problems) |
| 4017 self._problems.ClearContext() | 4028 self._problems.ClearContext() |
| 4018 | 4029 |
| 4019 def _LoadShapes(self): | 4030 def _LoadShapes(self): |
| 4020 if not self._HasFile('shapes.txt'): | 4031 if not self._HasFile('shapes.txt'): |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4222 def __init__(self, *args, **kwargs): | 4233 def __init__(self, *args, **kwargs): |
| 4223 """Initialize a new ShapeLoader object. | 4234 """Initialize a new ShapeLoader object. |
| 4224 | 4235 |
| 4225 See Loader.__init__ for argument documentation. | 4236 See Loader.__init__ for argument documentation. |
| 4226 """ | 4237 """ |
| 4227 Loader.__init__(self, *args, **kwargs) | 4238 Loader.__init__(self, *args, **kwargs) |
| 4228 | 4239 |
| 4229 def Load(self): | 4240 def Load(self): |
| 4230 self._LoadShapes() | 4241 self._LoadShapes() |
| 4231 return self._schedule | 4242 return self._schedule |
| OLD | NEW |