Refactoring in case I want to use some of the notify stuff in Dialcentral
authorepage <eopage@byu.net>
Sat, 24 Oct 2009 19:09:19 +0000 (19:09 +0000)
committerepage <eopage@byu.net>
Sat, 24 Oct 2009 19:09:19 +0000 (19:09 +0000)
git-svn-id: file:///svnroot/gc-dialer/trunk@560 c39d3808-3fe2-4d86-a59f-b7f623ee9f21

src/alarm_notify.py
src/examples/log_notifier.py
src/examples/sound_notifier.py

index 9cb42b8..1920a59 100755 (executable)
@@ -69,7 +69,7 @@ def is_type_changed(backend, type, get_material):
        return not seemEqual
 
 
-def is_changed():
+def create_backend(config):
        gvCookiePath = os.path.join(constants._data_path_, "gv_cookies.txt")
        backend = gv_backend.GVDialer(gvCookiePath)
 
@@ -78,8 +78,6 @@ def is_changed():
        if not loggedIn:
                loggedIn = backend.is_authed()
 
-       config = ConfigParser.SafeConfigParser()
-       config.read(constants._user_settings_)
        if not loggedIn:
                import base64
                try:
@@ -98,6 +96,11 @@ def is_changed():
                except ConfigParser.NoSectionError, e:
                        pass
 
+       assert loggedIn
+       return backend
+
+
+def is_changed(config, backend):
        try:
                notifyOnMissed = config.getboolean("2 - Account Info", "notifyOnMissed")
                notifyOnVoicemail = config.getboolean("2 - Account Info", "notifyOnVoicemail")
@@ -111,7 +114,6 @@ def is_changed():
                notifyOnVoicemail = False
                notifyOnSms = False
 
-       assert loggedIn
        notifySources = []
        if notifyOnMissed:
                notifySources.append(("missed", get_missed))
@@ -128,7 +130,10 @@ def is_changed():
 
 
 def notify_on_change():
-       notifyUser = is_changed()
+       config = ConfigParser.SafeConfigParser()
+       config.read(constants._user_settings_)
+       backend = create_backend(config)
+       notifyUser = is_changed(config, backend)
 
        if notifyUser:
                import led_handler
index 7c0ce24..6e63b5d 100644 (file)
@@ -4,6 +4,7 @@ from __future__ import with_statement
 
 import sys
 import datetime
+import ConfigParser
 
 
 sys.path.insert(0,"/usr/lib/dialcentral/")
@@ -17,7 +18,12 @@ def notify_on_change():
        filename = "%s/notification.log" % constants._data_path_
        with open(filename, "a") as file:
                file.write("Notification: %r\n" % (datetime.datetime.now(), ))
-               notifyUser = alarm_notify.is_changed()
+
+               config = ConfigParser.SafeConfigParser()
+               config.read(constants._user_settings_)
+               backend = alarm_notify.create_backend(config)
+               notifyUser = alarm_notify.is_changed(config, backend)
+
                if notifyUser:
                        file.write("\tChange occurred\n")
 
index 3679b5b..2df7b45 100644 (file)
@@ -1,16 +1,21 @@
 #!/usr/bin/env python
 
 import sys
+import ConfigParser
 
 
 sys.path.insert(0,"/usr/lib/dialcentral/")
 
 
+import constants
 import alarm_notify
 
 
 def notify_on_change():
-       notifyUser = alarm_notify.is_changed()
+       config = ConfigParser.SafeConfigParser()
+       config.read(constants._user_settings_)
+       backend = alarm_notify.create_backend(config)
+       notifyUser = alarm_notify.is_changed(config, backend)
 
        if notifyUser:
                import subprocess