1.1 --- a/imiptools/handlers/scheduling/__init__.py Sun Feb 07 23:35:20 2016 +0100
1.2 +++ b/imiptools/handlers/scheduling/__init__.py Mon Feb 08 00:14:53 2016 +0100
1.3 @@ -20,8 +20,11 @@
1.4 """
1.5
1.6 from imiptools.text import parse_line
1.7 -from imiptools.handlers.scheduling.manifest import scheduling_functions
1.8 -import re
1.9 +from imiptools.handlers.scheduling.manifest import confirmation_functions, \
1.10 + retraction_functions, \
1.11 + scheduling_functions
1.12 +
1.13 +# Function application/invocation.
1.14
1.15 def apply_scheduling_functions(functions, handler):
1.16
1.17 @@ -32,7 +35,7 @@
1.18
1.19 # Obtain the actual scheduling functions with arguments.
1.20
1.21 - functions = get_scheduling_function_calls(functions)
1.22 + functions = get_function_calls(functions, scheduling_functions)
1.23
1.24 response = "ACCEPTED"
1.25
1.26 @@ -62,7 +65,49 @@
1.27
1.28 return response
1.29
1.30 -def get_scheduling_function_calls(lines):
1.31 +def confirm_scheduling(functions, handler):
1.32 +
1.33 + """
1.34 + Confirm scheduling using the given listener 'functions' for the current
1.35 + object of the given 'handler'.
1.36 + """
1.37 +
1.38 + # Obtain the actual listener functions with arguments.
1.39 +
1.40 + functions = get_function_calls(functions, confirmation_functions)
1.41 + apply_functions(functions, handler)
1.42 +
1.43 +def retract_scheduling(functions, handler):
1.44 +
1.45 + """
1.46 + Retract scheduling using the given listener 'functions' for the current
1.47 + object of the given 'handler'.
1.48 + """
1.49 +
1.50 + # Obtain the actual listener functions with arguments.
1.51 +
1.52 + functions = get_function_calls(functions, retraction_functions)
1.53 + apply_functions(functions, handler)
1.54 +
1.55 +def apply_functions(functions, handler):
1.56 +
1.57 + """
1.58 + Apply the given notification 'functions' for the current object of the given
1.59 + 'handler'.
1.60 + """
1.61 +
1.62 + for fn, args in functions:
1.63 +
1.64 + # NOTE: Should signal an error for incorrectly configured resources.
1.65 +
1.66 + if not fn:
1.67 + continue
1.68 +
1.69 + fn(handler, args)
1.70 +
1.71 +# Function lookup.
1.72 +
1.73 +def get_function_calls(lines, registry):
1.74
1.75 """
1.76 Parse the given 'lines', returning a list of (function, arguments) tuples,
1.77 @@ -72,13 +117,16 @@
1.78 Each of the 'lines' should employ the function name and argument strings
1.79 separated by whitespace, with any whitespace inside arguments quoted using
1.80 single or double quotes.
1.81 +
1.82 + The given 'registry' indicates the mapping from function names to actual
1.83 + functions.
1.84 """
1.85
1.86 functions = []
1.87
1.88 for line in lines:
1.89 parts = parse_line(line)
1.90 - functions.append((scheduling_functions.get(parts[0]), parts[1:]))
1.91 + functions.append((registry.get(parts[0]), parts[1:]))
1.92
1.93 return functions
1.94