/usr/bin/remove-tel is in fso-frameworkd 0.9.5.9+git20110512-5.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | #! /usr/bin/python
# -*- coding: utf-8 -*-
import dbus
from sys import argv
from time import sleep
# define some nice dbus helper, which I really like, cause make code easier to read :)
def getDbusObject (bus, busname , objectpath , interface):
dbusObject = bus.get_object(busname, objectpath)
return dbus.Interface(dbusObject, dbus_interface=interface)
def print_array(array):
for entry in array:
print ' - ' + str(entry)
def strip_tel(value):
if value.startswith('tel:'):
return value[4:]
elif value.startswith('mail:'):
return value[5:]
else:
return False
bus = dbus.SystemBus()
initialized = False
print "Waiting for opimd to be ready..."
while (not initialized):
try:
interface = getDbusObject (bus, "org.freesmartphone.opimd", "/org/freesmartphone/PIM/Contacts", "org.freesmartphone.PIM.Contacts")
types = getDbusObject (bus, "org.freesmartphone.opimd", "/org/freesmartphone/PIM/Contacts", "org.freesmartphone.PIM.Fields")
initialized = True
except:
sleep(10)
x = interface.Query({})
query = getDbusObject (bus, "org.freesmartphone.opimd", x, "org.freesmartphone.PIM.ContactQuery")
def list_phone_fields():
return types.ListFieldsWithType('phonenumber')
def list_mail_fields():
return types.ListFieldsWithType('email')
def add_phone_field(field):
global phone_fields
if not field in phone_fields:
types.AddField(field, 'phonenumber')
phone_fields.append(field)
def add_mail_field(field):
global mail_fields
if not field in mail_fields:
types.AddField(field, 'email')
mail_fields.append(field)
try:
phone_fields = list_phone_fields()
mail_fields = list_mail_fields()
except:
print "Error: Couldn't get field types. Still running old opimd?"
exit(1)
results = query.GetResultCount()
for i in range(0, results):
x = query.GetContactPath()
print 'Processing ' + x
result = getDbusObject (bus, "org.freesmartphone.opimd", x, "org.freesmartphone.PIM.Contact")
content = result.GetContent()
to_update = {}
for field in content:
field = str(field)
if field.lower().endswith('phone'):
print ' Found field ' + field
if type(content[field]) == dbus.Array:
fresult = []
for entry in content[field]:
fresult.append(strip_tel(entry))
else:
fresult = strip_tel(content[field])
if fresult:
to_update[field] = fresult
add_phone_field(field)
if field.lower().endswith('e-mail') or field.lower().endswith('email'):
print ' Found field '+field
if type(content[field]) == dbus.Array:
fresult = []
for entry in content[field]:
fresult.append(strip_tel(entry))
else:
fresult = strip_tel(content[field])
if fresult:
to_update[field] = fresult
add_mail_field(field)
try:
if to_update!={}:
print to_update
print ' Updating entry...'
result.Update(to_update)
else:
print " Nothing to update"
except:
print ' Failed to update entry!'
print 'Finished'
print 'Fields with phonenumber type:'
print_array( phone_fields )
print 'Fields with email type:'
print_array( mail_fields )
|