View Single Post
Posts: 1,425 | Thanked: 983 times | Joined on May 2010 @ Hong Kong
#13
Though I still couldn't reproduce Matan's race condition, but may be running a compiled version would help. Anyway.

I made a slight modification to the script, including call-blocking function. I know there's already pycallblocker around for use, but I think some people would like it to be incorporated into one.

I'm still working on pelago's suggestion on using contact list and making UI(my weakest part), but for the time being just edit the script if you need to use it. ^^

Code:
#! /usr/bin/env python2.5
#
# callergroup - Assign Ringtone By Caller-Group for N900 v0.0.2
# By 9000 @ maemo.org/phonehk.com 14-May-2010
#
# ATTENTION: Use the script at your own risk. You're responsible for any damage that'd cause by using this script.
# LIMITATION: Lots. Like lacking fancy UI,  insufficient format support (WAV only), etc. 
# FEATURE: 1) Assign different ringtones to caller-groups you defined. 2) Block calls
# CHANGELOG: 18-May-2010: Add blocking function
#
# Usage: 
# 1) Move your default ringtone to /home/user/.local/share/sounds/callergroup/ , I choose Gradient.acc.wav in this example
# mkdir -p /home/user/.local/share/sounds/callergroup/
# mv /home/user/.local/share/sounds/Gradient.acc.wav /home/user/.local/share/sounds/callergroup/.
#
# 2) Symlink your default ringtone back to /home/user/.local/share/sounds/ , Gradient.aac.wav in this example
# ln -sf /home/user/.local/share/sounds/callergroup/Gradient.aac.wav /home/user/.local/share/sounds/Gradient.aac.wav
#
# 3) Copy any wav files you'd like to set for the groups. I use ringtone_for_group_X.wav in this example
# cp /media/mmc1/ringtone/*.wav /home/user/.local/share/sounds/callergroup/. (just an example)
#
# 4) Customize the telephone number and ringtone file name in the CUSTOMIZATION section below
#
# 5) Run the script
# /usr/bin/python ./callergroup.py
# 


import gobject, dbus
import time
import os
from dbus.mainloop.glib import DBusGMainLoop

def handle_call(obj_path, callernumber):
	global blocklist
	print 'Calling from '+callernumber+'...'

# Caller group found:
	if callernumber in group_info:
		assigned_group = group_info[callernumber]
		group_ring = group_ringtones[assigned_group]
		print 'Caller belongs to Group:'+assigned_group+', ringtone assigned:'+group_ring+'.wav'
		bus = dbus.SessionBus()
		profiled = bus.get_object('com.nokia.profiled', '/com/nokia/profiled')
		proxy = dbus.Interface(profiled, 'com.nokia.profiled')
		system_ring = os.path.basename(proxy.get_value('general','ringing.alert.tone'))
		os.system('ln -sf /home/user/.local/share/sounds/callergroup/'+group_ring+'.wav /home/user/.local/share/sounds/'+system_ring+'.wav')

# Call blocking:
	elif callernumber in blocklist:
		print 'Caller from '+callernumber+' blocked'
		bus = dbus.SystemBus()
		callobject = bus.get_object('com.nokia.csd.Call', '/com/nokia/csd/call/1')
		smsiface = dbus.Interface(callobject, 'com.nokia.csd.Call.Instance')
		smsiface.Release()

# Default:
	else:
		print 'Caller has no assigned group'
		bus = dbus.SessionBus()
		profiled = bus.get_object('com.nokia.profiled', '/com/nokia/profiled')
		proxy = dbus.Interface(profiled, 'com.nokia.profiled')
		system_ring = os.path.basename(proxy.get_value('general','ringing.alert.tone'))
		os.system('ln -sf /home/user/.local/share/sounds/callergroup/'+system_ring+'.wav /home/user/.local/share/sounds/'+system_ring+'.wav')

# ---CUSTOMIZATION--- #

# The telephone numbers to block
blocklist = ["11709394","53540997"]

# Change the name of the ringtones for the corresponding groups
group_ringtones = {	'GroupA':'ringtone_for_group_a',
			'GroupB':'ringtone_for_group_b',
			'GroupC':'ringtone_for_group_c',
			}

# Associate the telephone numbers to the groups
group_info = {	'77777777':'GroupA',
		'88888888':'GroupB',
		'12345678':'GroupB',
		'87654321':'GroupC',
		}

# ---END OF CUSTOMIZATION--- #  

DBusGMainLoop(set_as_default=True) 
bus = dbus.SystemBus()
bus.add_signal_receiver(handle_call, path='/com/nokia/csd/call', dbus_interface='com.nokia.csd.Call', signal_name='Coming')
gobject.MainLoop().run()
Source Reference:
http://maemocentral.com/2010/02/22/h...s-on-the-n900/
http://www.maemoers.com/archiver/tid-2364.html
Attached Files
File Type: zip callergroup.zip (1.4 KB, 367 views)

Last edited by 9000; 2010-05-24 at 15:53.
 

The Following 7 Users Say Thank You to 9000 For This Useful Post: