Commit d92bea58 authored by Sriram Karra's avatar Sriram Karra

Raise exception if there is an error parsing BBDB record

Due to a bug we were return None from the constructor... which, er,
does not do the right thing.
parent b365afc1
......@@ -30,6 +30,9 @@ from contact import Contact
from utils import chompq, unchompq
import demjson, pimdb_bb, folder_bb, utils
class BBDBParseError(Exception):
pass
class BBContact(Contact):
"""This class extends the Contact abstract base class to wrap a BBDB
Contact"""
......@@ -120,8 +123,7 @@ class BBContact(Contact):
parse_res = re.search(con_re, rec)
if not parse_res:
logging.critical('Could not Parse BBDB contact entry: %s', rec)
return
raise BBDBParseError('Could not Parse BBDB contact entry: %s' %rec)
d = parse_res.groupdict()
self._snarf_names_from_parse_res(d)
......
......@@ -115,12 +115,16 @@ class BBContactsFolder(Folder):
self.set_dirty()
for item in items:
bbc = BBContact(self, con=item)
bbc.update_sync_tags(src_tag, item.get_itemid())
bbc.set_updated(pimdb_bb.BBPIMDB.get_bbdb_time())
self.add_contact(bbc)
item.update_sync_tags(dst_tag, bbc.get_itemid())
try:
bbc = BBContact(self, con=item)
bbc.update_sync_tags(src_tag, item.get_itemid())
bbc.set_updated(pimdb_bb.BBPIMDB.get_bbdb_time())
self.add_contact(bbc)
item.update_sync_tags(dst_tag, bbc.get_itemid())
except BBDBParseError, e:
logging.error('Could not instantiate BBDBContact object: %s',
str(e))
try:
self.get_store().save_file()
......
##
## Created : Sat Apr 07 18:52:19 IST 2012
## Last Modified : Sat May 12 10:41:34 IST 2012
## Last Modified : Mon May 14 00:00:44 IST 2012
##
## Copyright (C) 2012 by Sriram Karra <karra.etc@gmail.com>
##
......@@ -23,7 +23,7 @@ import codecs, datetime, logging, os, re, shutil, string, time
from pimdb import PIMDB
from folder import Folder
from folder_bb import BBContactsFolder
from contact_bb import BBContact
from contact_bb import BBContact, BBDBParseError
import utils
## Note: Each BBDB File is a message store and there are one or more folders
......@@ -268,7 +268,13 @@ class MessageStore:
if re.search('^;', ff):
continue
c = BBContact(def_f, rec=ff.rstrip())
try:
c = BBContact(def_f, rec=ff.rstrip())
except BBDBParseError, e:
logging.error('Could not instantiate BBDBContact object: %s',
str(e))
continue
fn = c.get_bbdb_folder()
if fn:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment