1.1 --- a/imip_store.py Mon Feb 08 17:40:20 2016 +0100
1.2 +++ b/imip_store.py Mon Feb 08 18:46:31 2016 +0100
1.3 @@ -986,7 +986,7 @@
1.4
1.5 return dict(self._get_table_atomic(quota, filename, tab_separated=False))
1.6
1.7 - # Free/busy period access.
1.8 + # Free/busy period access for users within quota groups.
1.9
1.10 def get_freebusy(self, quota, user, get_table=None):
1.11
1.12 @@ -1024,7 +1024,7 @@
1.13 if not filename or not isfile(filename):
1.14 return []
1.15
1.16 - return self._get_table_atomic(quota, filename, [(1, None)])
1.17 + return self._get_table_atomic(quota, filename, [(1, None), (3, None)])
1.18
1.19 def set_entries(self, quota, group, entries):
1.20
1.21 @@ -1037,7 +1037,7 @@
1.22 if not filename:
1.23 return False
1.24
1.25 - self._set_table_atomic(quota, filename, entries, [(1, "")])
1.26 + self._set_table_atomic(quota, filename, entries, [(1, ""), (3, "")])
1.27 return True
1.28
1.29 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/imiptools/handlers/scheduling/quota.py Mon Feb 08 17:40:20 2016 +0100
2.2 +++ b/imiptools/handlers/scheduling/quota.py Mon Feb 08 18:46:31 2016 +0100
2.3 @@ -19,7 +19,8 @@
2.4 this program. If not, see <http://www.gnu.org/licenses/>.
2.5 """
2.6
2.7 -from imiptools.dates import format_duration, get_duration
2.8 +from imiptools.dates import format_datetime, format_duration, get_datetime, \
2.9 + get_duration, to_utc_datetime
2.10 from imiptools.data import get_uri
2.11 from imiptools.period import Endless
2.12 from datetime import timedelta
2.13 @@ -72,13 +73,14 @@
2.14 quota, group = _get_quota_and_group(handler, args)
2.15
2.16 total = _get_duration(handler)
2.17 + expiry = _get_expiry_time(handler)
2.18
2.19 # Obtain the journal entries and limits.
2.20
2.21 journal = handler.get_journal()
2.22 entries = journal.get_entries(quota, group)
2.23
2.24 - if _add_to_entries(entries, handler.uid, handler.recurrenceid, format_duration(total)):
2.25 + if _add_to_entries(entries, handler.uid, handler.recurrenceid, format_duration(total), format_datetime(expiry)):
2.26 journal.set_entries(quota, group, entries)
2.27
2.28 def remove_from_quota(handler, args):
2.29 @@ -142,24 +144,37 @@
2.30
2.31 return total
2.32
2.33 +def _get_expiry_time(handler):
2.34 +
2.35 + """
2.36 + Return the expiry time for quota purposes of the current object provided by
2.37 + the 'handler'.
2.38 + """
2.39 +
2.40 + # Count only explicit periods.
2.41 + # NOTE: Should reject indefinitely recurring events.
2.42 +
2.43 + periods = handler.get_periods(handler.obj, explicit_only=True)
2.44 + return periods and to_utc_datetime(periods[-1].get_end_point()) or None
2.45 +
2.46 def _get_usage(entries):
2.47
2.48 "Return the usage total according to the given 'entries'."
2.49
2.50 total = timedelta(0)
2.51
2.52 - for found_uid, found_recurrenceid, found_duration in entries:
2.53 + for found_uid, found_recurrenceid, found_duration, found_expiry in entries:
2.54 retraction = found_duration.startswith("-")
2.55 multiplier = retraction and -1 or 1
2.56 total += multiplier * get_duration(found_duration[retraction and 1 or 0:])
2.57
2.58 return total
2.59
2.60 -def _add_to_entries(entries, uid, recurrenceid, duration):
2.61 +def _add_to_entries(entries, uid, recurrenceid, duration, expiry):
2.62
2.63 """
2.64 Add to 'entries' an entry for the event having the given 'uid' and
2.65 - 'recurrenceid' with the given 'duration'.
2.66 + 'recurrenceid' with the given 'duration' and 'expiry' time.
2.67 """
2.68
2.69 confirmed = _find_applicable_entry(entries, uid, recurrenceid, duration)
2.70 @@ -167,15 +182,15 @@
2.71 # Where a previous entry still applies, retract it if different.
2.72
2.73 if confirmed:
2.74 - found_uid, found_recurrenceid, found_duration = confirmed
2.75 + found_uid, found_recurrenceid, found_duration, found_expiry = confirmed
2.76 if found_duration != duration:
2.77 - entries.append((found_uid, found_recurrenceid, "-%s" % found_duration))
2.78 + entries.append((found_uid, found_recurrenceid, "-%s" % found_duration, found_expiry))
2.79 else:
2.80 return False
2.81
2.82 # Without an applicable previous entry, add a new entry.
2.83
2.84 - entries.append((uid, recurrenceid, duration))
2.85 + entries.append((uid, recurrenceid, duration, expiry))
2.86 return True
2.87
2.88 def _remove_from_entries(entries, uid, recurrenceid, duration):
2.89 @@ -190,8 +205,8 @@
2.90 # Where a previous entry still applies, retract it.
2.91
2.92 if confirmed:
2.93 - found_uid, found_recurrenceid, found_duration = confirmed
2.94 - entries.append((found_uid, found_recurrenceid, "-%s" % found_duration))
2.95 + found_uid, found_recurrenceid, found_duration, found_expiry = confirmed
2.96 + entries.append((found_uid, found_recurrenceid, "-%s" % found_duration, found_expiry))
2.97 return found_duration == duration
2.98
2.99 return False
2.100 @@ -205,12 +220,12 @@
2.101
2.102 confirmed = None
2.103
2.104 - for found_uid, found_recurrenceid, found_duration in entries:
2.105 + for found_uid, found_recurrenceid, found_duration, found_expiry in entries:
2.106 if uid == found_uid and recurrenceid == found_recurrenceid:
2.107 if found_duration.startswith("-"):
2.108 confirmed = None
2.109 else:
2.110 - confirmed = found_uid, found_recurrenceid, found_duration
2.111 + confirmed = found_uid, found_recurrenceid, found_duration, found_expiry
2.112
2.113 return confirmed
2.114