~jconti/recent-notifications/trunk

« back to all changes in this revision

Viewing changes to recent_notifications/Config.py

  • Committer: Jason Conti
  • Date: 2011-02-14 18:47:15 UTC
  • Revision ID: jason.conti@gmail.com-20110214184715-kf2yr28lhdea6v8o
Can now enable/disable debug messages (which are logged to ~/.cache/recent-notifications.log). Errors are still logged to that file even if debug is disabled. Disabling debug by default, since most people will have no use for it, and if you never reboot, the file could grow quite large.

Show diffs side-by-side

added added

removed removed

Lines of Context:
108
108
    else:
109
109
      return default
110
110
 
 
111
  def get_int(self, key, default = 0):
 
112
    """Returns this value of the given key as an int, or the default value if it fails to
 
113
    convert or does not exist."""
 
114
    if key not in self._options:
 
115
      return default
 
116
    value = self._options[key]
 
117
    try:
 
118
      return int(value)
 
119
    except:
 
120
      return default
 
121
 
111
122
  def set(self, key, value):
112
123
    """Sets the value for the given key, saves the config file and notifies any
113
124
    listeners that the value has changed."""
119
130
      for f in self._listeners[key]:
120
131
        f(key, value)
121
132
 
 
133
  def set_if_unset(self, key, value):
 
134
    """Calls set(key, value) only if the key does not exist in this config."""
 
135
    if key not in self._options:
 
136
      self.set(key, value)
 
137