work in progress: fake windows API for testing with Outlook crawler

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2501 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2008-04-07 07:30:47 +00:00
parent e4108ed7d1
commit 671e15ddd5
8 changed files with 44 additions and 29 deletions

View file

@ -33,8 +33,8 @@ from twisted.internet.defer import succeed
class MailCrawler(Crawler): class MailCrawler(Crawler):
def __init__(self, params): def __init__(self, master):
self.params = params super(MailCrawler, self).__init__(master)
self.result = [] self.result = []
def collect(self, filter=None): def collect(self, filter=None):
@ -42,7 +42,7 @@ class MailCrawler(Crawler):
# d = self.crawlFolders() # d = self.crawlFolders()
d = succeed([]) d = succeed([])
return d return d
def fetchCriteria(self): def fetchCriteria(self):
pass pass

View file

@ -26,20 +26,21 @@ import re
from zope.interface import implements from zope.interface import implements
from twisted.internet import defer from twisted.internet import defer
import win32com.client #import win32com.client
import ctypes #import ctypes
import win32api, win32process, win32con #import win32api, win32process, win32con
from cybertools.agent.base.agent import Agent, Master from cybertools.agent.base.agent import Agent, Master
from cybertools.agent.crawl.mail import MailCrawler from cybertools.agent.crawl.mail import MailCrawler
from cybertools.agent.crawl.mail import MailResource from cybertools.agent.crawl.mail import MailResource
from cybertools.agent.components import agents from cybertools.agent.components import agents
from cybertools.agent.system.windows import api
# some constants # some constants
COMMASPACE = ', ' COMMASPACE = ', '
class OutlookCrawler(MailCrawler): class OutlookCrawler(MailCrawler):
keys = "" keys = ""
inbox = "" inbox = ""
subfolders = "" subfolders = ""
@ -54,7 +55,7 @@ class OutlookCrawler(MailCrawler):
else: else:
pass pass
#self.d.addErrback([]) #self.d.addErrback([])
return d return self.d
def fetchCriteria(self): def fetchCriteria(self):
criteria = self.params criteria = self.params
@ -107,7 +108,7 @@ class OutlookCrawler(MailCrawler):
def login(self): def login(self):
pass pass
def handleOutlookDialog(self): def handleOutlookDialog(self):
""" """
This function handles the outlook dialog, which appears if someone This function handles the outlook dialog, which appears if someone
@ -140,11 +141,11 @@ class OutlookCrawler(MailCrawler):
break break
def findOutlook(self): def findOutlook(self):
outlookFound = 0 outlookFound = False
try: try:
self.oOutlookApp = \ self.oOutlookApp = \
win32com.client.gencache.EnsureDispatch("Outlook.Application") api.client.gencache.EnsureDispatch("Outlook.Application")
outlookFound = 1 outlookFound = True
except: except:
pass pass
return outlookFound return outlookFound
@ -168,5 +169,5 @@ class OutlookCrawler(MailCrawler):
msg['To'] = COMMASPACE.join(recipients) msg['To'] = COMMASPACE.join(recipients)
msg.preamble = emails['Body'].encode('utf-8') msg.preamble = emails['Body'].encode('utf-8')
return msg return msg
agents.register(OutlookCrawler, Master, name='crawl.outlook') agents.register(OutlookCrawler, Master, name='crawl.outlook')

View file

@ -2,16 +2,18 @@
Agents for Job Execution and Communication Tasks Agents for Job Execution and Communication Tasks
================================================ ================================================
($Id$)
>>> from cybertools.agent.base.agent import Master
>>> config = ''' >>> config = '''
... controller(names=['core.sample']) ... controller(names=['core.sample'])
... scheduler(name='core') ... scheduler(name='core')
... logger(name='default', standard=30) ... logger(name='default', standard=30)
... system.winapi = 'testing'
... ''' ... '''
>>> master = Master(config) >>> from cybertools.agent.main import setup
>>> master.setup() >>> master = setup(config)
Starting agent application...
Using controllers core.sample.
OutlookCrawler OutlookCrawler
@ -33,19 +35,10 @@ dlls".
In the next step we request the start of a job, again via the controller. In the next step we request the start of a job, again via the controller.
>>> controller.enterJob('outlook', 'sample02') >>> controller.enterJob('sample', 'sample02')
The job is not executed immediately - we have to hand over control to The job is not executed immediately - we have to hand over control to
the twisted reactor first. the twisted reactor first.
>>> from cybertools.agent.crawl.outlook import OutlookCrawler
>>> from cybertools.agent.crawl.outlookstub import OutlookCrawlerStub
>>> OutlookCrawler.findOutlook = OutlookCrawlerStub.findOutlook
>>> OutlookCrawler = OutlookCrawlerStub
>>> from cybertools.agent.tests import tester >>> from cybertools.agent.tests import tester
>>> tester.iterate() >>> tester.iterate()
Returning reference to Outlook Application
Retrieving Parameters
Crawling Folders
loading mails from folder
Job 00001 completed; result: [];

View file

@ -56,7 +56,9 @@ def setupEnvironment(config):
from cybertools.agent.base import agent, control, job, log, schedule from cybertools.agent.base import agent, control, job, log, schedule
from cybertools.agent.core import agent, control, schedule from cybertools.agent.core import agent, control, schedule
from cybertools.agent.control import cmdline from cybertools.agent.control import cmdline
from cybertools.agent.crawl import base #, outlook from cybertools.agent.system.windows import api
api.setup(config)
from cybertools.agent.crawl import base, outlook
def startReactor(): def startReactor():

View file

@ -22,3 +22,17 @@ Conficuration-controlled import of Windows API functions.
$Id$ $Id$
""" """
def setup(config):
global client, ctypes, win32api, win32process, win32con
if config.system.winapi == 'testing':
from cybertools.agent.testing.winapi import \
client, ctypes, win32api, win32process, win32con
else:
try:
from win32com import client
import ctypes
import win32api, win32process, win32con
except ImportError:
from cybertools.agent.testing.winapi import \
client, ctypes, win32api, win32process, win32con

View file

@ -0,0 +1,4 @@
"""
$Id$
"""

View file

@ -22,3 +22,4 @@ Fake Windows API functions for testing purposes.
$Id$ $Id$
""" """
client = ctypes = win32api = win32process = win32con = None

View file

@ -43,7 +43,7 @@ def test_suite():
unittest.makeSuite(Test), unittest.makeSuite(Test),
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),
)) ))
return testSuite return testSuite