Skip to content

Commit

Permalink
Revert "Removed backwards compatibility support for old .prices forma…
Browse files Browse the repository at this point in the history
…t, they were slowing down processing"

This reverts commit 657872d.
  • Loading branch information
kfsone committed Nov 16, 2014
1 parent 8fb2c0b commit ad41e04
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions buildcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
######################################################################
# Regular expression patterns. Here be draegons.
# If you add new patterns:
# - use fragments and re.VERBOSE
# - use fragments and re.VERBOSE (see itemPriceRe)
# - use named captures (?P<name> ...)
# - include comments

Expand Down Expand Up @@ -66,6 +66,26 @@
# 'now'
timeFrag = r'(?P<time>(\d{4}-\d{2}-\d{2}[T ])?\d{2}:\d{2}:\d{2}|now)'

# pre-4.6.0 extended format
# <item name> <sell_to> <buy_from> [ <time> [ demand <units>L<level> stock <units>L<level> ] ]
itemPriceRe = re.compile(r"""
^
# name, prices
{base_f}
# extended section with time and possibly demand+stock info
(?:
\s+
{time_f}
# optional demand/stock after time
(?:
\s+ demand \s+ (?P<demand> -?\d+L-?\d+ | n/a | -L-)
\s+ stock \s+ (?P<stock> -?\d+L-?\d+ | n/a | -L-)
)?
)?
\s*
$
""".format(base_f=itemPriceFrag, time_f=timeFrag), re.IGNORECASE + re.VERBOSE)

# new format:
# <name> <sell> <buy> [ <demand> <stock> [ <time> | now ] ]
qtyLevelFrag = r"""
Expand All @@ -77,7 +97,7 @@
| 0 # alias for n/a
| bug
"""
itemPriceRe = re.compile(r"""
newItemPriceRe = re.compile(r"""
^
{base_f}
\s+
Expand Down Expand Up @@ -201,16 +221,19 @@ class Supply(object):
'm': 2, 'M': 2, '2': 2,
'h': 3, 'H': 3, '3': 3,
}
# Split a <units>L<level> reading
splitLRe = re.compile(r'^(\d+)L(-?\d+)$', re.IGNORECASE)
# Split a <units><level> reading
splitAtRe = re.compile(r'^(\d+)([\?LMH])$', re.IGNORECASE)

def parseSupply(pricesFile, lineNo, category, reading):
if reading == "?":
if reading in ("?", "unk", "UNK", "-1L-1", "-1L0", "0L-1"):
return (-1, -1)
elif reading == "-":
elif reading in ("-", "0", "-L-", "n/a", "N/A"):
return (0, 0)
else:
matches = Supply.splitAtRe.match(reading)
matches = Supply.splitAtRe.match(reading) or \
Supply.splitLRe.match(reading)
if not matches:
raise SupplyError(
pricesFile, lineNo, category,
Expand Down Expand Up @@ -494,10 +517,12 @@ def processItemLine(matches):

########################################
### "Item sell buy ..." lines.
matches = itemPriceRe.match(text)
matches = newItemPriceRe.match(text)
if not matches:
raise SyntaxError(priceFile, lineNo,
"Unrecognized line/syntax", text)
matches = itemPriceRe.match(text)
if not matches:
raise SyntaxError(priceFile, lineNo,
"Unrecognized line/syntax", text)

sql = processItemLine(matches)
if sql:
Expand Down

0 comments on commit ad41e04

Please sign in to comment.