Changed bad return type self.result in outllok.py back to None
Added import for com_error type in outlook.py. added main_outlook.py in /testing to run tests against Outlook2000. Also added outlook.cfg in /testing which has the configuration data for main_outlook.py Removed outlook_real.txt and doctests line from tests.py git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2535 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									bd1c522b20
								
							
						
					
					
						commit
						acc93c09b5
					
				
					 5 changed files with 88 additions and 50 deletions
				
			
		|  | @ -27,6 +27,7 @@ from email import MIMEMultipart | ||||||
| 
 | 
 | ||||||
| from zope.interface import implements | from zope.interface import implements | ||||||
| from twisted.internet import defer | 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 | #The watsup import is needed as soon as we start handling the Outlook Pop-Up | ||||||
| #again | #again | ||||||
| #This should also be integrated within the wrapper-api for doctests | #This should also be integrated within the wrapper-api for doctests | ||||||
|  | @ -113,7 +114,7 @@ class OutlookCrawler(MailCrawler): | ||||||
|                         try: |                         try: | ||||||
|                             if isinstance(getattr(mail, key), (int, str, unicode)): |                             if isinstance(getattr(mail, key), (int, str, unicode)): | ||||||
|                                 self.keys.append(key) |                                 self.keys.append(key) | ||||||
|                         except: |                         except com_error: | ||||||
|                             pass |                             pass | ||||||
|                 record = {} |                 record = {} | ||||||
|                 for key in self.keys: |                 for key in self.keys: | ||||||
|  | @ -122,8 +123,7 @@ class OutlookCrawler(MailCrawler): | ||||||
|                 msg = self.createEmailMime(record) |                 msg = self.createEmailMime(record) | ||||||
|                 # Create a resource and append it to the result list |                 # Create a resource and append it to the result list | ||||||
|                 self.createResource(msg, folder, "Microsoft Office Outlook") |                 self.createResource(msg, folder, "Microsoft Office Outlook") | ||||||
|                 return self.result |                 yield None | ||||||
|                 #yield None --> nothing would be returned |  | ||||||
| 
 | 
 | ||||||
|     def login(self): |     def login(self): | ||||||
|         pass |         pass | ||||||
|  | @ -165,7 +165,7 @@ class OutlookCrawler(MailCrawler): | ||||||
|             self.oOutlookApp = \ |             self.oOutlookApp = \ | ||||||
|                 api.client.gencache.EnsureDispatch("Outlook.Application") |                 api.client.gencache.EnsureDispatch("Outlook.Application") | ||||||
|             outlookFound = True |             outlookFound = True | ||||||
|         except: |         except com_error: | ||||||
|             pass |             pass | ||||||
|         return outlookFound |         return outlookFound | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -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: [<cybertools.agent.crawl.mail.MailResource object at ...>]; |  | ||||||
							
								
								
									
										74
									
								
								agent/testing/main_outlook.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								agent/testing/main_outlook.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -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() | ||||||
							
								
								
									
										10
									
								
								agent/testing/outlook.cfg
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								agent/testing/outlook.cfg
									
										
									
									
									
										Normal file
									
								
							|  | @ -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' | ||||||
|  | @ -44,7 +44,6 @@ def test_suite(): | ||||||
|             DocFileSuite('README.txt', optionflags=flags), |             DocFileSuite('README.txt', optionflags=flags), | ||||||
|             DocFileSuite('crawl/README.txt', optionflags=flags), |             DocFileSuite('crawl/README.txt', optionflags=flags), | ||||||
|             DocFileSuite('crawl/outlook.txt', optionflags=flags), |             DocFileSuite('crawl/outlook.txt', optionflags=flags), | ||||||
|             DocFileSuite('crawl/outlook_real.txt', optionflags=flags), |  | ||||||
|     )) |     )) | ||||||
|     return testSuite |     return testSuite | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 scrat
						scrat