diff --git a/agent/crawl/outlook.py b/agent/crawl/outlook.py index 8fa3536..60983e9 100644 --- a/agent/crawl/outlook.py +++ b/agent/crawl/outlook.py @@ -27,6 +27,7 @@ from email import MIMEMultipart from zope.interface import implements from twisted.internet import defer +from pywintypes import com_error #The watsup import is needed as soon as we start handling the Outlook Pop-Up #again #This should also be integrated within the wrapper-api for doctests @@ -113,7 +114,7 @@ class OutlookCrawler(MailCrawler): try: if isinstance(getattr(mail, key), (int, str, unicode)): self.keys.append(key) - except: + except com_error: pass record = {} for key in self.keys: @@ -122,8 +123,7 @@ class OutlookCrawler(MailCrawler): msg = self.createEmailMime(record) # Create a resource and append it to the result list self.createResource(msg, folder, "Microsoft Office Outlook") - return self.result - #yield None --> nothing would be returned + yield None def login(self): pass @@ -165,7 +165,7 @@ class OutlookCrawler(MailCrawler): self.oOutlookApp = \ api.client.gencache.EnsureDispatch("Outlook.Application") outlookFound = True - except: + except com_error: pass return outlookFound diff --git a/agent/crawl/outlook_real.txt b/agent/crawl/outlook_real.txt deleted file mode 100644 index e485c61..0000000 --- a/agent/crawl/outlook_real.txt +++ /dev/null @@ -1,45 +0,0 @@ -================================================ -Agents for Job Execution and Communication Tasks -================================================ - - ($Id: outlook.txt 2522 2008-04-12 16:29:12Z scrat $) - - >>> config = ''' - ... controller(names=['core.sample']) - ... scheduler(name='core') - ... logger(name='default', standard=30) - ... system.winapi = 'use_outlook' - ... ''' - >>> from cybertools.agent.main import setup - >>> master = setup(config) - Starting agent application... - Using controllers core.sample. - - -OutlookCrawler -============== - -The agent uses Twisted's cooperative multitasking model. - -OutlookCrawler is derived from MailCrawler. The OutlookCrawler returns a deferred -which itself holds a list of MailResource Objects. - -Returns a deferred that must be supplied with a callback method (and in -most cases also an errback method). - -The TestCase here is using subsidiary methods which replace calls to the "real Outlook -dlls". - - >>> controller = master.controllers[0] - >>> controller.createAgent('crawl.outlook', 'sample02') - -In the next step we request the start of a job, again via the controller. - - >>> controller.enterJob('sample', 'sample02', params=dict(inbox=True)) - -The job is not executed immediately - we have to hand over control to -the twisted reactor first. - - >>> from cybertools.agent.tests import tester - >>> tester.iterate() - Job 00001 completed; result: []; diff --git a/agent/testing/main_outlook.py b/agent/testing/main_outlook.py new file mode 100644 index 0000000..9d3a15b --- /dev/null +++ b/agent/testing/main_outlook.py @@ -0,0 +1,74 @@ +#! /usr/bin/env python2.4 +# +# Copyright (c) 2008 Helmut Merz helmutm@cy55.de +# +# 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 +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +""" +Agent application. + +$Id$ +""" + +import os +from twisted.internet import reactor + +from cybertools.agent.base.agent import Master + + +application = None # contains application object if started via twistd + + +def getConfig(): + agentHome = os.path.abspath(os.path.dirname(__file__)) + configName = 'outlook.cfg' + configFile = open(os.path.join(agentHome, configName)) + config = configFile.read() + configFile.close() + return config + + +def setup(configInfo=None): + if configInfo is None: + configInfo = getConfig() + master = Master(configInfo) + setupEnvironment(master.config) + master.setup() + print 'Starting agent application...' + print 'Using controllers %s.' % ', '.join(master.config.controller.names) + return master + + +def setupEnvironment(config): + from cybertools.agent.base import agent, control, job, log, schedule + from cybertools.agent.core import agent, control, schedule + from cybertools.agent.control import cmdline + from cybertools.agent.system.windows import api + api.setup(config) + from cybertools.agent.crawl import base, outlook + + +def startReactor(): + reactor.run() + print 'Agent application has been stopped.' + + +if __name__ == '__main__': + master = setup() + controller = master.controllers[0] + controller.createAgent('crawl.outlook', 'sample02') + controller.enterJob('sample', 'sample02', params=dict(inbox=True)) + startReactor() diff --git a/agent/testing/outlook.cfg b/agent/testing/outlook.cfg new file mode 100644 index 0000000..113a193 --- /dev/null +++ b/agent/testing/outlook.cfg @@ -0,0 +1,10 @@ +# +# Standard configuration for agent application +# +# $Id: outlook.cfg 2496 2008-04-04 08:07:22Z helmutm $ +# + +controller(names=['core.sample']) +scheduler(name='core') +logger(name='default', standard=30) +system.winapi = 'use_outlook' \ No newline at end of file diff --git a/agent/tests.py b/agent/tests.py index 12487b1..f7323f0 100755 --- a/agent/tests.py +++ b/agent/tests.py @@ -44,7 +44,6 @@ def test_suite(): DocFileSuite('README.txt', optionflags=flags), DocFileSuite('crawl/README.txt', optionflags=flags), DocFileSuite('crawl/outlook.txt', optionflags=flags), - DocFileSuite('crawl/outlook_real.txt', optionflags=flags), )) return testSuite