#!/usr/bin/env python
+from __future__ import with_statement
+
import os
import time
import datetime
import ConfigParser
import logging
-import util.qt_compat as qt_compat
-QtCore = qt_compat.QtCore
import dbus
+import dialcentral.util.qt_compat as qt_compat
+QtCore = qt_compat.QtCore
+import dialcentral.util.linux as linux_utils
+
_FREMANTLE_ALARM = "Fremantle"
_DIABLO_ALARM = "Diablo"
_INVALID_COOKIE = -1
_REPEAT_FOREVER = -1
_TITLE = "Dialcentral Notifications"
- _LAUNCHER = os.path.abspath(os.path.join(os.path.dirname(__file__), "alarm_notify.py"))
+ _LAUNCHER = "python %s" % os.path.abspath(os.path.join(os.path.dirname(__file__), "alarm_notify.py"))
def __init__(self):
self._recurrence = 5
self._alarmCookie = self._INVALID_COOKIE
self._launcher = self._LAUNCHER
+ @property
+ def alarmCookie(self):
+ return self._alarmCookie
+
def load_settings(self, config, sectionName):
try:
self._recurrence = config.getint(sectionName, "recurrence")
_INVALID_COOKIE = -1
_TITLE = "Dialcentral Notifications"
- _LAUNCHER = os.path.abspath(os.path.join(os.path.dirname(__file__), "alarm_notify.py"))
+ _LAUNCHER = "python %s" % os.path.abspath(os.path.join(os.path.dirname(__file__), "alarm_notify.py"))
_REPEAT_FOREVER = -1
def __init__(self):
self._alarmCookie = self._INVALID_COOKIE
self._launcher = self._LAUNCHER
+ @property
+ def alarmCookie(self):
+ return self._alarmCookie
+
def load_settings(self, config, sectionName):
try:
self._recurrence = config.getint(sectionName, "recurrence")
self._timer.setSingleShot(False)
self._timer.setInterval(5 * self._MIN_TO_MS_FACTORY)
+ @property
+ def alarmCookie(self):
+ return 0
+
def load_settings(self, config, sectionName):
try:
self._timer.setInterval(config.getint(sectionName, "recurrence") * self._MIN_TO_MS_FACTORY)
self._enabled = False
self._recurrence = 5
+ @property
+ def alarmCookie(self):
+ return 0
+
def load_settings(self, config, sectionName):
try:
self._recurrence = config.getint(sectionName, "recurrence")
def isEnabled(self):
return self._currentAlarmType != self.ALARM_NONE
+ @property
+ def alarmCookie(self):
+ return self._alarms[self._currentAlarmType].alarmCookie
+
def _init_alarm(self, t):
if t not in self._alarms and self.ALARM_FACTORY[t] is not None:
self._alarms[t] = self.ALARM_FACTORY[t]()
-def main():
+def run():
logFormat = '(%(relativeCreated)5d) %(levelname)-5s %(threadName)s.%(name)s.%(funcName)s: %(message)s'
logging.basicConfig(level=logging.DEBUG, format=logFormat)
- import constants
+ from dialcentral import constants
try:
import optparse
except ImportError:
parser.add_option("-r", "--recurrence", action="store", type="int", dest="recurrence", help="How often the alarm occurs", default=5)
(commandOptions, commandArgs) = parser.parse_args()
+ settingsPath = linux_utils.get_resource_path("config", constants.__app_name__, "settings.ini")
+
alarmHandler = AlarmHandler()
config = ConfigParser.SafeConfigParser()
- config.read(constants._user_settings_)
+ config.read(settingsPath)
alarmHandler.load_settings(config, "alarm")
if commandOptions.display:
print "Alarm (%s) is %s for every %d minutes" % (
- alarmHandler._alarmCookie,
+ alarmHandler.alarmCookie,
"enabled" if alarmHandler.isEnabled else "disabled",
alarmHandler.recurrence,
)
else:
isEnabled = commandOptions.enabled
recurrence = commandOptions.recurrence
- alarmHandler.apply_settings(isEnabled, recurrence)
+
+ if alarmHandler.backgroundNotificationsSupported:
+ enableType = AlarmHandler.ALARM_BACKGROUND
+ else:
+ enableType = AlarmHandler.ALARM_APPLICATION
+ alarmHandler.apply_settings(enableType if isEnabled else AlarmHandler.ALARM_NONE, recurrence)
alarmHandler.save_settings(config, "alarm")
- configFile = open(constants._user_settings_, "wb")
- try:
+ with open(settingsPath, "wb") as configFile:
config.write(configFile)
- finally:
- configFile.close()
if __name__ == "__main__":
- main()
+ run()