1.1 --- a/imiptools/handlers/scheduling.py Fri Jan 29 16:44:32 2016 +0100
1.2 +++ b/imiptools/handlers/scheduling.py Fri Jan 29 17:02:06 2016 +0100
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Common scheduling functionality.
1.6
1.7 -Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -25,6 +25,41 @@
1.13 periods_from, remove_event_periods, \
1.14 remove_periods
1.15
1.16 +def apply_scheduling_functions(functions, handler):
1.17 +
1.18 + """
1.19 + Apply the given scheduling 'functions' in the current object of the given
1.20 + 'handler'.
1.21 + """
1.22 +
1.23 + response = "ACCEPTED"
1.24 +
1.25 + for fn in functions:
1.26 +
1.27 + # NOTE: Should signal an error for incorrectly configured resources.
1.28 +
1.29 + if not fn:
1.30 + return "DECLINED"
1.31 +
1.32 + # Keep evaluating scheduling functions, stopping only if one
1.33 + # declines or gives a null response.
1.34 +
1.35 + else:
1.36 + result = fn(handler)
1.37 +
1.38 + # Return a negative result immediately.
1.39 +
1.40 + if not result or result == "DECLINED":
1.41 + return result
1.42 +
1.43 + # Modify the eventual response from acceptance if a countering
1.44 + # result is obtained.
1.45 +
1.46 + elif response == "ACCEPTED":
1.47 + response = result
1.48 +
1.49 + return response
1.50 +
1.51 def schedule_in_freebusy(handler, freebusy=None):
1.52
1.53 """