This method examines the name of the input file and verifies
that it conforms to the batch file naming scheme. Assuming
that it does, it stores away the year in
self.year, and sets either
self.station, depending on whether the
name starts with a digit or not (digit implies station
number). It sets the other attribute to
so that for example if the file name is
self.station is set to the
Station object for station 16205 and
self.location is set to none. Conversely, a file
yose-2007-5 would cause
self.location to be set to the
Location object for Yosemite, while
be set to
# - - - B a s e C o m p i l e r . p a r s e F i l e N a m e - - - def parseFileName(self): '''Process the name of a batch file. [ if self.fileName conforms to the batch file naming scheme and represents a multi-station location in self.stationSet -> self.location := a Location object representing that location self.station := None self.year := year from self.fileName else if self.fileName conforms to the batch file naming scheme and represents a single-station location in self.stationSet -> self.location := None self.station := a Station object representing that station self.year := year from self.fileName else -> Log() +:= error message(s) raise ValueError ] '''
We'll use the compiled regular expressions
STA_NO_PAT to check
to see if the file name starts with either a location code or
a station number.
#-- 1 -- self.location = self.station = None
#-- 2 - # [ if self.fileName starts with a string that matches # LOCATION_PAT and is a location code defined in # self.stationSet -> # rest := fileName past that string # self.location := the Location with that location code # from self.stationSet # else if self.fileName starts with a string that matches # STA_NO_PAT and is a station number in self.stationSet -> # rest := fileName past that string # self.station := the Station with that station number # from self.stationSet # else -> # Log() +:= error message # raise ValueError ] rest = self.parseFileLocality()
A hyphen must separate the location or station code and the batch's four-digit year.
#-- 3 -- # [ if rest starts with "-" -> # rest := rest without its first character # else -> # Log() +:= error message # raise ValueError ] if ((len(rest) == 0) or (rest != '-')): message = ("A hyphen must follow the location or station " "of the file name.") Log().message(message) raise ValueError, message else: rest = rest[1:]
The four-digit year must be next. We ignore any part of the file name past the year.
#-- 4 -- # [ if rest starts with YYYY_PAT -> # self.year := the part that matched YYYY_PAT # else -> # Log() +:= error message # raise ValueError ] m = YYYY_PAT.match(rest) if m is None: message = ("A four-digit year must follow the hyphen " "after the location or station code.") Log().error(message) raise ValueError, message else: self.year = m.group()