Commit 0dc0f13f authored by Sriram Karra's avatar Sriram Karra

Handle non-existent BBDB stores in profiles gracefully - i.e. do not puke

parent fcecdbb4
......@@ -23,6 +23,7 @@ state.json
# Karra's Password files for development purposes
......@@ -231,18 +231,26 @@ class MessageStore:
return None
def _set_default_preamble (self):
ver = '7'
self.append_preamble(';; -*-coding: utf-8-emacs;-*-\n')
self.append_preamble(';;; file-format: %s\n' % ver)
return ver
def parse_with_encoding (self, def_f, fn, encoding):
"""Folder object to which the parsed contacts will be added. fn is the
name of the BBDB file/message store. encoding is a string representing
a text encoding such as utf-8, latin-1, etc."""
if not os.path.exists(fn):
with, encoding=encoding) as bbf:
ver = self._parse_preamble(fn, bbf)
if not ver:
## We encountered a blank BBDB file.
ver = '7'
self.append_preamble(';; -*-coding: utf-8-emacs;-*-\n')
self.append_preamble(';;; file-format: %s\n' % ver)
ver = self._set_default_preamble()
## Now fetch and set up the parsing routines specific to the file
## format
......@@ -75,6 +75,12 @@ def asynk_ts_parse (ts):
return iso8601.parse(asynk_ts_to_iso8601(ts))
def touch (fn):
"""Equivalent of the Unix 'touch' command."""
with open(fn, 'a'):
os.utime(fn, None)
def abs_pathname (config, fname):
"""If fname is an absolute path then it is returned as is. If it starts
with a ~ then expand the path as per Unix conventions and finally if it
......@@ -74,9 +74,13 @@ def main (argv=None):
print "Running tests against all BBDB files in data/bb/..."
patt = os.path.join(asynk_base_dir, "test", "gold", "data",
"bb", "*")
for f in glob.glob(patt):
bb_data_dir = os.path.join(asynk_base_dir, "test", "gold", "data",
patt = os.path.join(bb_data_dir, "*")
test_inputs = glob.glob(patt)
for f in test_inputs:
def run (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