Bump to 1.3.11-2
[gc-dialer] / dialcentral / alarm_notify.py
index bc6240e..084127c 100755 (executable)
@@ -8,9 +8,13 @@ import logging
 import logging.handlers
 
 import constants
+from util import linux as linux_utils
 from backends.gvoice import gvoice
 
 
+CACHE_PATH = linux_utils.get_resource_path("cache", constants.__app_name__)
+
+
 def get_missed(backend):
        missedPage = backend._browser.download(backend._XML_MISSED_URL)
        missedJson = backend._grab_json(missedPage)
@@ -53,8 +57,8 @@ def is_type_changed(backend, type, get_material):
        jsonMaterial = get_material(backend)
        unreadCount = jsonMaterial["unreadCounts"][type]
 
-       previousSnapshotPath = os.path.join(constants._data_path_, "snapshot_%s.old.json" % type)
-       currentSnapshotPath = os.path.join(constants._data_path_, "snapshot_%s.json" % type)
+       previousSnapshotPath = os.path.join(CACHE_PATH, "snapshot_%s.old.json" % type)
+       currentSnapshotPath = os.path.join(CACHE_PATH, "snapshot_%s.json" % type)
 
        try:
                os.remove(previousSnapshotPath)
@@ -87,7 +91,7 @@ def is_type_changed(backend, type, get_material):
 
 
 def create_backend(config):
-       gvCookiePath = os.path.join(constants._data_path_, "gv_cookies.txt")
+       gvCookiePath = os.path.join(CACHE_PATH, "gv_cookies.txt")
        backend = gvoice.GVoiceBackend(gvCookiePath)
 
        loggedIn = False
@@ -150,8 +154,10 @@ def is_changed(config, backend):
 
 
 def notify_on_change():
+       settingsPath = linux_utils.get_resource_path("config", constants.__app_name__, "settings.ini")
+
        config = ConfigParser.SafeConfigParser()
-       config.read(constants._user_settings_)
+       config.read(settingsPath)
        backend = create_backend(config)
        notifyUser = is_changed(config, backend)
 
@@ -164,10 +170,12 @@ def notify_on_change():
                logging.info("No Change")
 
 
-if __name__ == "__main__":
+def run():
+       notifierPath = os.path.join(CACHE_PATH, "notifier.log")
+
        logFormat = '(%(relativeCreated)5d) %(levelname)-5s %(threadName)s.%(name)s.%(funcName)s: %(message)s'
        logging.basicConfig(level=logging.DEBUG, format=logFormat)
-       rotating = logging.handlers.RotatingFileHandler(constants._notifier_logpath_, maxBytes=512*1024, backupCount=1)
+       rotating = logging.handlers.RotatingFileHandler(notifierPath, maxBytes=512*1024, backupCount=1)
        rotating.setFormatter(logging.Formatter(logFormat))
        root = logging.getLogger()
        root.addHandler(rotating)
@@ -180,3 +188,7 @@ if __name__ == "__main__":
        except:
                logging.exception("Error")
                raise
+
+
+if __name__ == "__main__":
+       run()