Skip to content

Commit

Permalink
Fix for certain broken station names.
Browse files Browse the repository at this point in the history
Some people are using station names in a station.csv that are missing spaces.
  • Loading branch information
Oliver Smith committed Dec 13, 2014
1 parent 3b92412 commit 505f9ce
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 15 deletions.
73 changes: 58 additions & 15 deletions cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,30 @@ def __init__(self, fromFile, lineNo, keyType, keyValue, prevLineNo):
))


class DeletedKeyError(BuildCacheBaseException):
"""
Raised when a key value in a .csv file is marked as DELETED in the
corrections file.
"""
def __init__(self, fromFile, lineNo, keyType, keyValue):
super().__init__(fromFile, lineNo,
"{} '{}' is marked as DELETED and should not be used.\n".format(
keyType, keyValue
))


class DeprecatedKeyError(BuildCacheBaseException):
"""
Raised when a key value in a .csv file has a correction; the old
name should not appear in the .csv file.
"""
def __init__(self, fromFile, lineNo, keyType, keyValue, newValue):
super().__init__(fromFile, lineNo,
"{} '{}' is deprecated and should be replaced with '{}'.\n".format(
keyType, keyValue, newValue
))


class MultipleStationEntriesError(DuplicateKeyError):
""" Raised when a station appears multiple times in the same file. """
def __init__(self, fromFile, lineNo, facility, prevLineNo):
Expand Down Expand Up @@ -569,23 +593,44 @@ def processPricesFile(tdenv, db, pricesPath, defaultZero=False):

######################################################################

def deprecationCheckSystem(line, debug):
def deprecationCheckSystem(importPath, lineNo, line, debug):
correctSystem = corrections.correctSystem(line[0])
if correctSystem != line[0]:
if debug: print("! System.csv: deprecated system: {}".format(line[0]))
line[0] = correctSystem
if correctSystem == corrections.DELETED:
raise DeletedKeyError(
importPath, lineNo,
'System', line[0]
)
raise DeprecatedKeyError(
importPath, lineNo,
'System', line[0], correctSystem
)


def deprecationCheckStation(line, debug):
def deprecationCheckStation(importPath, lineNo, line, debug):
correctSystem = corrections.correctSystem(line[0])
if correctSystem != line[0]:
if debug: print("! Station.csv: deprecated system: {}".format(line[0]))
line[0] = correctSystem
if correctSystem == corrections.DELETED:
raise DeletedKeyError(
importPath, lineNo,
'System', line[0]
)
raise DeprecatedKeyError(
importPath, lineNo,
'System', line[0], correctSystem
)

correctStation = corrections.correctStation(correctSystem, line[1])
if correctStation != line[1]:
if debug: print("! Station.csv: deprecated station: {}".format(line[1]))
line[1] = correctStation
if correctStation == corrections.DELETED:
raise DeletedKeyError(
importPath, lineNo,
'Station', line[1]
)
raise DeprecatedKeyError(
importPath, lineNo,
'Station', line[0]+"/"+line[1], correctStation
)


def processImportFile(tdenv, db, importPath, tableName):
Expand Down Expand Up @@ -660,12 +705,9 @@ def processImportFile(tdenv, db, importPath, tableName):
tdenv.DEBUG0("SQL-Statement: {}", sql_stmt)

# Check if there is a deprecation check for this table.
if tdenv.debug:
deprecationFn = getattr(sys.modules[__name__],
"deprecationCheck"+tableName,
None)
else:
deprecationFn = None
deprecationFn = getattr(sys.modules[__name__],
"deprecationCheck"+tableName,
None)

# import the data
importCount = 0
Expand All @@ -675,7 +717,8 @@ def processImportFile(tdenv, db, importPath, tableName):
lineNo = csvin.line_num
if len(linein) == columnCount:
tdenv.DEBUG1(" Values: {}", ', '.join(linein))
if deprecationFn: deprecationFn(linein, tdenv.debug)
if deprecationFn:
deprecationFn(importPath, lineNo, linein, tdenv.debug)
if uniqueIndexes:
# Need to construct the actual unique index key as
# something less likely to collide with manmade
Expand Down
3 changes: 3 additions & 0 deletions corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"G 139-50/FILIPCHENKO": "Filipchenko City",
"AMARAK/WERNER VON SIEMENS VISON": "Werner Von Siemens Vision",
"SETING/COX LANDING": DELETED,
"APOYOTA/FLINTSTATION": "Flint Station",
"APOYOTA/HAHNRELAY": "Hahn Relay",
"EKONIR/MOREYVISION": "Morey Vision",

#ADD_STATIONS_HERE
}
Expand Down

0 comments on commit 505f9ce

Please sign in to comment.