| LEFT | RIGHT |
|---|---|
| 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 2434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2445 yield (self.service_id, date, unicode(exception_type)) | 2445 yield (self.service_id, date, unicode(exception_type)) |
| 2446 | 2446 |
| 2447 def GetCalendarDatesFieldValuesTuples(self): | 2447 def GetCalendarDatesFieldValuesTuples(self): |
| 2448 """Return a list of date execeptions""" | 2448 """Return a list of date execeptions""" |
| 2449 result = [] | 2449 result = [] |
| 2450 for date_tuple in self.GenerateCalendarDatesFieldValuesTuples(): | 2450 for date_tuple in self.GenerateCalendarDatesFieldValuesTuples(): |
| 2451 result.append(date_tuple) | 2451 result.append(date_tuple) |
| 2452 result.sort() # helps with __eq__ | 2452 result.sort() # helps with __eq__ |
| 2453 return result | 2453 return result |
| 2454 | 2454 |
| 2455 def SetDateHasService(self, date, has_service=True, | 2455 def SetDateHasService(self, date, has_service=True, problems=None): |
| 2456 problems=None): | |
| 2457 if date in self.date_exceptions and problems: | 2456 if date in self.date_exceptions and problems: |
| 2458 problems.DuplicateID(('service_id', 'date'), | 2457 problems.DuplicateID(('service_id', 'date'), |
| 2459 (self.service_id, date), | 2458 (self.service_id, date), |
| 2460 type=TYPE_WARNING) | 2459 type=TYPE_WARNING) |
| 2461 self.date_exceptions[date] = has_service and 1 or 2 | 2460 self.date_exceptions[date] = has_service and 1 or 2 |
| 2462 | 2461 |
| 2463 def ResetDateToNormalService(self, date): | 2462 def ResetDateToNormalService(self, date): |
| 2464 if date in self.date_exceptions: | 2463 if date in self.date_exceptions: |
| 2465 del self.date_exceptions[date] | 2464 del self.date_exceptions[date] |
| 2466 | 2465 |
| (...skipping 1516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3983 self._ReadCSV(file_name, | 3982 self._ReadCSV(file_name, |
| 3984 ServicePeriod._FIELD_NAMES, | 3983 ServicePeriod._FIELD_NAMES, |
| 3985 ServicePeriod._FIELD_NAMES_REQUIRED): | 3984 ServicePeriod._FIELD_NAMES_REQUIRED): |
| 3986 context = (file_name, row_num, row, cols) | 3985 context = (file_name, row_num, row, cols) |
| 3987 self._problems.SetFileContext(*context) | 3986 self._problems.SetFileContext(*context) |
| 3988 | 3987 |
| 3989 period = ServicePeriod(field_list=row) | 3988 period = ServicePeriod(field_list=row) |
| 3990 | 3989 |
| 3991 if period.service_id in periods: | 3990 if period.service_id in periods: |
| 3992 self._problems.DuplicateID('service_id', period.service_id) | 3991 self._problems.DuplicateID('service_id', period.service_id) |
| 3993 continue | 3992 else: |
|
Tom
2009/10/26 19:34:20
else:
periods[period.service_id] = (period, cont
jirka
2009/10/26 22:18:13
On 2009/10/26 19:34:20, Tom wrote:
> else:
> per
| |
| 3994 | 3993 periods[period.service_id] = (period, context) |
| 3995 periods[period.service_id] = (period, context) | 3994 self._problems.ClearContext() |
| 3996 | 3995 |
| 3997 # process calendar_dates.txt | 3996 # process calendar_dates.txt |
| 3998 if self._HasFile(file_name_dates): | 3997 if self._HasFile(file_name_dates): |
| 3999 # ['service_id', 'date', 'exception_type'] | 3998 # ['service_id', 'date', 'exception_type'] |
| 4000 fields = ServicePeriod._FIELD_NAMES_CALENDAR_DATES | 3999 fields = ServicePeriod._FIELD_NAMES_CALENDAR_DATES |
| 4001 for (row, row_num, cols) in self._ReadCSV(file_name_dates, | 4000 for (row, row_num, cols) in self._ReadCSV(file_name_dates, |
| 4002 fields, fields): | 4001 fields, fields): |
| 4003 context = (file_name_dates, row_num, row, cols) | 4002 context = (file_name_dates, row_num, row, cols) |
| 4004 self._problems.SetFileContext(*context) | 4003 self._problems.SetFileContext(*context) |
| 4005 | 4004 |
| 4006 service_id = row[0] | 4005 service_id = row[0] |
| 4007 | 4006 |
| 4008 period = None | 4007 period = None |
| 4009 if service_id in periods: | 4008 if service_id in periods: |
| 4010 period = periods[service_id][0] | 4009 period = periods[service_id][0] |
| 4011 else: | 4010 else: |
| 4012 period = ServicePeriod(service_id) | 4011 period = ServicePeriod(service_id) |
| 4013 periods[period.service_id] = (period, context) | 4012 periods[period.service_id] = (period, context) |
| 4014 | 4013 |
| 4015 exception_type = row[2] | 4014 exception_type = row[2] |
| 4016 if exception_type == u'1': | 4015 if exception_type == u'1': |
| 4017 period.SetDateHasService(row[1], True, self._problems) | 4016 period.SetDateHasService(row[1], True, self._problems) |
| 4018 elif exception_type == u'2': | 4017 elif exception_type == u'2': |
| 4019 period.SetDateHasService(row[1], False, self._problems) | 4018 period.SetDateHasService(row[1], False, self._problems) |
| 4020 else: | 4019 else: |
| 4021 self._problems.InvalidValue('exception_type', exception_type) | 4020 self._problems.InvalidValue('exception_type', exception_type) |
| 4021 self._problems.ClearContext() | |
| 4022 | 4022 |
|
Tom
2009/10/26 19:34:20
self._problems.ClearContext()
jirka
2009/10/26 22:18:13
On 2009/10/26 19:34:20, Tom wrote:
> self._problem
| |
| 4023 # 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 |
| 4024 # validated with both calendar and calendar_dates info present | 4024 # validated with both calendar and calendar_dates info present |
| 4025 for period, context in periods.values(): | 4025 for period, context in periods.values(): |
| 4026 self._problems.SetFileContext(*context) | 4026 self._problems.SetFileContext(*context) |
| 4027 self._schedule.AddServicePeriodObject(period, self._problems) | 4027 self._schedule.AddServicePeriodObject(period, self._problems) |
| 4028 self._problems.ClearContext() | 4028 self._problems.ClearContext() |
| 4029 | 4029 |
| 4030 def _LoadShapes(self): | 4030 def _LoadShapes(self): |
| 4031 if not self._HasFile('shapes.txt'): | 4031 if not self._HasFile('shapes.txt'): |
| 4032 return | 4032 return |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4233 def __init__(self, *args, **kwargs): | 4233 def __init__(self, *args, **kwargs): |
| 4234 """Initialize a new ShapeLoader object. | 4234 """Initialize a new ShapeLoader object. |
| 4235 | 4235 |
| 4236 See Loader.__init__ for argument documentation. | 4236 See Loader.__init__ for argument documentation. |
| 4237 """ | 4237 """ |
| 4238 Loader.__init__(self, *args, **kwargs) | 4238 Loader.__init__(self, *args, **kwargs) |
| 4239 | 4239 |
| 4240 def Load(self): | 4240 def Load(self): |
| 4241 self._LoadShapes() | 4241 self._LoadShapes() |
| 4242 return self._schedule | 4242 return self._schedule |
| LEFT | RIGHT |