Exemple #1
0
def notify_on_change():
	notifierLogPath = linux_utils.get_resource_path("cache", constants.__app_name__, "notifier.log")
	settingsPath = linux_utils.get_resource_path("config", constants.__app_name__, "settings.ini")
	with open(notifierLogPath, "a") as file:
		file.write("Notification: %r\n" % (datetime.datetime.now(), ))

		config = ConfigParser.SafeConfigParser()
		config.read(settingsPath)
		backend = alarm_notify.create_backend(config)
		notifyUser = alarm_notify.is_changed(config, backend)

		if notifyUser:
			file.write("\tChange occurred\n")
Exemple #2
0
def notify_on_change():
	settingsPath = linux_utils.get_resource_path("config", constants.__app_name__, "settings.ini")
	notifierSettingsPath = linux_utils.get_resource_path("config", constants.__app_name__, "notifier.ini")

	config = ConfigParser.SafeConfigParser()
	config.read(settingsPath)
	backend = alarm_notify.create_backend(config)
	notifyUser = alarm_notify.is_changed(config, backend)

	config = ConfigParser.SafeConfigParser()
	config.read(notifierSettingsPath)
	soundFile = config.get("Sound Notifier", "soundfile")
	soundFile = "/usr/lib/gv-notifier/alert.mp3"

	if notifyUser:
		import subprocess
		import led_handler
		logging.info("Changed, playing %s" % soundFile)
		led = led_handler.LedHandler()
		led.on()
		soundOn = subprocess.call("/usr/bin/dbus-send --dest=com.nokia.osso_media_server --print-reply /com/nokia/osso_media_server com.nokia.osso_media_server.music.play_media string:file://%s",shell=True)
	else:
		logging.info("No Change")
Exemple #3
0
def run():
	logFormat = '(%(relativeCreated)5d) %(levelname)-5s %(threadName)s.%(name)s.%(funcName)s: %(message)s'
	logging.basicConfig(level=logging.DEBUG, format=logFormat)
	from dialcentral import constants
	try:
		import optparse
	except ImportError:
		return

	parser = optparse.OptionParser()
	parser.add_option("-x", "--display", action="store_true", dest="display", help="Display data")
	parser.add_option("-e", "--enable", action="store_true", dest="enabled", help="Whether the alarm should be enabled or not", default=False)
	parser.add_option("-d", "--disable", action="store_false", dest="enabled", help="Whether the alarm should be enabled or not", default=False)
	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(settingsPath)
	alarmHandler.load_settings(config, "alarm")

	if commandOptions.display:
		print "Alarm (%s) is %s for every %d minutes" % (
			alarmHandler.alarmCookie,
			"enabled" if alarmHandler.isEnabled else "disabled",
			alarmHandler.recurrence,
		)
	else:
		isEnabled = commandOptions.enabled
		recurrence = commandOptions.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")
		with open(settingsPath, "wb") as configFile:
			config.write(configFile)
Exemple #4
0
	config = ConfigParser.SafeConfigParser()
	config.read(notifierSettingsPath)
	soundFile = config.get("Sound Notifier", "soundfile")
	soundFile = "/usr/lib/gv-notifier/alert.mp3"

	if notifyUser:
		import subprocess
		import led_handler
		logging.info("Changed, playing %s" % soundFile)
		led = led_handler.LedHandler()
		led.on()
		soundOn = subprocess.call("/usr/bin/dbus-send --dest=com.nokia.osso_media_server --print-reply /com/nokia/osso_media_server com.nokia.osso_media_server.music.play_media string:file://%s",shell=True)
	else:
		logging.info("No Change")


if __name__ == "__main__":
	notifierLogPath = linux_utils.get_resource_path("cache", constants.__app_name__, "notifier.log")

	logging.basicConfig(level=logging.WARNING, filename=notifierLogPath)
	logging.info("Sound Notifier %s-%s" % (constants.__version__, constants.__build__))
	logging.info("OS: %s" % (os.uname()[0], ))
	logging.info("Kernel: %s (%s) for %s" % os.uname()[2:])
	logging.info("Hostname: %s" % os.uname()[1])
	try:
		notify_on_change()
	except:
		logging.exception("Error")
		raise