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):
|
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):
|
||||||
|
|
|
@ -26,14 +26,15 @@ 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 = ', '
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
|
|
@ -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: [];
|
|
||||||
|
|
|
@ -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():
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
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$
|
$Id$
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
client = ctypes = win32api = win32process = win32con = None
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue