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

Sebastian Krzyszkowiak seba.dos1 at gmail.com
Sat Aug 6 08:18:32 UTC 2011


The following commit has been merged in the debian branch:
commit bb2d4bdb07cf9ba153c16724b7323e43f751186d
Author: Guillaume Anciaux <g.anciaux at laposte.net>
Date:   Sat Sep 26 14:49:12 2009 +0200

    opimd: add VCard-Contacts backend
    Signed-off-by: Sebastian Krzyszkowiak <seba.dos1 at gmail.com>

diff --git a/framework/subsystems/opimd/pimb_csv_contacts.py b/framework/subsystems/opimd/pimb_vcard_contacts.py
similarity index 65%
copy from framework/subsystems/opimd/pimb_csv_contacts.py
copy to framework/subsystems/opimd/pimb_vcard_contacts.py
index c71015f..80d61cf 100644
--- a/framework/subsystems/opimd/pimb_csv_contacts.py
+++ b/framework/subsystems/opimd/pimb_vcard_contacts.py
@@ -1,13 +1,12 @@
 # -*- coding: utf-8 -*-
 #
 #   Openmoko PIM Daemon
-#   CSV-Contacts Backend Plugin
+#   VCARD-Contacts Backend Plugin
 #
 #   http://openmoko.org/
 #   http://pyneo.org/
 #
-#   Copyright (C) 2008 by Soeren Apel (abraxa at dar-clan.de)
-#   Copyright (C) 2009 by Sebastian Krzyszkowiak (seba.dos1 at gmail.com)
+#   Copyright (C) 2008 by Guillaume Anciaux (g.anciaux at laposte.net)
 #
 #   This program is free software; you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
@@ -24,9 +23,9 @@
 #   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 #
 
-"""opimd CSV-Contacts Backend Plugin"""
+"""opimd VCARD-Contacts Backend Plugin"""
 import os
-
+import vobject
 import logging
 logger = logging.getLogger('opimd')
 
@@ -41,14 +40,15 @@ from framework.config import config, rootdir
 rootdir = os.path.join( rootdir, 'opim' )
 
 _DOMAINS = ('Contacts', )
-_CSV_FILE_NAME = 'csv-contacts.txt'
+_VCARD_FILE_NAME = 'addressbook.vcf'
+_VCARD_FILE_NAME2 = 'addressbook2.vcf'
 
 
 
 #----------------------------------------------------------------------------#
-class CSVContactBackend(Backend):
+class VCARDContactBackend(Backend):
 #----------------------------------------------------------------------------#
-    name = 'CSV-Contacts'
+    name = 'VCARD-Contacts'
     properties = [PIMB_CAN_ADD_ENTRY, PIMB_CAN_DEL_ENTRY, PIMB_CAN_UPD_ENTRY, PIMB_CAN_UPD_ENTRY_WITH_NEW_FIELD, PIMB_NEEDS_SYNC]
 
     _domain_handlers = None           # Map of the domain handler objects we support
@@ -56,7 +56,7 @@ class CSVContactBackend(Backend):
 #----------------------------------------------------------------------------#
 
     def __init__(self):
-        super(CSVContactBackend, self).__init__()
+        super(VCARDContactBackend, self).__init__()
         self._domain_handlers = {}
         self._entry_ids = []
         
@@ -83,20 +83,28 @@ class CSVContactBackend(Backend):
 
     def load_entries_from_file(self):
         """Loads all entries from disk"""
-        
         try:
-            path = os.path.join(rootdir, _CSV_FILE_NAME)
+            path = os.path.join(rootdir, _VCARD_FILE_NAME)
+            logger.debug("read from vcard %s ", path)                    
             file = open(path, 'r')
-            
-            for line in file:
-                if line.find('=') == -1: continue
-                in_line = line.strip()
-
-                # Break CSV line up into key/value pairs, then assign them to the new entry
+            cards=vobject.readComponents(file)
+            for i in cards:
                 entry = {}
-                pairs = in_line.split(',')
-                for pair in pairs:
-                    (key, value) = pair.split('=')
+                for pair in i.lines():
+                    value = pair.value
+                    key = pair.name
+                    parameters = pair.params
+                    logger.debug("read from vcard %s %s" , key, value)
+                    if (key == "TEL"): 
+                        key = "Phone"
+                    elif (key == "FN"):
+                        key = "Name"
+                    elif (key == "EMAIL"):
+                        key = "EMail"
+                    else:
+                        continue
+
+                    logger.debug("adding vcard info %s %s" , key, value)
                     if entry.has_key(key):
                         if type(entry[key]) == list:
                             entry[key].append(value)
@@ -104,30 +112,41 @@ class CSVContactBackend(Backend):
                             entry[key]=[entry[key], value]
                     else:
                         entry[key] = value
-                
+                        
                 entry_id = self._domain_handlers['Contacts'].register_entry(self, entry)
                 self._entry_ids.append(entry_id)
                 
         except IOError:
-            logger.error("Error opening %s", path)
+            logger.error("vcard Error opening %s", path)
 
 
     def save_entries_to_file(self):
         """Saves all entries to disk"""
         
-        path = os.path.join(rootdir, _CSV_FILE_NAME)
+        path = os.path.join(rootdir, _VCARD_FILE_NAME2)
         file = open(path, 'w')
-        
+
+        logger.error("vcard saving entry ti files")        
         for entry in self._domain_handlers['Contacts'].enumerate_items(self):
             line = ""
+            card = vobject.vCard()
             for field in entry:
                 (field_name, field_data) = field
                 if type(field_data) == Array or type(field_data) == list:
                     for value in field_data:
-                        line += field_name + '=' + value + ','
+                        logger.error("vcard parsing memory entry")        
+                        if (field_name == "Name"): 
+                            card.add('fn').value = value
+                        elif (field_name == "Phone"): 
+                            card.add('tel').value = value
+                        elif (field_name == "EMail"): 
+                            card.add('email').value = value
+                        logger.error("vcard done")        
                 else:
-                    line += field_name + '=' + field_data + ','
-            file.write(line[:-1] + "\n")
+                    if (field_name == "Name"): card.add('fn').value = value
+                    elif (field_name == "Phone"): card.add('tel').value = value
+                    elif (field_name == "EMail"): card.add('email').value = value
+                file.write(card.serialize())
         
         file.close()
 
@@ -137,7 +156,6 @@ class CSVContactBackend(Backend):
 
     def sync(self):
         self.save_entries_to_file()
-        return True
 
     def upd_entry(self, contact_data):
         pass

-- 
FSO frameworkd Debian packaging



More information about the pkg-fso-commits mailing list