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:
parent
e4108ed7d1
commit
671e15ddd5
8 changed files with 44 additions and 29 deletions
|
@ -33,8 +33,8 @@ from twisted.internet.defer import succeed
|
|||
|
||||
class MailCrawler(Crawler):
|
||||
|
||||
def __init__(self, params):
|
||||
self.params = params
|
||||
def __init__(self, master):
|
||||
super(MailCrawler, self).__init__(master)
|
||||
self.result = []
|
||||
|
||||
def collect(self, filter=None):
|
||||
|
@ -42,7 +42,7 @@ class MailCrawler(Crawler):
|
|||
# d = self.crawlFolders()
|
||||
d = succeed([])
|
||||
return d
|
||||
|
||||
|
||||
def fetchCriteria(self):
|
||||
pass
|
||||
|
||||
|
|
|
@ -26,20 +26,21 @@ import re
|
|||
|
||||
from zope.interface import implements
|
||||
from twisted.internet import defer
|
||||
import win32com.client
|
||||
import ctypes
|
||||
import win32api, win32process, win32con
|
||||
#import win32com.client
|
||||
#import ctypes
|
||||
#import win32api, win32process, win32con
|
||||
|
||||
from cybertools.agent.base.agent import Agent, Master
|
||||
from cybertools.agent.crawl.mail import MailCrawler
|
||||
from cybertools.agent.crawl.mail import MailResource
|
||||
from cybertools.agent.components import agents
|
||||
from cybertools.agent.system.windows import api
|
||||
|
||||
# some constants
|
||||
COMMASPACE = ', '
|
||||
|
||||
class OutlookCrawler(MailCrawler):
|
||||
|
||||
|
||||
keys = ""
|
||||
inbox = ""
|
||||
subfolders = ""
|
||||
|
@ -54,7 +55,7 @@ class OutlookCrawler(MailCrawler):
|
|||
else:
|
||||
pass
|
||||
#self.d.addErrback([])
|
||||
return d
|
||||
return self.d
|
||||
|
||||
def fetchCriteria(self):
|
||||
criteria = self.params
|
||||
|
@ -107,7 +108,7 @@ class OutlookCrawler(MailCrawler):
|
|||
|
||||
def login(self):
|
||||
pass
|
||||
|
||||
|
||||
def handleOutlookDialog(self):
|
||||
"""
|
||||
This function handles the outlook dialog, which appears if someone
|
||||
|
@ -140,11 +141,11 @@ class OutlookCrawler(MailCrawler):
|
|||
break
|
||||
|
||||
def findOutlook(self):
|
||||
outlookFound = 0
|
||||
outlookFound = False
|
||||
try:
|
||||
self.oOutlookApp = \
|
||||
win32com.client.gencache.EnsureDispatch("Outlook.Application")
|
||||
outlookFound = 1
|
||||
api.client.gencache.EnsureDispatch("Outlook.Application")
|
||||
outlookFound = True
|
||||
except:
|
||||
pass
|
||||
return outlookFound
|
||||
|
@ -168,5 +169,5 @@ class OutlookCrawler(MailCrawler):
|
|||
msg['To'] = COMMASPACE.join(recipients)
|
||||
msg.preamble = emails['Body'].encode('utf-8')
|
||||
return msg
|
||||
|
||||
|
||||
agents.register(OutlookCrawler, Master, name='crawl.outlook')
|
||||
|
|
|
@ -2,16 +2,18 @@
|
|||
Agents for Job Execution and Communication Tasks
|
||||
================================================
|
||||
|
||||
|
||||
>>> from cybertools.agent.base.agent import Master
|
||||
($Id$)
|
||||
|
||||
>>> config = '''
|
||||
... controller(names=['core.sample'])
|
||||
... scheduler(name='core')
|
||||
... logger(name='default', standard=30)
|
||||
... system.winapi = 'testing'
|
||||
... '''
|
||||
>>> master = Master(config)
|
||||
>>> master.setup()
|
||||
>>> from cybertools.agent.main import setup
|
||||
>>> master = setup(config)
|
||||
Starting agent application...
|
||||
Using controllers core.sample.
|
||||
|
||||
|
||||
OutlookCrawler
|
||||
|
@ -33,19 +35,10 @@ dlls".
|
|||
|
||||
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 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
|
||||
>>> tester.iterate()
|
||||
Returning reference to Outlook Application
|
||||
Retrieving Parameters
|
||||
Crawling Folders
|
||||
loading mails from folder
|
||||
Job 00001 completed; result: [];
|
||||
|
|
|
@ -56,7 +56,9 @@ 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.crawl import base #, outlook
|
||||
from cybertools.agent.system.windows import api
|
||||
api.setup(config)
|
||||
from cybertools.agent.crawl import base, outlook
|
||||
|
||||
|
||||
def startReactor():
|
||||
|
|
|
@ -22,3 +22,17 @@ Conficuration-controlled import of Windows API functions.
|
|||
$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
|
||||
|
||||
|
|
4
agent/testing/__init__.py
Normal file
4
agent/testing/__init__.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
"""
|
||||
$Id$
|
||||
"""
|
||||
|
|
@ -22,3 +22,4 @@ Fake Windows API functions for testing purposes.
|
|||
$Id$
|
||||
"""
|
||||
|
||||
client = ctypes = win32api = win32process = win32con = None
|
||||
|
|
|
@ -43,7 +43,7 @@ def test_suite():
|
|||
unittest.makeSuite(Test),
|
||||
DocFileSuite('README.txt', optionflags=flags),
|
||||
DocFileSuite('crawl/README.txt', optionflags=flags),
|
||||
#DocFileSuite('crawl/outlook.txt', optionflags=flags),
|
||||
DocFileSuite('crawl/outlook.txt', optionflags=flags),
|
||||
))
|
||||
return testSuite
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue