From 3950c2f3c5cb9ee66d0edd4a7df5c512b0e28a94 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sun, 12 Jun 2005 01:11:11 +0000 Subject: [PATCH] add intersection support --- CommandParser.py | 27 +++++++++++++++++++------- PlanLocation.py | 44 ++++++++++++++++++++++++++++++++++++++++++ Planner.py | 9 ++------- mailPlanner.py | 2 +- runplanner.py | 2 +- tests/test_command_parser.py | 46 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 114 insertions(+), 16 deletions(-) create mode 100644 PlanLocation.py create mode 100755 tests/test_command_parser.py diff --git a/CommandParser.py b/CommandParser.py index d65ecca..3e9a974 100644 --- a/CommandParser.py +++ b/CommandParser.py @@ -7,11 +7,12 @@ import sre import time import PlanTime +import PlanLocation class Command: def __init__(self): - self.src = None - self.dest = None + self.start = None + self.end = None self.time = None class CommandParseException(Exception): @@ -24,14 +25,14 @@ class CommandParser: self.parse(str) def parse(self, str): - # Look for src and dest at the start of the string. + # Look for start and end at the start of the string. match = _full_rx.match(str) if not match: raise CommandParseException("Failed to extract source and " "destination from command '%s'" % str); self.cmd = Command() - self.cmd.src = match.group("src") - self.cmd.dest = match.group("dest") + self.cmd.start = self.parseLocation(match.group("start")) + self.cmd.end = self.parseLocation(match.group("end")) # Now look for time constraints. rule = match.group("rule") @@ -44,6 +45,13 @@ class CommandParser: self.cmd.time \ = PlanTime.PlanTime(self.decodeTime(timestr), ruleMap[rule]) + def parseLocation(self, str): + match = _intersection_rx.match(str) + if match: + return PlanLocation.IntersectionLocation(match.group(1), + match.group(2)) + return PlanLocation.AddressLocation(str) + def decodeTime(self, str): match = _time_rx.match(str) if not match: @@ -51,11 +59,16 @@ class CommandParser: t = time.localtime() return time.mktime(t) -_full_re = ("^\s*(?P.*?)\s+to\s+(?P.*?)\s*" +_full_re = ("^\s*(?P.*?)\s+to\s+(?P.*?)\s*" # at this point the pattern either ends, or there's a timespec - "(?:$|(?Pby|at)\s+(?P