1.1 --- a/imiptools/profile.py Sun Oct 25 01:25:29 2015 +0200
1.2 +++ b/imiptools/profile.py Sun Oct 25 18:53:50 2015 +0100
1.3 @@ -24,6 +24,10 @@
1.4 from imiptools.filesys import fix_permissions, FileBase
1.5 from os.path import exists, isdir
1.6 from os import listdir, makedirs
1.7 +import pytz
1.8 +
1.9 +def identity_dict(l):
1.10 + return dict([(i, i) for i in l])
1.11
1.12 class Preferences(FileBase):
1.13
1.14 @@ -48,6 +52,51 @@
1.15 "permitted_times" : None,
1.16 }
1.17
1.18 + known_key_choices = {
1.19 + "TZID" : identity_dict(pytz.all_timezones),
1.20 + "add_method_response" : {
1.21 + "add" : "Add events",
1.22 + "ignore" : "Ignore requests",
1.23 + "refresh" : "Ask for refreshed event details"
1.24 + },
1.25 + "event_refreshing" : {
1.26 + "never" : "Do not respond",
1.27 + "always" : "Always respond"
1.28 + },
1.29 + "freebusy_bundling" : {
1.30 + "never" : "Never",
1.31 + "always" : "Always"
1.32 + },
1.33 + "freebusy_messages" : {
1.34 + "none" : "Do not notify",
1.35 + "notify" : "Notify"
1.36 + },
1.37 + "freebusy_publishing" : {
1.38 + "publish" : "Publish",
1.39 + "no" : "Do not publish"
1.40 + },
1.41 + "freebusy_sharing" : {
1.42 + "share" : "Share",
1.43 + "no" : "Do not share"
1.44 + },
1.45 + "incoming" : {
1.46 + "message-only" : "Original message only",
1.47 + "message-then-summary" : "Original message followed by a separate summary message",
1.48 + "summary-then-message" : "Summary message followed by the original message",
1.49 + "summary-only" : "Summary message only",
1.50 + "summary-wraps-message" : "Summary message wrapping the original message"
1.51 + },
1.52 + "organiser_replacement" : {
1.53 + "any" : "Anyone",
1.54 + "attendee" : "Existing attendees only",
1.55 + "never" : "Never allow organiser replacement"
1.56 + },
1.57 + "participating" : {
1.58 + "participate" : "Participate",
1.59 + "no" : "Do not participate"
1.60 + }
1.61 + }
1.62 +
1.63 def __init__(self, user, store_dir=None):
1.64 FileBase.__init__(self, store_dir or config.PREFERENCES_DIR)
1.65 self.user = user
1.66 @@ -109,6 +158,8 @@
1.67 'all_known' is set to a true value, with absent entries providing a
1.68 default of None or any indicated 'default' or, if 'config_default' is
1.69 set to a true value, the default value from the config module.
1.70 +
1.71 + Each entry will have the form (key, value).
1.72 """
1.73
1.74 l = []
1.75 @@ -116,6 +167,22 @@
1.76 l.append((key, self.get(key, default, config_default)))
1.77 return l
1.78
1.79 + def choices(self, all_known=False, default=None, config_default=False):
1.80 +
1.81 + """
1.82 + Return all entries in the preferences or all known entries if
1.83 + 'all_known' is set to a true value, with absent entries providing a
1.84 + default of None or any indicated 'default' or, if 'config_default' is
1.85 + set to a true value, the default value from the config module.
1.86 +
1.87 + Each entry will have the form (key, value, choices).
1.88 + """
1.89 +
1.90 + l = []
1.91 + for key, value in self.items(all_known, default, config_default):
1.92 + l.append((key, value, self.known_key_choices.get(key)))
1.93 + return l
1.94 +
1.95 def __getitem__(self, name):
1.96
1.97 "Return the value for 'name', raising a KeyError if absent."