diff --git a/agent/crawl/mail.py b/agent/crawl/mail.py index 489a49d..77b5008 100644 --- a/agent/crawl/mail.py +++ b/agent/crawl/mail.py @@ -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 diff --git a/agent/crawl/outlook.py b/agent/crawl/outlook.py index ac6b463..edca280 100644 --- a/agent/crawl/outlook.py +++ b/agent/crawl/outlook.py @@ -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') diff --git a/agent/crawl/outlook.txt b/agent/crawl/outlook.txt index 06317c1..d2da0c1 100644 --- a/agent/crawl/outlook.txt +++ b/agent/crawl/outlook.txt @@ -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: []; diff --git a/agent/main.py b/agent/main.py index 5ce5cc1..e6f520f 100755 --- a/agent/main.py +++ b/agent/main.py @@ -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(): diff --git a/agent/system/windows/api.py b/agent/system/windows/api.py index 525d86f..b937082 100644 --- a/agent/system/windows/api.py +++ b/agent/system/windows/api.py @@ -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 + diff --git a/agent/testing/__init__.py b/agent/testing/__init__.py new file mode 100644 index 0000000..4bc90fb --- /dev/null +++ b/agent/testing/__init__.py @@ -0,0 +1,4 @@ +""" +$Id$ +""" + diff --git a/agent/testing/winapi.py b/agent/testing/winapi.py index 8ec141a..5b91ab8 100644 --- a/agent/testing/winapi.py +++ b/agent/testing/winapi.py @@ -22,3 +22,4 @@ Fake Windows API functions for testing purposes. $Id$ """ +client = ctypes = win32api = win32process = win32con = None diff --git a/agent/tests.py b/agent/tests.py index e1ab46d..f7323f0 100755 --- a/agent/tests.py +++ b/agent/tests.py @@ -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