1.1 --- a/docs/preferences.txt Fri Jan 29 16:44:32 2016 +0100
1.2 +++ b/docs/preferences.txt Fri Jan 29 17:02:06 2016 +0100
1.3 @@ -202,9 +202,12 @@
1.4 Default: schedule_in_freebusy
1.5 Alternatives: (see below)
1.6
1.7 -Indicates the scheduling function used by resources to find an appropriate
1.8 -period for an event. The imiptools.handlers.scheduling module contains the
1.9 -built-in scheduling functions which include the following:
1.10 +Indicates the scheduling functions used by resources to find an appropriate
1.11 +period for an event, with each function to be applied to a scheduling request
1.12 +appearing on a separate line.
1.13 +
1.14 +The imiptools.handlers.scheduling module contains the built-in scheduling
1.15 +functions which include the following:
1.16
1.17 schedule_in_freebusy accept an invitation if the event periods are free
1.18 according to the free/busy records for the resource;
2.1 --- a/docs/wiki/FuturePlans Fri Jan 29 16:44:32 2016 +0100
2.2 +++ b/docs/wiki/FuturePlans Fri Jan 29 17:02:06 2016 +0100
2.3 @@ -67,24 +67,6 @@
2.4 accounting for resources, although this is beyond the scope of imip-agent
2.5 itself.
2.6
2.7 -=== Combining Scheduling Functions ===
2.8 -
2.9 -Extend the resource scheduling support to provide chains of scheduling
2.10 -functions, as opposed to a single function. Thus, different activities could
2.11 -be combined. For example, to suggest alternative periods whilst enforcing
2.12 -booking quotas, there would be two functions indicated in the
2.13 -`scheduling_function` setting for a resource:
2.14 -
2.15 -{{{
2.16 -schedule_next_available_in_freebusy
2.17 -enforce_quota
2.18 -}}}
2.19 -
2.20 -Each function would consider the current state of the event, and the chain
2.21 -would be terminated if a function decided to decline the participation of
2.22 -the resource. Otherwise, each function in turn would be able to refine the
2.23 -event and decide upon the resource's participation.
2.24 -
2.25 == Other Ideas ==
2.26
2.27 Some more ideas that would be worth pursuing...
3.1 --- a/docs/wiki/Preferences Fri Jan 29 16:44:32 2016 +0100
3.2 +++ b/docs/wiki/Preferences Fri Jan 29 17:02:06 2016 +0100
3.3 @@ -229,9 +229,12 @@
3.4 Default:: `schedule_in_freebusy`
3.5 Alternatives:: (see below)
3.6
3.7 -Indicates the scheduling function used by resources to find an appropriate
3.8 -period for an event. The `imiptools.handlers.scheduling` module contains the
3.9 -built-in scheduling functions which include the following:
3.10 +Indicates the scheduling functions used by resources to find an appropriate
3.11 +period for an event, with each function to be applied to a scheduling request
3.12 +appearing on a separate line.
3.13 +
3.14 +The imiptools.handlers.scheduling module contains the built-in scheduling
3.15 +functions which include the following:
3.16
3.17 {{{#!table
3.18 `schedule_in_freebusy` || accept an invitation if the event periods are free
4.1 --- a/imiptools/handlers/resource.py Fri Jan 29 16:44:32 2016 +0100
4.2 +++ b/imiptools/handlers/resource.py Fri Jan 29 17:02:06 2016 +0100
4.3 @@ -3,7 +3,7 @@
4.4 """
4.5 Handlers for a resource.
4.6
4.7 -Copyright (C) 2014, 2015 Paul Boddie <paul@boddie.org.uk>
4.8 +Copyright (C) 2014, 2015, 2016 Paul Boddie <paul@boddie.org.uk>
4.9
4.10 This program is free software; you can redistribute it and/or modify it under
4.11 the terms of the GNU General Public License as published by the Free Software
4.12 @@ -22,7 +22,8 @@
4.13 from imiptools.data import get_address, to_part, uri_dict
4.14 from imiptools.handlers import Handler
4.15 from imiptools.handlers.common import CommonFreebusy, CommonEvent
4.16 -from imiptools.handlers.scheduling import scheduling_functions
4.17 +from imiptools.handlers.scheduling import apply_scheduling_functions, \
4.18 + scheduling_functions
4.19
4.20 class ResourceHandler(CommonEvent, Handler):
4.21
4.22 @@ -162,15 +163,16 @@
4.23 invalid requests.
4.24 """
4.25
4.26 - scheduling_function = self.get_preferences().get("scheduling_function", "schedule_in_freebusy")
4.27 - fn = scheduling_functions.get(scheduling_function)
4.28 + # Obtain a list of scheduling functions.
4.29
4.30 - # NOTE: Should signal an error for incorrectly configured resources.
4.31 + functions = self.get_preferences().get("scheduling_function",
4.32 + "schedule_in_freebusy").split("\n")
4.33
4.34 - if not fn:
4.35 - return "DECLINED"
4.36 - else:
4.37 - return fn(self)
4.38 + # Obtain the actual scheduling functions.
4.39 +
4.40 + functions = map(scheduling_functions.get, functions)
4.41 +
4.42 + return apply_scheduling_functions(functions, self)
4.43
4.44 class Event(ResourceHandler):
4.45
5.1 --- a/imiptools/handlers/scheduling.py Fri Jan 29 16:44:32 2016 +0100
5.2 +++ b/imiptools/handlers/scheduling.py Fri Jan 29 17:02:06 2016 +0100
5.3 @@ -3,7 +3,7 @@
5.4 """
5.5 Common scheduling functionality.
5.6
5.7 -Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk>
5.8 +Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
5.9
5.10 This program is free software; you can redistribute it and/or modify it under
5.11 the terms of the GNU General Public License as published by the Free Software
5.12 @@ -25,6 +25,41 @@
5.13 periods_from, remove_event_periods, \
5.14 remove_periods
5.15
5.16 +def apply_scheduling_functions(functions, handler):
5.17 +
5.18 + """
5.19 + Apply the given scheduling 'functions' in the current object of the given
5.20 + 'handler'.
5.21 + """
5.22 +
5.23 + response = "ACCEPTED"
5.24 +
5.25 + for fn in functions:
5.26 +
5.27 + # NOTE: Should signal an error for incorrectly configured resources.
5.28 +
5.29 + if not fn:
5.30 + return "DECLINED"
5.31 +
5.32 + # Keep evaluating scheduling functions, stopping only if one
5.33 + # declines or gives a null response.
5.34 +
5.35 + else:
5.36 + result = fn(handler)
5.37 +
5.38 + # Return a negative result immediately.
5.39 +
5.40 + if not result or result == "DECLINED":
5.41 + return result
5.42 +
5.43 + # Modify the eventual response from acceptance if a countering
5.44 + # result is obtained.
5.45 +
5.46 + elif response == "ACCEPTED":
5.47 + response = result
5.48 +
5.49 + return response
5.50 +
5.51 def schedule_in_freebusy(handler, freebusy=None):
5.52
5.53 """