imip-agent

Changeset

791:7cbf127b2711
2015-09-29 Paul Boddie raw files shortlog changelog graph Added a CN (common name) setting and support for user attributes.
docs/preferences.txt (file) imiptools/client.py (file) imiptools/profile.py (file)
     1.1 --- a/docs/preferences.txt	Tue Sep 29 14:04:57 2015 +0200
     1.2 +++ b/docs/preferences.txt	Tue Sep 29 19:02:01 2015 +0200
     1.3 @@ -1,6 +1,15 @@
     1.4  Preferences and Settings
     1.5  ========================
     1.6  
     1.7 +CN
     1.8 +--
     1.9 +
    1.10 +Default: (none)
    1.11 +Alternatives: (see below)
    1.12 +
    1.13 +The common name of the user, employed in iCalendar objects and user
    1.14 +interfaces.
    1.15 +
    1.16  LANG
    1.17  ----
    1.18  
     2.1 --- a/imiptools/client.py	Tue Sep 29 14:04:57 2015 +0200
     2.2 +++ b/imiptools/client.py	Tue Sep 29 19:02:01 2015 +0200
     2.3 @@ -74,6 +74,10 @@
     2.4              self.preferences = Preferences(self.user, self.preferences_dir)
     2.5          return self.preferences
     2.6  
     2.7 +    def get_user_attributes(self):
     2.8 +        prefs = self.get_preferences()
     2.9 +        return prefs and prefs.get_all(["CN"]) or {}
    2.10 +
    2.11      def get_tzid(self):
    2.12          prefs = self.get_preferences()
    2.13          return prefs and prefs.get("TZID") or get_default_timezone()
     3.1 --- a/imiptools/profile.py	Tue Sep 29 14:04:57 2015 +0200
     3.2 +++ b/imiptools/profile.py	Tue Sep 29 19:02:01 2015 +0200
     3.3 @@ -44,6 +44,30 @@
     3.4          except KeyError:
     3.5              return default
     3.6  
     3.7 +    def get_all(self, names):
     3.8 +
     3.9 +        """
    3.10 +        Return a dictionary containing values for entries having the given
    3.11 +        'names'. Absent entries for names are omitted without error.
    3.12 +        """
    3.13 +
    3.14 +        d = {}
    3.15 +        for name in names:
    3.16 +            value = self.get(name)
    3.17 +            if value is not None:
    3.18 +                d[name] = value
    3.19 +        return d
    3.20 +
    3.21 +    def has_key(self, name):
    3.22 +
    3.23 +        "Return whether an entry exists for 'name'."
    3.24 +
    3.25 +        try:
    3.26 +            self[name]
    3.27 +            return True
    3.28 +        except KeyError:
    3.29 +            return False
    3.30 +
    3.31      def __getitem__(self, name):
    3.32  
    3.33          "Return the value for 'name', raising a KeyError if absent."