This class has only one method, the .readLine() method that must be supplied in
classes derived from the BaseStationSet
class.
# - - - M a p s S t a t i o n S e t . r e a d L i n e - - -
def readLine(self, scan):
'''Process one line from the stations authority file.
'''
In general, we proceed through each field by using the
Scan.move() method. This method takes a
field length, advances the current scan position that
far, and returns the characters scanned. It raises IndexError if the line doesn't have enough
characters. See Section 6, “scanFieldList(): A utility routine
for flat-file scanning”.
#-- 1 --
# [ if the line in scan starts with a sequence of fields
# whose names and lengths are specified by
# MapsStationSet.FIELD_LIST ->
# scan := scan advanced past those fields
# fieldSet := values of those fields in the same
# order
# else ->
# Log() +:= error message
# raise IOError ]
fieldSet = scanFieldList(scan, MapsStationSet.FIELD_LIST)
We unpack fieldSet into individual variables.
Then we call the parent class's .addStation() method to take care of adding the
new codes to the file. That method can fail, for example
if there is a duplicate station code; if so, it will
raise IOError.
#-- 2 --
region, staNo, locCode, staName, staCode, state = fieldSet
It is necessary to ignore records with a staCode of zero; these represent stations whose
numbers have not yet been assigned.
Release 8.04 was a fix to this next prime: the
SHIPSTAT.DBF of 2014-07-28 had
some STA fields that were blank, not
just zero. The old logic was if not
int(staNo):.
#-- 3 --
# [ if staNo is blank or zero ->
# return
# else -> I ]
if (staNo.strip()=='') or (int(staNo)==0):
return
The .rstrip() calls below remove trailing
spaces from those fields. See Section 8.5, “BaseStationSet.addStation(): Add a
new station”.
#-- 4 --
# [ if staNo duplicates a value in self ->
# raise IOError
# else if locCode is not in self ->
# self := self with a new location added as well as
# a new station made from (region, staNo,
# staName, staCode, and state)
# else if locCode is in self ->
# self := self with a new station added, made from
# (region, staNo, staName, staCode, state) ]
self.addStation(locCode, staNo, staCode, staName.rstrip())