Commit d642e2a1 authored by Sriram Karra's avatar Sriram Karra

list_folders() implementation for all the PIMDBs

Includes some minor logging changes so only useful information
is printed during default run.
parent 4345192a
##
## Created : Tue Mar 13 14:26:01 IST 2012
## Last Modified : Tue Apr 10 09:09:29 IST 2012
## Last Modified : Wed Apr 11 18:36:40 IST 2012
##
## Copyright (C) 2012 Sriram Karra <karra.etc@gmail.com>
##
......@@ -68,6 +68,14 @@ class PIMDB:
raise NotImplementedError
@abstractmethod
def list_folders (self):
"""Print details of all folders in the PIMDB. Detail will typically
include one line per folder, with its name, and any identifier that
can be used for further referencing."""
raise NotImplementedError
@abstractmethod
def new_folder (self, fname, type):
"""Create a new folder of specified type and return an id. The folder
......@@ -180,7 +188,7 @@ class PIMDB:
ed = dbc['phones_map']
return self._set_att('phones_map', ed)
except KeyError, e:
logging.debug('set_phones_map(): No phones_map for PIMDB %s',
logging.debug('PIMDB %s does not have phones_map',
self.get_dbid())
return self._set_att('phones_map', None)
......
##
## Created : Sat Apr 07 18:52:19 IST 2012
## Last Modified : Tue Apr 10 09:13:31 IST 2012
## Last Modified : Wed Apr 11 19:07:28 IST 2012
##
## Copyright (C) 2012 by Sriram Karra <karra.etc@gmail.com>
##
......@@ -32,6 +32,13 @@ class BBPIMDB(PIMDB):
return 'bb'
def list_folders (self):
"""See the documentation in class PIMDB"""
## BBDB is intended to be a one database system...
logging.info(' %2d; Name: %-32s ID: %s', 1, self.get_def_fn(),
None)
def new_folder (self, fname, type):
"""See the documentation in class PIMDB"""
......
##
## Created : Thu Jul 07 14:47:54 IST 2011
## Last Modified : Tue Apr 10 09:12:25 IST 2012
## Last Modified : Wed Apr 11 19:09:54 IST 2012
##
## Copyright (C) 2011, 2012 by Sriram Karra <karra.etc@gmail.com>
##
......@@ -37,6 +37,25 @@ class GCPIMDB(PIMDB):
return 'gc'
def list_folders (self, silent=False):
"""Apart from doing the usual thing, this also retusn some good
stuff..."""
ret = []
feed = self.get_groups_feed()
if not feed.entry:
return ret
for i, entry in enumerate(feed.entry):
name = entry.content.text if entry.content else entry.title.text
if not silent:
logging.info(' %2d: Contacts Name: %-25s ID: %s',
i, name, entry.id.text)
ret.append((entry.id.text, name, entry))
return ret
def new_folder (self, fname, ftype=None):
if not ftype:
ftype = Folder.CONTACT_t
......@@ -86,7 +105,7 @@ class GCPIMDB(PIMDB):
"""See the documentation in class PIMDB"""
logging.debug('Getting Group List to populate folders...')
groups = self.list_groups()
groups = self.list_folders(silent=True)
for (gid, gn, gcentry) in groups:
f = GCContactsFolder(self, gid, gn, gcentry)
self.add_contacts_folder(f)
......@@ -130,7 +149,7 @@ class GCPIMDB(PIMDB):
self.gdc = gdc
def gc_init (self):
logging.debug('Logging into Google...')
logging.info('Logging into Google...')
gdc = gdata.contacts.client.ContactsClient(source='Gout-Sync')
gdc.ClientLogin(self.get_user(), self.get_pw(), gdc.source)
......@@ -152,19 +171,6 @@ class GCPIMDB(PIMDB):
feed = self.get_gdc().GetGroups()
return feed
def list_groups (self):
ret = []
feed = self.get_groups_feed()
if not feed.entry:
return ret
for i, entry in enumerate(feed.entry):
name = entry.content.text if entry.content else entry.title.text
ret.append((entry.id.text, name, entry))
return ret
def print_groups (self):
feed = self.get_groups_feed()
......
##
## Created : Wed May 18 13:16:17 IST 2011
## Last Modified : Tue Apr 10 09:10:49 IST 2012
## Last Modified : Wed Apr 11 19:08:53 IST 2012
##
## Copyright (C) 2011, 2012 Sriram Karra <karra.etc@gmail.com>
##
......@@ -10,7 +10,7 @@
## This is an implementation of the Outlook PIMDB by extending the PIMDB
## abstract base class
import os, os.path, sys, logging, time, traceback
import os, os.path, string, sys, logging, time, traceback
from datetime import datetime
import iso8601, base64
......@@ -260,9 +260,8 @@ class MessageStore:
cf = OLContactsFolder(self.ol, eid, name, f, self)
self.add_to_folders(cf)
except TypeError, e:
logging.debug('Actual exception: %s', e)
logging.info('No Contacts Folder for message store: %s',
self.name)
logging.debug('No Contacts Folder for store: %s. (Ex: %s)',
self.name, e)
try:
(eid, name, f) = self.get_folder_obj(Folder.PR_IPM_NOTE_ENTRYID,
......@@ -270,9 +269,8 @@ class MessageStore:
nf = OLNotesFolder(self.ol, eid, name, f, self)
self.add_to_folders(nf)
except TypeError, e:
logging.debug('Actual exception: %s', e)
logging.info('No Notes Folder for message store: %s',
self.name)
logging.debug('No Notes Folder for store: %s. (Ex: %s)',
self.name, e)
try:
(eid, name, f) = self.get_folder_obj(Folder.PR_IPM_TASK_ENTRYID,
......@@ -280,9 +278,8 @@ class MessageStore:
tf = OLTasksFolder(self.ol, eid, name, f, self)
self.add_to_folders(tf)
except TypeError, e:
logging.debug('Actual exception: %s', e)
logging.info('No Tasks Folder for message store: %s',
self.name)
logging.debug('No Tasks Folder for store: %s. (Ex: %s)',
self.name, e)
## FIXME: We will have to do the above jig and dance for these
## Calendars at some point.
......@@ -336,6 +333,14 @@ class OLPIMDB(PIMDB):
self.msgstores = ms
return ms
def list_folders (self):
i = 1
for t in Folder.valid_types:
for f in self.get_folders(t):
logging.info(' %2d: %s', i, str(f))
i += 1
def new_folder (self, fname, type):
"""Create a new folder of specified type and return an id. The folder
will not contain any items"""
......@@ -394,10 +399,11 @@ class OLPIMDB(PIMDB):
##
def mapi_initialize (self):
logging.debug('Initalizing MAPI...')
logging.info('Initalizing MAPI...')
mapi.MAPIInitialize(None)
logging.info('Initalizing MAPI...done')
flags = (mapi.MAPI_EXTENDED | mapi.MAPI_USE_DEFAULT | MOD_FLAG)
logging.debug('Opening default profile in MAPI...')
logging.info('Opening default profile in MAPI...')
self.set_olsession(mapi.MAPILogonEx(0, "", None, flags))
logging.info('Opening default profile in MAPI...done')
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