[pkg-fso-commits] [SCM] FSO frameworkd Debian packaging branch, debian, updated. upstream/0.9.5.5-717-g0f98819

Klaus Kurzmann mok at fluxnetz.de
Sat Aug 6 08:19:01 UTC 2011


The following commit has been merged in the debian branch:
commit e089faa5f0cfd9d7bd22f1d1a6f132d91809b819
Author: Klaus Kurzmann <mok at fluxnetz.de>
Date:   Thu Jan 28 17:12:31 2010 +0100

    tools: add remove-tel script needed to convert old contacts to type based opimd
    
    Signed-off-by: Klaus Kurzmann <mok at fluxnetz.de>

diff --git a/tools/remove-tel b/tools/remove-tel
new file mode 100644
index 0000000..6bfa3dd
--- /dev/null
+++ b/tools/remove-tel
@@ -0,0 +1,110 @@
+#!/usr/bin/env 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 )

-- 
FSO frameworkd Debian packaging



More information about the pkg-fso-commits mailing list