rearrange system startup so that components are not registered during initial import but via a controlled setup

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2500 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2008-04-07 06:36:48 +00:00
parent 5aee688a12
commit e4108ed7d1
14 changed files with 313 additions and 268 deletions

View file

@ -1,4 +1,4 @@
================================================
================================================
Agents for Job Execution and Communication Tasks
================================================
@ -101,8 +101,10 @@ configuration are provided by the controller.
So we are now ready to create a master agent and configure it by supplying
the path to the configuration file.
>>> from cybertools.agent.base.agent import Master
>>> master = Master(configFile)
>>> from cybertools.agent.main import setup
>>> master = setup(configFile)
Starting agent application...
Using controllers base.sample.
>>> configFile.close()
>>> master.config
@ -201,8 +203,9 @@ the twisted reactor.
... scheduler(name='core')
... logger(name='default', standard=30)
... '''
>>> master = Master(config)
>>> master.setup()
>>> master = setup(config)
Starting agent application...
Using controllers core.sample.
>>> master.scheduler
<cybertools.agent.core.schedule.Scheduler object ...>

View file

@ -1,10 +1,3 @@
"""
$Id$
"""
# register default adapters
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

View file

@ -60,22 +60,24 @@ class Master(Agent):
name = 'master'
scheduler = None
logger = None
def __init__(self, configuration):
if isinstance(configuration, Configurator):
config = configuration
self.config = configuration
else: # configuration is path to config file
config = self.config = Configurator()
config.load(configuration)
self.config = Configurator()
self.config.load(configuration)
self.master = self
self.controllers = []
self.children = {}
def setup(self):
config = self.config
self.logger = loggers(self, name=config.logger.name)
for n in config.controller.names:
self.controllers.append(controllers(self, n))
self.scheduler = schedulers(self, name=config.scheduler.name)
def setup(self):
for cont in self.controllers:
cont.setup()

View file

@ -17,7 +17,7 @@
#
"""
Common stuff.
Miscellaneous common stuff.
$Id$
"""

View file

@ -4,15 +4,15 @@ Agents for Job Execution and Communication Tasks
($Id$)
>>> from cybertools.agent.base.agent import Master
>>> config = '''
... controller(names=['core.sample'])
... scheduler(name='core')
... logger(name='default', standard=30)
... '''
>>> master = Master(config)
>>> master.setup()
>>> from cybertools.agent.main import setup
>>> master = setup(config)
Starting agent application...
Using controllers core.sample.
Crawler

View file

@ -19,7 +19,7 @@
"""
Outlook Crawler Class.
$Id: mail.py 2493 2008-04-03 11:17:37Z helmutm $
$Id$
"""
import re

View file

@ -1,20 +0,0 @@
from cybertools.agent.crawl.mail import MailCrawler
class OutlookCrawlerStub(MailCrawler):
def __init__(self):
pass
def findOutlook(self):
print "Returning reference to Outlook Application"
def fetchCriteria(self):
print "Retrieving Parameters"
def crawlFolders(self):
print "Crawling Folders"
self.loadMailsFromFolder()
def loadMailsFromFolder(self):
print "loading mails from folder"
self.createResource("SampleMail", "OutlookStubFolder", "OutlookStub")

View file

@ -41,11 +41,22 @@ def getConfig():
return config
def setup():
master = Master(getConfig())
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.crawl import base #, outlook
def startReactor():

4
agent/system/__init__.py Normal file
View file

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

View file

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

View file

@ -0,0 +1,24 @@
#
# 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
#
"""
Conficuration-controlled import of Windows API functions.
$Id$
"""

24
agent/testing/winapi.py Normal file
View file

@ -0,0 +1,24 @@
#
# 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
#
"""
Fake Windows API functions for testing purposes.
$Id$
"""

View file

@ -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