imip-agent

Change of imiptools/handlers/scheduling/__init__.py

1031:fc1efc973849
imiptools/handlers/scheduling/__init__.py
     1.1 --- a/imiptools/handlers/scheduling/__init__.py	Sat Jan 30 17:24:39 2016 +0100
     1.2 +++ b/imiptools/handlers/scheduling/__init__.py	Sun Jan 31 00:45:26 2016 +0100
     1.3 @@ -19,7 +19,9 @@
     1.4  this program.  If not, see <http://www.gnu.org/licenses/>.
     1.5  """
     1.6  
     1.7 +from imiptools.text import parse_line
     1.8  from imiptools.handlers.scheduling.manifest import scheduling_functions
     1.9 +import re
    1.10  
    1.11  def apply_scheduling_functions(functions, handler):
    1.12  
    1.13 @@ -28,9 +30,13 @@
    1.14      'handler'.
    1.15      """
    1.16  
    1.17 +    # Obtain the actual scheduling functions with arguments.
    1.18 +
    1.19 +    functions = get_scheduling_function_calls(functions)
    1.20 +
    1.21      response = "ACCEPTED"
    1.22  
    1.23 -    for fn in functions:
    1.24 +    for fn, args in functions:
    1.25  
    1.26          # NOTE: Should signal an error for incorrectly configured resources.
    1.27  
    1.28 @@ -41,7 +47,7 @@
    1.29          # declines or gives a null response.
    1.30  
    1.31          else:
    1.32 -            result = fn(handler)
    1.33 +            result = fn(handler, args)
    1.34  
    1.35              # Return a negative result immediately.
    1.36  
    1.37 @@ -56,4 +62,24 @@
    1.38  
    1.39      return response
    1.40  
    1.41 +def get_scheduling_function_calls(lines):
    1.42 +
    1.43 +    """
    1.44 +    Parse the given 'lines', returning a list of (function, arguments) tuples,
    1.45 +    with each function being a genuine function object and with the arguments
    1.46 +    being a list of strings.
    1.47 +
    1.48 +    Each of the 'lines' should employ the function name and argument strings
    1.49 +    separated by whitespace, with any whitespace inside arguments quoted using
    1.50 +    single or double quotes.
    1.51 +    """
    1.52 +
    1.53 +    functions = []
    1.54 +
    1.55 +    for line in lines:
    1.56 +        parts = parse_line(line)
    1.57 +        functions.append((scheduling_functions.get(parts[0]), parts[1:]))
    1.58 +
    1.59 +    return functions
    1.60 +
    1.61  # vim: tabstop=4 expandtab shiftwidth=4