예제 #1
0
  def read(cls, file_name, context):
    # Open the file
    with open(file_name) as file:
      # Create a new file
      identification_record = IdentificationRecord.read(next(file),context)
      station_file = cls(identification_record)

      # Iterate over the file
      for string in file:
        record = StationRecord.read(string,context)
        station_file.add(record)

      # Return the file
      return station_file
예제 #2
0
파일: timezone.py 프로젝트: danae/iffgraph
    def read(cls, file_name, context):
        # Open the file
        with open(file_name) as file:
            # Create a new file
            identification_record = IdentificationRecord.read(
                next(file), context)
            timezone_file = cls(identification_record)

            # Initialize local variables
            current_timezone = None

            # Iterate over the file
            for string in file:
                # Get the record belonging to the identifier and parse it
                identifier = string[0]
                if identifier not in identifiers:
                    raise RuntimeError(
                        'Invalid record type: {}'.format(identifier))

                record = identifiers.get(identifier).read(string)

                # Switch the record
                if isinstance(record, TimezoneRecord):
                    # Check if a timezone is selected, then add it
                    if current_timezone is not None:
                        # Add the timezone to the file
                        timezone_file.add(current_timezone)

                    # Create a new timezone
                    current_timezone = record

                elif isinstance(record, EarlierPeriodRecord) or isinstance(
                        record, LaterPeriodRecord):
                    # Check if a timezone is selected
                    if current_timezone is None:
                        raise RuntimeError("No timezone is selected")

                    # Set the period
                    current_timezone.offset = record.offset
                    current_timezone.first_day = record.first_day
                    current_timezone.last_day = record.last_day

            # Append the last timezone
            if current_timezone is not None:
                # Add the timezone to the file
                timezone_file.add(current_timezone)

            # Return the file
            return timezone_file
예제 #3
0
파일: footnote.py 프로젝트: danae/iffgraph
    def read(cls, file_name, context):
        # Open the file
        with open(file_name) as file:
            # Create a new footnote file
            identification_record = IdentificationRecord.read(
                next(file), context)
            footnote_file = cls(identification_record)

            # Initialize local variables
            current_footnote = None

            # Iterate over the file
            for string in file:
                # Get the record belonging to the identifier and parse it
                identifier = string[0]
                if identifier not in identifiers:
                    record = VectorRecord.read(string, context)
                else:
                    record = identifiers.get(identifier).read(string, context)

                # Switch the record
                if isinstance(record, FootnoteRecord):
                    # Check if a footnote is selected, then add it
                    if current_footnote is not None:
                        footnote_file.add(current_footnote)

                    # Create a new footnote
                    current_footnote = record

                elif isinstance(record, VectorRecord):
                    # Check if a footnote is selected
                    if current_footnote is None:
                        raise RuntimeError("No footnote is selected")

                    # Set the vector
                    current_footnote.vector = record.vector

            # Append the last footnote
            if current_footnote is not None:
                footnote_file.add(current_footnote)

            # Return the file
            return footnote_file
예제 #4
0
파일: service.py 프로젝트: danae/iffgraph
  def read(cls, file_name, context):
    # Open the file
    with open(file_name) as file:
      # Create a new file
      identification_record = IdentificationRecord.read(next(file),context)
      timetable_file = cls(identification_record)

      # Initialize local variables
      current_service = None
      current_stop = None

      # Iterate over the file
      for string in file:
        # Get the record belonging to the identifier and parse it
        identifier = string[0]
        if identifier not in identifiers:
          raise RuntimeError('Invalid record type: {}'.format(identifier))

        record = identifiers.get(identifier).read(string,context)

        # Switch the record
        if isinstance(record,ServiceRecord):
          # Check if a service is selected, then add it
          if current_service is not None:
            timetable_file._split_services(current_service)

          # Create a new service
          current_service = record
          current_stop = None

        elif isinstance(record,ServiceNumberRecord):
          # Check if a service is selected
          if current_service is None:
            raise RuntimeError("No service is selected")

          # Append the service number
          current_service.service_numbers.append(record)

        elif isinstance(record,FootnoteRecord):
          # Check if a service is selected
          if current_service is None:
            raise RuntimeError("No service is selected")

          # Append the footnote
          current_service.footnote = record.footnote

        elif isinstance(record,TransportModeRecord):
          # Check if a service is selected
          if current_service is None:
            raise RuntimeError("No service is selected")

          # Append the transport mode
          current_service.transport_mode = record.transport_mode

        elif isinstance(record,AttributeRecord):
          # Check if a service is selected
          if current_service is None:
            raise RuntimeError("No service is selected")

          # Append the attribute
          current_service.attributes.append(record.attribute)

        elif type(record) in [StartRecord, ContinuationRecord, PassingRecord, IntervalRecord, FinalRecord]:
          # Check if a service is selected
          if current_service is None:
            raise RuntimeError("No service is selected")

          # Append the stop
          current_stop = Stop(**record.__dict__)
          current_service.stops.append(current_stop)

        elif isinstance(record,PlatformRecord):
          # Check if a stop is selected
          if current_stop is None:
            raise RuntimeError("No stop is selected")

          # Set the platforms
          current_stop.arrival_platform = record.arrival_platform_name
          current_stop.departure_platform = record.departure_platform_name

      # Add the last service
      if current_service is not None:
        timetable_file._split_services(current_service)

      # Return the file
      return timetable_file