[Checkins]
SVN: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/
Some code clean up.
Jürgen Kartnaller
juergen at kartnaller.at
Sun Sep 3 06:51:31 EDT 2006
Log message for revision 69944:
Some code clean up.
New features :
- sample generator manager stores data sources
- generators can get sample data from different sources
Changed:
U z3c.sampledata/branches/jukart-features/src/z3c/sampledata/README.txt
U z3c.sampledata/branches/jukart-features/src/z3c/sampledata/browser/README.txt
A z3c.sampledata/branches/jukart-features/src/z3c/sampledata/browser/testmanager.zcml
U z3c.sampledata/branches/jukart-features/src/z3c/sampledata/browser/views.py
U z3c.sampledata/branches/jukart-features/src/z3c/sampledata/configure.zcml
U z3c.sampledata/branches/jukart-features/src/z3c/sampledata/ftesting.zcml
U z3c.sampledata/branches/jukart-features/src/z3c/sampledata/ftests.py
A z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/
A z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/__init__.py
A z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/configure.zcml
A z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/intids.py
A z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/pau.py
A z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/principals.py
A z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/principals.txt
A z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/site.py
U z3c.sampledata/branches/jukart-features/src/z3c/sampledata/interfaces.py
U z3c.sampledata/branches/jukart-features/src/z3c/sampledata/manager.py
U z3c.sampledata/branches/jukart-features/src/z3c/sampledata/meta.zcml
U z3c.sampledata/branches/jukart-features/src/z3c/sampledata/metaconfigure.py
U z3c.sampledata/branches/jukart-features/src/z3c/sampledata/metadirectives.py
D z3c.sampledata/branches/jukart-features/src/z3c/sampledata/principal.py
D z3c.sampledata/branches/jukart-features/src/z3c/sampledata/principal.txt
D z3c.sampledata/branches/jukart-features/src/z3c/sampledata/site.py
D z3c.sampledata/branches/jukart-features/src/z3c/sampledata/site.zcml
D z3c.sampledata/branches/jukart-features/src/z3c/sampledata/testprincipals.txt
U z3c.sampledata/branches/jukart-features/src/z3c/sampledata/tests.py
-=-
Modified: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/README.txt
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/README.txt 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/README.txt 2006-09-03 10:51:30 UTC (rev 69944)
@@ -1,7 +1,17 @@
-==========================================
-Pluggable sample data framework for Lovely
-==========================================
+===============================
+Pluggable sample data framework
+===============================
+Creating a good testing environment is the most important way to create
+high quality software.
+
+But most of the time it is a pain !
+
+This package tries to do the best to support the development of sample
+data generators.
+A sample data generator is a pluggable tool to create data needed for tests.
+
+
There are several goals to this framework:
- provide the developers with an automatic setup that is close to
@@ -19,7 +29,7 @@
Generators
----------
-A generator generates a setup.
+A generator generates sample data.
>>> from zope import interface
>>> from zope import component
@@ -27,75 +37,132 @@
>>> class GeneratePrincipals(object):
... interface.implements(ISampleDataPlugin)
- ... name = 'z3c.principals'
... dependencies = []
... schema = None
- ... def generate(self, context, param={}, seed=None):
- ... if context != 'This is a site':
- ... print 'Expected string "This is a site" !'
+ ... def generate(self, context, param={}, dataSource=None, seed=None):
+ ... print self.__class__.__name__
+ ... if dataSource is not None:
+ ... for data in dataSource:
+ ... print '- %s'%data['login']
>>> principalPlugin = GeneratePrincipals()
-For the sample manager the plugin must be registered as a utility.
-
- >>> component.provideUtility(principalPlugin, ISampleDataPlugin,'z3c.principals')
-
For our tests we provide another generator :
>>> class GenerateSite(object):
... interface.implements(ISampleDataPlugin)
- ... name = 'z3c.site'
... dependencies = []
... schema = None
- ... def generate(self, context, param={}, seed=None):
- ... return 'This is a site'
+ ... def generate(self, context, param={}, dataSource=None, seed=None):
+ ... if 'sitename' in param:
+ ... print 'This is site %r'%param['sitename']
+ ... else:
+ ... print self.__class__.__name__
+ ... return 'I am from the site'
>>> sitePlugin = GenerateSite()
- >>> component.provideUtility(sitePlugin, ISampleDataPlugin,'z3c.site')
Generator Manager
-----------------
-A generator manager groups a collection of generators and allows to define
-dependencies between generator.
+A generator manager groups a collection of generators.
+The manager allows to :
+ - define dependencies between generators
+
+ - define data connections between dependent generators
+
+ - provide default configuration data
+
>>> from z3c.sampledata import Manager
>>> manager = Manager('manager', '')
+
+Generator Plugin
+~~~~~~~~~~~~~~~~
+
+For the manager our sample generators must be registered as named utilities.
+
+ >>> component.provideUtility(sitePlugin,
+ ... ISampleDataPlugin,'z3c.sampledata.site')
+ >>> component.provideUtility(principalPlugin,
+ ... ISampleDataPlugin,'z3c.sampledata.principals')
+
+
+Generating Sample Data
+~~~~~~~~~~~~~~~~~~~~~~
+
Now we can add generators to the manager.
-In addition to the "hardwired" dependencies in each generator it is possible
-to add dependencies in the generator manager.
- >>> manager.add('z3c.principals',
- ... dependsOn=['z3c.site',],
- ... contextFrom='z3c.site')
+ >>> manager.add('z3c.sampledata.principals',
+ ... dependsOn=['z3c.sampledata.site',],
+ ... contextFrom='z3c.sampledata.site')
+In addition to the "hardwired" dependencies defined by the dependencies
+property in each generator it is possible to add dependencies in the generator
+manager.
+
A manager provides it's generators.
>>> manager.generators.keys()
- ['z3c.principals']
+ ['z3c.sampledata.principals']
We can tell the manager to generate all samples.
-There is no need to add the sample generator 'z3c.site', it is added
-automatically because of the dependency of 'z3c.principals'.
+There is no need to add the sample generator 'z3c.sampledata.site', it is added
+automatically because of the dependency of 'z3c.sampledata.principals'.
>>> infos = manager.generate(context=None, param={}, seed='something')
+ GenerateSite
+ GeneratePrincipals
+
>>> [info.name for info in infos]
- ['z3c.site', 'z3c.principals']
+ ['z3c.sampledata.site', 'z3c.sampledata.principals']
-Cycles are detected.
+Parameters for the sample generators
+------------------------------------
+
+To have more control over the sample generation process it is possible to
+setup parameters for the generators.
+
>>> manager = Manager('manager', '')
- >>> manager.add('z3c.principals',
- ... dependsOn=['z3c.site',],
- ... contextFrom='z3c.site')
- >>> manager.add('z3c.site',
- ... dependsOn=['z3c.principals',])
+ >>> manager.add('z3c.sampledata.site',
+ ... param={'sitename':'samplesite'})
+
+ >>> manager.add('z3c.sampledata.principals',
+ ... dependsOn=['z3c.sampledata.site',],
+ ... contextFrom='z3c.sampledata.site')
+
>>> infos = manager.generate(context=None, param={}, seed='something')
+ This is site 'samplesite'
+ GeneratePrincipals
+
+It is also possible to overwrite the parameters from the configuration.
+
+ >>> infos = manager.generate(context=None,
+ ... param={'z3c.sampledata.site':
+ ... {'sitename':'managers site'}},
+ ... seed='something')
+ This is site 'managers site'
+ GeneratePrincipals
+
+
+Cycles in the generator definition
+----------------------------------
+
+ >>> manager = Manager('manager', '')
+ >>> manager.add('z3c.sampledata.principals',
+ ... dependsOn=['z3c.sampledata.site',],
+ ... contextFrom='z3c.sampledata.site')
+ >>> manager.add('z3c.sampledata.site',
+ ... dependsOn=['z3c.sampledata.principals',])
+
+ >>> infos = manager.generate(context=None, param={}, seed='something')
Traceback (most recent call last):
...
- CyclicDependencyError: cyclic dependency at 'z3c.principals'
+ CyclicDependencyError: cyclic dependency at 'z3c.sampledata.principals'
+
A test for a complex dependency.
>>> class Generator(object):
@@ -103,7 +170,7 @@
... name = 'generator'
... dependencies = []
... schema = None
- ... def generate(self, context, param={}, seed=None):
+ ... def generate(self, context, param={}, dataSource=None, seed=None):
... return 'I am a generator'
>>> component.provideUtility(Generator(), ISampleDataPlugin,'g.1')
>>> component.provideUtility(Generator(), ISampleDataPlugin,'g.2')
@@ -117,6 +184,67 @@
['g.1', 'g.2', 'g.3']
+Sample Data Source
+------------------
+
+A sample data generator usually gets its sample data from a data source.
+Mostly it is necessary to have different data sources for different uses.
+
+As an example, it is always a pain if the sample data for the tests use the
+same data as the UI uses later to provide data for the customer to click
+around.
+
+ >>> manager = Manager('manager', '')
+
+ >>> manager.addSource('z3c.datasource.principals',
+ ... data=[{'login':'jukart', 'password':'trakuj'},
+ ... {'login':'srichter', 'password':'rethcirs'}])
+
+ >>> manager.add('z3c.sampledata.principals',
+ ... dataSource='z3c.datasource.principals',
+ ... dependsOn=['z3c.sampledata.site',],
+ ... contextFrom='z3c.sampledata.site')
+
+ >>> infos = manager.generate(context=None, param={}, seed='something')
+ GenerateSite
+ GeneratePrincipals
+ - jukart
+ - srichter
+
+
+It is also possible to use adapters to act as a data source.
+
+ >>> manager = Manager('manager', '')
+
+ >>> class IPrincipalDataSource(interface.Interface):
+ ... pass
+
+ >>> def principalDataFactory(object):
+ ... return [{'login':'jukart', 'password':'trakuj'},
+ ... {'login':'srichter', 'password':'rethcirs'}]
+
+ >>> component.provideAdapter(
+ ... factory=principalDataFactory,
+ ... adapts=(ISampleDataPlugin,),
+ ... provides=IPrincipalDataSource,
+ ... name='testprincipals')
+
+ >>> manager.addSource('z3c.datasource.principals',
+ ... adapterName='testprincipals',
+ ... adaptTo=IPrincipalDataSource)
+
+ >>> manager.add('z3c.sampledata.principals',
+ ... dataSource='z3c.datasource.principals',
+ ... dependsOn=['z3c.sampledata.site',],
+ ... contextFrom='z3c.sampledata.site')
+
+ >>> infos = manager.generate(context=None, param={}, seed='something')
+ GenerateSite
+ GeneratePrincipals
+ - jukart
+ - srichter
+
+
BuiltIn sample generators
-------------------------
@@ -128,7 +256,7 @@
Creates a simple folder and makes it a site.
- >>> from z3c.sampledata.site import SampleSite
+ >>> from z3c.sampledata.generator.site import SampleSite
>>> component.provideUtility(SampleSite(),
... ISampleDataPlugin,
... 'z3c.sampledata.site')
@@ -136,7 +264,10 @@
>>> manager.add('z3c.sampledata.site')
>>> from zope.app.folder.folder import Folder
>>> baseContext = Folder()
- >>> infos = manager.generate(context=baseContext, param={'sitename':'test'}, seed=None)
+ >>> infos = manager.generate(context=baseContext,
+ ... param={'z3c.sampledata.site':
+ ... {'sitename':'test'}},
+ ... seed=None)
>>> [info.name for info in infos]
['z3c.sampledata.site']
>>> 'test' in baseContext
@@ -149,7 +280,7 @@
Creates an IntIds utility inside the site given as context.
This generator depends on the creation of a site.
- >>> from z3c.sampledata.site import SampleIntIds
+ >>> from z3c.sampledata.generator.intids import SampleIntIds
>>> component.provideUtility(SampleIntIds(),
... ISampleDataPlugin,
... 'z3c.sampledata.intids')
@@ -157,7 +288,10 @@
... contextFrom='z3c.sampledata.site',
... )
>>> baseContext = Folder()
- >>> infos = manager.generate(context=baseContext, param={'sitename':'intids'}, seed=None)
+ >>> infos = manager.generate(context=baseContext,
+ ... param={'z3c.sampledata.site':
+ ... {'sitename':'intids'}},
+ ... seed=None)
>>> [info.name for info in infos]
['z3c.sampledata.site', 'z3c.sampledata.intids']
>>> site = baseContext['intids']
@@ -165,20 +299,28 @@
<zope.app.intid.IntIds object at ...>
-How do I create a sample data plugin?
--------------------------------------
+Pluggable Authentication
+~~~~~~~~~~~~~~~~~~~~~~~~
-In order to create a sample data plugin, you only have to register a
-named utility that implements the interface
-`z3c.sampledata.interfaces.ISampleDataPlugin`.
+Creates a pluggable authentication uitility inside the site given as context.
+This generator depends on the creation of a site.
-A plugin must provide :
+ >>> from z3c.sampledata.generator.pau import SamplePau
+ >>> component.provideUtility(SamplePau(),
+ ... ISampleDataPlugin,
+ ... 'z3c.sampledata.pau')
+ >>> manager = Manager('manager', '')
+ >>> manager.add('z3c.sampledata.site')
+ >>> manager.add('z3c.sampledata.pau',
+ ... contextFrom='z3c.sampledata.site',
+ ... )
+ >>> baseContext = Folder()
+ >>> infos = manager.generate(context=baseContext,
+ ... param={'z3c.sampledata.site':
+ ... {'sitename':'pau'}},
+ ... seed=None)
- - name
- - dependencies on other plugins (list of names of ISampleDataPlugin utilities)
- - schema for the parameters
-
How to setup configuration for the generator manager
----------------------------------------------------
@@ -217,8 +359,8 @@
</configure>
-Data Generator
-==============
+Data Sources
+============
This package implements the base functionality for data generators.
A data generator is used to provide the raw data for a sample generator.
Modified: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/browser/README.txt
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/browser/README.txt 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/browser/README.txt 2006-09-03 10:51:30 UTC (rev 69944)
@@ -10,14 +10,26 @@
>>> browser.addHeader('Authorization','Basic mgr:mgrpw')
>>> browser.handleErrors = False
+We select the sample data manager overview.
+
>>> browser.open('http://localhost/@@managesamples.html')
- >>> link = browser.getLink(text='samplemanager')
- >>> link.click()
+
+Now we select our samplemanager.
+
+ >>> browser.getLink(text='samplemanager').click()
>>> browser.url
'http://localhost/@@generatesample.html?manager=samplemanager'
+We are now in the configuration view for the selected manager.
+
>>> browser.getControl(name='generator.seed').value = 'lovely'
- >>> browser.getControl(name='z3c.principals.minPrincipals').value = '2'
- >>> browser.getControl(name='z3c.principals.maxPrincipals').value = '34'
+ >>> browser.getControl(
+ ... name='z3c.sampledata.site.sitename').value = 'testsite'
+ >>> browser.getControl(
+ ... name='z3c.sampledata.principals.minPrincipals').value = '2'
+ >>> browser.getControl(
+ ... name='z3c.sampledata.principals.maxPrincipals').value = '34'
+ >>> browser.getControl(
+ ... name='z3c.sampledata.principals.pauLocation').value = 'default/pau'
>>> browser.getControl('Generate').click()
Added: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/browser/testmanager.zcml
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/browser/testmanager.zcml 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/browser/testmanager.zcml 2006-09-03 10:51:30 UTC (rev 69944)
@@ -0,0 +1,34 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+ xmlns:browser="http://namespaces.zope.org/browser"
+ i18n_domain="zope">
+
+ <SampleManager
+ name="samplemanager"
+ >
+
+ <datasource
+ name="z3c.sampledata.principals"
+ adapterName="z3c.sampledata.principals"
+ adapterInterface="z3c.sampledata.ftests.IPrincipalDataSource"
+ />
+
+ <generator
+ name="z3c.sampledata.site"
+ />
+ <generator
+ name="z3c.sampledata.intids"
+ contextFrom="z3c.sampledata.site"
+ />
+ <generator
+ name="z3c.sampledata.pau"
+ contextFrom="z3c.sampledata.site"
+ />
+ <generator
+ name="z3c.sampledata.principals"
+ dataSource="z3c.sampledata.principals"
+ dependsOn="z3c.sampledata.pau"
+ contextFrom="z3c.sampledata.site"
+ />
+ </SampleManager>
+
+</configure>
Property changes on: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/browser/testmanager.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/browser/views.py
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/browser/views.py 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/browser/views.py 2006-09-03 10:51:30 UTC (rev 69944)
@@ -77,13 +77,19 @@
def handle_generate_action(self, action, data):
managerName = self.request['manager']
manager = component.getUtility(ISampleManager, name=managerName)
+ generatorData = {}
for subform in self.subforms:
subform.update()
- errors = form.getWidgetsData(subform.widgets, subform.prefix, data)
- seed = None
- if 'seed' in data:
- seed = data['seed']
- self.workedOn = manager.generate(self.context, data, seed)
+ formData = {}
+ errors = form.getWidgetsData(subform.widgets,
+ subform.prefix,
+ formData)
+ generatorData[subform.prefix] = formData
+ gen = data.get('generator', {})
+ seed = gen.get('seed', None)
+ self.workedOn = manager.generate(context=self.context,
+ param=generatorData,
+ seed=seed)
self.workDone = True
self.actions = []
Modified: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/configure.zcml
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/configure.zcml 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/configure.zcml 2006-09-03 10:51:30 UTC (rev 69944)
@@ -1,18 +1,6 @@
<configure xmlns="http://namespaces.zope.org/zope">
- <utility
- name="z3c.site"
- factory="z3c.sampledata.site.SampleSite"
- provides="z3c.sampledata.interfaces.ISampleDataPlugin"
- />
-
- <utility
- name="z3c.principals"
- factory="z3c.sampledata.principal.SamplePrincipals"
- provides="z3c.sampledata.interfaces.ISampleDataPlugin"
- />
-
- <include file="site.zcml" />
+ <include package=".generator" />
<include package=".browser" />
</configure>
Modified: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/ftesting.zcml
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/ftesting.zcml 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/ftesting.zcml 2006-09-03 10:51:30 UTC (rev 69944)
@@ -21,49 +21,20 @@
<include package="z3c.sampledata"/>
<role id="zope.Anonymous" title="Everybody"
- description="All users have this role implicitly" />
+ description="All users have this role implicitly" />
<role id="zope.Manager" title="Site Manager" />
<grantAll role="zope.Manager" />
+
<principal
- id="zope.manager"
- title="Administrator"
- login="mgr"
- password="mgrpw" />
+ id="zope.manager"
+ title="Administrator"
+ login="mgr"
+ password="mgrpw" />
<grant
- role="zope.Manager"
- principal="zope.manager"
- />
-
- <unauthenticatedPrincipal
- id="zope.anybody"
- title="Unauthenticated User" />
+ role="zope.Manager"
+ principal="zope.manager"
+ />
- <unauthenticatedGroup
- id="zope.Anybody"
- title="Unauthenticated Users"
- />
+ <include package="z3c.sampledata.browser" file="testmanager.zcml" />
- <authenticatedGroup
- id="zope.Authenticated"
- title="Authenticated Users"
- />
-
- <everybodyGroup
- id="zope.Everybody"
- title="All Users"
- />
-
- <grant permission="zope.View"
- role="zope.Anonymous" />
- <grant permission="zope.app.dublincore.view"
- role="zope.Anonymous" />
-
- <SampleManager
- name="samplemanager"
- >
- <generator
- name="z3c.principals"
- />
- </SampleManager>
-
</configure>
Modified: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/ftests.py
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/ftests.py 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/ftests.py 2006-09-03 10:51:30 UTC (rev 69944)
@@ -1,5 +1,7 @@
import unittest
+from zope import interface
+
import zope.event
from zope.lifecycleevent import ObjectCreatedEvent
@@ -13,6 +15,15 @@
functional.defineLayer('TestLayer', 'ftesting.zcml')
+class IPrincipalDataSource(interface.Interface):
+ pass
+
+def principalDataFactory(object):
+ return [{'login':'jukart', 'password':'trakuj'},
+ {'login':'srichter', 'password':'rethcirs'}]
+
+
+
def setUp(test):
site = functional.getRootFolder()
sm = site.getSiteManager()
Added: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/__init__.py
===================================================================
Property changes on: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/configure.zcml
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/configure.zcml 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/configure.zcml 2006-09-03 10:51:30 UTC (rev 69944)
@@ -0,0 +1,37 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+ <!-- Some useful sample generators -->
+
+ <utility
+ name="z3c.sampledata.site"
+ factory=".site.SampleSite"
+ provides="z3c.sampledata.interfaces.ISampleDataPlugin"
+ />
+
+ <utility
+ name="z3c.sampledata.intids"
+ factory=".intids.SampleIntIds"
+ provides="z3c.sampledata.interfaces.ISampleDataPlugin"
+ />
+
+ <utility
+ name="z3c.sampledata.pau"
+ factory=".pau.SamplePau"
+ provides="z3c.sampledata.interfaces.ISampleDataPlugin"
+ />
+
+ <utility
+ name="z3c.sampledata.principals"
+ factory=".principals.SamplePrincipals"
+ provides="z3c.sampledata.interfaces.ISampleDataPlugin"
+ />
+
+ <!-- A default data source provider for principals -->
+ <adapter
+ factory=".principals.defaultPrincipalDataFactory"
+ for="z3c.sampledata.interfaces.ISampleDataPlugin"
+ provides=".principals.IPrincipalDataSource"
+ />
+
+</configure>
+
Property changes on: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/configure.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/intids.py
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/intids.py 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/intids.py 2006-09-03 10:51:30 UTC (rev 69944)
@@ -0,0 +1,60 @@
+##############################################################################
+#
+# Copyright (c) 2006 Lovely Systems and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Sample generator to create a intids utility inside a site.
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+import zope.interface
+import zope.component
+import zope.event
+import zope.schema
+import zope.lifecycleevent
+from zope.interface import implements
+
+from zope.app.intid import IntIds
+from zope.app.intid.interfaces import IIntIds
+
+from z3c.sampledata.interfaces import ISampleDataPlugin
+
+from z3c.sampledata import _
+
+
+class SampleIntIds(object):
+
+ implements(ISampleDataPlugin)
+
+ dependencies = []
+ schema = None
+
+ def generate(self, context, param={}, dataSource={}, seed=None):
+ """Generate an IntId utility inside context.
+
+ 'context' must be a site manager.
+ """
+ if 'omit' in param or context is None:
+ return None
+ sm = context.getSiteManager()
+ default = sm['default']
+
+ if 'intid' not in default:
+ intid = IntIds()
+ zope.event.notify(zope.lifecycleevent.ObjectCreatedEvent(intid))
+ default['intid'] = intid
+ sm.registerUtility(intid, IIntIds)
+ return intid
+ else:
+ return default['intid']
+
Property changes on: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/intids.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/pau.py
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/pau.py 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/pau.py 2006-09-03 10:51:30 UTC (rev 69944)
@@ -0,0 +1,72 @@
+##############################################################################
+#
+# Copyright (c) 2006 Lovely Systems and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Sample generator to create a pau inside a site.
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+import zope.interface
+import zope.component
+import zope.event
+import zope.schema
+import zope.lifecycleevent
+from zope.interface import implements
+
+from zope.app.authentication.authentication import PluggableAuthentication
+from zope.app.security.interfaces import IAuthentication
+from zope.app.authentication.interfaces import IAuthenticatorPlugin
+from zope.app.authentication.principalfolder import PrincipalFolder
+
+from z3c.sampledata.interfaces import ISampleDataPlugin
+
+from z3c.sampledata import _
+
+
+class SamplePau(object):
+
+ implements(ISampleDataPlugin)
+
+ dependencies = []
+ schema = None
+
+ def generate(self, context, param={}, dataSource={}, seed=None):
+ """Generate a pay utility inside context.
+
+ 'context' must be a site manager.
+ """
+ if 'omit' in param or context is None:
+ return None
+ sm = context.getSiteManager()
+ default = sm['default']
+
+ if 'pau' not in default:
+ pau = PluggableAuthentication()
+ zope.event.notify(zope.lifecycleevent.ObjectCreatedEvent(pau))
+ default['pau'] = pau
+ sm.registerUtility(pau, IAuthentication)
+ # create a principal folder
+ pfNames = (u'members',)
+ pau.authenticatorPlugins = pfNames
+ for name in pfNames:
+ if name in pau:
+ continue
+ pf = PrincipalFolder(name +'.')
+ zope.event.notify(zope.lifecycleevent.ObjectCreatedEvent(pf))
+ default['pau'][name] = pf
+ sm.registerUtility(pf, IAuthenticatorPlugin, name)
+ return pau
+ else:
+ return default['pau']
+
Property changes on: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/pau.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/principals.py
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/principals.py 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/principals.py 2006-09-03 10:51:30 UTC (rev 69944)
@@ -0,0 +1,158 @@
+##############################################################################
+#
+# Copyright (c) 2006 Lovely Systems and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Sample generator to create principals
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+import zope.interface
+import zope.component
+import zope.event
+import zope.schema
+import zope.lifecycleevent
+from zope.interface import implements
+from zope.security.proxy import removeSecurityProxy
+from zope.app.security.interfaces import IAuthentication
+from zope.app.authentication import principalfolder
+from zope.app.component import hooks
+
+from z3c.sampledata.interfaces import ISampleDataPlugin
+
+from z3c.sampledata import _
+
+
+class IPrincipalDataSource(zope.interface.Interface):
+ """A marker interface for principal data source adapters"""
+
+def defaultPrincipalDataFactory(object):
+ return [['batlogg', 'Jodok Batlogg', 'bJB'],
+ ['jukart', 'Juergen Kartnaller', 'jJK'],
+ ['dobee', 'Bernd Dorn', 'dBD'],
+ ['srichter', 'Stephan Richter', 'sSR'],
+ ['byzo', 'Michael Breidenbruecker', 'bMB'],
+ ['oli', 'Oliver Ruhm', 'oOR']]
+
+
+class ISamplePrincipalParameters(zope.interface.Interface):
+ """The parameters for the sample principal generator."""
+
+ minPrincipals = zope.schema.Int(
+ title = _(u'Min principals'),
+ description = _(u'Create at least this number of pricipals from'
+ u' the principals file.\n'
+ u'This has higher priority than maxPricipals.\n'
+ u'-1 : create all principals from the datasource.'
+ ),
+ required = False,
+ default = -1,
+ )
+
+ maxPrincipals = zope.schema.Int(
+ title = _(u'Max principals'),
+ description = _(u'The maximum number of principals to create.\n'
+ u'Uses the first principals from the datasource.'
+ ),
+ required = False,
+ default = -1,
+ )
+
+ pauLocation = zope.schema.TextLine(
+ title = _(u'PAU location'),
+ description = _(u'Path to the PAU inside the site manager.'),
+ required = False,
+ default = u'default/pau',
+ )
+
+ passwordManager = zope.schema.TextLine(
+ title = _(u'Password Manager'),
+ description = _(u'The password manager to use.'),
+ required = False,
+ default = u'SHA1',
+ )
+
+
+class SamplePrincipals(object):
+ """Create principals inside a site manager.
+
+ context : site
+ return : pau in which the principals where created
+ """
+
+ implements(ISampleDataPlugin)
+
+ dependencies = []
+ schema = ISamplePrincipalParameters
+
+ maxPrincipals = None
+ minPrincipals = None
+
+ def generate(self, context, param={}, dataSource=[], seed=None):
+ """Generate sample pricipals"""
+ if 'omit' in param or context is None:
+ return None
+ self.minPrincipals = int(param['minPrincipals'])
+ if self.minPrincipals<0:
+ self.minPrincipals = None
+ self.maxPrincipals = int(param['maxPrincipals'])
+ if self.maxPrincipals<0:
+ self.maxPrincipals = None
+ originalSite = hooks.getSite()
+ hooks.setSite(context)
+ sm = zope.component.getSiteManager(context)
+ self.pau = sm
+ for loc in param['pauLocation'].split('/'):
+ self.pau = self.pau[loc]
+ self.passwordManagerName = param['passwordManager']
+
+ numCreated = 0
+ self.logins = []
+ if dataSource:
+ for info in dataSource:
+ if ( self.maxPrincipals is not None
+ and numCreated>=self.maxPrincipals):
+ break
+ login = unicode(info[0])
+ if login in self.logins:
+ # ignore duplicate principals
+ continue
+ self._createPrincipal(info)
+ numCreated+=1
+
+ if ( self.minPrincipals is not None
+ and numCreated<self.minPrincipals):
+ for i in range(self.minPrincipals-numCreated):
+ info = ['login%i'%i,'name%i'%i,'%i'%i]
+ self._createPrincipal(info)
+
+ hooks.setSite(originalSite)
+
+ return self.pau
+
+ def _createPrincipal(self, info):
+ login = unicode(info[0])
+ self.logins.append(login)
+ if login in self.pau['members']:
+ return
+ name = unicode(info[1])
+ password = unicode(info[2])
+ principal = principalfolder.InternalPrincipal(
+ login,
+ password,
+ name,
+ passwordManagerName=self.passwordManagerName)
+ zope.event.notify(
+ zope.lifecycleevent.ObjectCreatedEvent(principal))
+ self.pau['members'][login] = principal
+
Property changes on: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/principals.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/principals.txt
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/principals.txt 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/principals.txt 2006-09-03 10:51:30 UTC (rev 69944)
@@ -0,0 +1,88 @@
+================================
+Principal Sample Data Generation
+================================
+
+This gerator creates principals from a data source.
+
+ >>> from z3c.sampledata.generator.principals import SamplePrincipals
+ >>> generator = SamplePrincipals()
+
+Before we can use the generator we need to setup principal authentication.
+
+ >>> import zope.event
+ >>> from zope.lifecycleevent import ObjectCreatedEvent
+ >>> from zope.app.authentication.interfaces import IAuthenticatorPlugin
+ >>> from zope.app.security.interfaces import IAuthentication
+ >>> from zope.app.authentication.authentication import PluggableAuthentication
+ >>> from zope.app.authentication.principalfolder import PrincipalFolder
+
+ >>> sm = root.getSiteManager()
+ >>> default = sm['default']
+ >>> pau = PluggableAuthentication()
+ >>> zope.event.notify(ObjectCreatedEvent(pau))
+ >>> default['pau'] = pau
+ >>> sm.registerUtility(pau, IAuthentication)
+ >>> # we can do this always
+ >>> pau.credentialsPlugins = ('Session Credentials', )
+ >>> pfNames = (u'members',)
+ >>> pau.authenticatorPlugins = pfNames
+ >>> for name in pfNames:
+ ... if name in pau:
+ ... continue
+ ... pf = PrincipalFolder(name +'.')
+ ... default['pau'][name] = pf
+ ... sm.registerUtility(pf, IAuthenticatorPlugin, name)
+
+ >>> principalDataSource = [['batlogg','Jodok Batlogg','bJB'],
+ ... ['jukart','Juergen Kartnaller','jJK'],
+ ... ['dobee','Bernd Dorn','dBD'],
+ ... ['srichter','Stephan Richter','sSR'],
+ ... ['byzo','Michael Breidenbruecker','bMB'],
+ ... ['oli','Oliver Ruhm','oOR']]
+
+Now that everything is set up we can generate the principals for the root
+object.
+
+We can define a maximum number of users.
+
+ >>> p = generator.generate(root,
+ ... param={'minPrincipals':-1,
+ ... 'maxPrincipals': 2,
+ ... 'pauLocation':'default/pau',
+ ... 'passwordManager':'SHA1'},
+ ... dataSource=principalDataSource
+ ... )
+ >>> p == pau
+ True
+ >>> len(pau['members'])
+ 2
+
+With both parameter set to -1 all members from the datasource are generated.
+
+ >>> p = generator.generate(root,
+ ... param={'minPrincipals':-1,
+ ... 'maxPrincipals':-1,
+ ... 'pauLocation':'default/pau',
+ ... 'passwordManager':'SHA1'},
+ ... dataSource=principalDataSource
+ ... )
+ >>> p == pau
+ True
+ >>> principal = pau['members']['batlogg']
+ >>> principal.title
+ u'Jodok Batlogg'
+
+We can define a minimum number of users.
+
+ >>> numMembers = len(pau['members'])
+ >>> p = generator.generate(root,
+ ... param={'minPrincipals': 10,
+ ... 'maxPrincipals':-1,
+ ... 'pauLocation':'default/pau',
+ ... 'passwordManager':'SHA1'},
+ ... )
+ >>> p == pau
+ True
+ >>> len(pau['members']) == numMembers+10
+ True
+
Property changes on: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/principals.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/site.py
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/site.py 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/site.py 2006-09-03 10:51:30 UTC (rev 69944)
@@ -0,0 +1,64 @@
+##############################################################################
+#
+# Copyright (c) 2006 Lovely Systems and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Sample generator to create a site.
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+import zope.interface
+import zope.component
+import zope.event
+import zope.schema
+import zope.lifecycleevent
+from zope.interface import implements
+from zope.app.component import hooks
+
+from zope.app.component.site import LocalSiteManager
+from zope.app.folder.folder import Folder
+
+from z3c.sampledata.interfaces import ISampleDataPlugin
+
+from z3c.sampledata import _
+
+
+class ISampleSiteParameters(zope.interface.Interface):
+ """The parameters for the site creation."""
+
+ sitename = zope.schema.TextLine(
+ title = _(u'Sitename'),
+ required = True,
+ default = u'',
+ )
+
+
+class SampleSite(object):
+
+ implements(ISampleDataPlugin)
+
+ dependencies = []
+ schema = ISampleSiteParameters
+
+ def generate(self, context, param={}, dataSource={}, seed=None):
+ """Generate the site inside context"""
+ if 'omit' in param:
+ return None
+ name = param['sitename']
+ folder = Folder()
+ zope.event.notify(zope.lifecycleevent.ObjectCreatedEvent(folder))
+ context[name] = folder
+ sm = LocalSiteManager(folder)
+ folder.setSiteManager(sm)
+ hooks.setSite(folder)
+ return folder
Property changes on: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/generator/site.py
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/interfaces.py
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/interfaces.py 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/interfaces.py 2006-09-03 10:51:30 UTC (rev 69944)
@@ -12,7 +12,7 @@
#
###############################################################################
"""
-$Id$
+$Id: $
"""
import zope.interface
@@ -30,21 +30,19 @@
dependencies by these names.
"""
- name = zope.schema.Id(title=u"Sample data generator name")
-
dependencies = zope.schema.List(
title=u"A list of dependenies",
value_type=zope.schema.Id(title=u"Sample data generator name"),
description=u"""
A list of names of sample data generators this one depends on.
""")
-
+
schema = zope.schema.InterfaceField(
title=u"Parameters",
description=u"The schema which provides the parameters.",
)
- def generate(app, param={}, seed=None):
+ def generate(context, param={}, dataSource=None, seed=None):
"""Generate sample data of this plugin.
This method assumes the sample data this plugin depends on has
@@ -63,11 +61,23 @@
description = _(u'The unique name of the sample manager'),
)
- def add(generator, dependsOn=[], contextFrom=None):
+ def addSource(name, data):
+ """Add a new data source to the manager.
+
+ A data source can be assigned to generator plugins.
+ """
+
+ def add(generator,
+ param={},
+ dataSource=None,
+ dependsOn=[],
+ contextFrom=None):
"""Add a generator to the manager.
generator:
The name of a utility providing 'ISampleDataPlugin'.
+ dataSource
+ The name of the data source for the generator.
dependsOn:
The names of generators this generator depends on.
This is used in addition to the dependencies defined in the
@@ -90,6 +100,12 @@
Returns a dict with names of plugins run as keys and CPU times as
values.
+
+ context:
+ The context to be used to generate the sample data.
+ param:
+ A mapping containing the parameters for the generator plugins.
+ The key is the name of the plugin.
"""
Modified: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/manager.py
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/manager.py 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/manager.py 2006-09-03 10:51:30 UTC (rev 69944)
@@ -33,14 +33,28 @@
self.name = name
self.seed = seed
self.generators = {}
+ self.sources = {}
- def add(self, generator, dependsOn=[], contextFrom=None):
+ def addSource(self,
+ name,
+ data=None,
+ adaptTo=None,
+ adapterName=u''):
+ self.sources[name] = (data, adaptTo, adapterName)
+
+ def add(self,
+ generator,
+ param={},
+ dataSource=None,
+ dependsOn=[],
+ contextFrom=None):
info = self.generators.setdefault(generator, {})
+ info['param'] = param
+ info['dataSource'] = dataSource
info['dependsOn'] = dependsOn
info['contextFrom'] = contextFrom
def orderedPlugins(self):
-
# status is a dict plugin names as keys and statuses as values.
# Statuses can be as follows:
#
@@ -75,6 +89,8 @@
pluginInfo = self.generators[name]
info.addDependents(pluginInfo['dependsOn'])
info.contextFrom = pluginInfo['contextFrom']
+ info.param = pluginInfo['param']
+ info.dataSource = pluginInfo['dataSource']
if info.contextFrom is not None:
info.addDependents([info.contextFrom])
generator = component.getUtility(ISampleDataPlugin, name)
@@ -93,7 +109,7 @@
def generate(self, context=None, param={}, seed=None):
plugins = self.orderedPlugins()
-
+
# contextFrom contains the return values of the plugins
contextFrom = {}
@@ -102,7 +118,21 @@
if info.contextFrom is not None:
genContext = contextFrom[info.contextFrom]
start = time.clock()
- contextFrom[info.name] = info.generator.generate(genContext, param, seed)
+ data, adapterInterface, adapterName = \
+ self.sources.get(info.dataSource, (None, None, None))
+ if data is None and adapterInterface is not None:
+ data = component.getAdapter(info.generator,
+ adapterInterface,
+ name=adapterName)
+ generatorParam = param.get(info.name, None)
+ if generatorParam is None:
+ generatorParam = info.param
+
+ contextFrom[info.name] = info.generator.generate(
+ context=genContext,
+ param=generatorParam,
+ dataSource=data,
+ seed=seed)
info.time = time.clock() - start
return plugins
@@ -111,6 +141,8 @@
class PluginInfo(object):
def __init__(self, name):
self.name = name
+ self.param = {}
+ self.dataSource = None
self.dependencies = []
self.contextFrom = None
self.generator = None
Modified: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/meta.zcml
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/meta.zcml 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/meta.zcml 2006-09-03 10:51:30 UTC (rev 69944)
@@ -15,6 +15,11 @@
schema=".metadirectives.IGeneratorSubDirective"
/>
+ <meta:subdirective
+ name="datasource"
+ schema=".metadirectives.IDataSourceSubDirective"
+ />
+
</meta:complexDirective>
</meta:directives>
Modified: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/metaconfigure.py
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/metaconfigure.py 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/metaconfigure.py 2006-09-03 10:51:30 UTC (rev 69944)
@@ -11,12 +11,26 @@
self.manager = Manager(name, seed)
utility(_context, ISampleManager, component=self.manager, name=name)
- def generator(self, _context, name, dependsOn=None, contextFrom=None):
+ def generator(self, _context,
+ name,
+ dependsOn=None,
+ contextFrom=None,
+ dataSource=None):
dependencies = []
if dependsOn is not None:
- dependencies = dependsOn.split(' ')
- self.manager.add(name, dependencies, contextFrom)
+ dependencies = dependsOn.split()
+ self.manager.add(name,
+ dependsOn=dependencies,
+ contextFrom=contextFrom,
+ dataSource=dataSource)
+ def datasource(self, _context, name, adapterInterface, adapterName=u''):
+ self.manager.addSource(name,
+ data=[],
+ adaptTo=adapterInterface,
+ adapterName=adapterName)
+
+
def __call__(self):
return
Modified: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/metadirectives.py
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/metadirectives.py 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/metadirectives.py 2006-09-03 10:51:30 UTC (rev 69944)
@@ -1,5 +1,6 @@
from zope import interface
from zope import schema
+from zope.configuration.fields import GlobalInterface
from z3c.sampledata import _
@@ -44,3 +45,32 @@
required = False,
)
+ dataSource = schema.TextLine(
+ title = _(u"Datasource"),
+ description = _(u'The data source for the generator'),
+ default = u'',
+ required = False,
+ )
+
+
+class IDataSourceSubDirective(interface.Interface):
+ """Parameters for the 'datasource' subdirective."""
+
+ name = schema.TextLine(
+ title = _(u"Name"),
+ description = _(u'The unique name of the datasource'),
+ )
+
+ adapterInterface = GlobalInterface(
+ title = _(u"Interface"),
+ description = _(u'The interface to adapt to'),
+ required = True
+ )
+
+ adapterName = schema.TextLine(
+ title = _(u"Adapter"),
+ description = _(u'The name of the adapter providing the data.'),
+ required = False,
+ default = u''
+ )
+
Deleted: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/principal.py
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/principal.py 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/principal.py 2006-09-03 10:51:30 UTC (rev 69944)
@@ -1,129 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006 Lovely Systems and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Sample generator for principals
-
-$Id$
-"""
-__docformat__ = "reStructuredText"
-
-import zope.interface
-import zope.component
-import zope.event
-import zope.schema
-import zope.lifecycleevent
-from zope.interface import implements
-from zope.security.proxy import removeSecurityProxy
-from zope.app.security.interfaces import IAuthentication
-from zope.app.authentication import principalfolder
-from zope.app.component import hooks
-
-from interfaces import ISampleDataPlugin
-
-from data import DataGenerator
-
-from z3c.sampledata import _
-
-
-class ISamplePrincipalParameters(zope.interface.Interface):
- """The parameters for the sample principal generator."""
-
- minPrincipals = zope.schema.Int(
- title = _(u'Min principals'),
- description = _(u'Create at least this number of pricipals from'
- u' the principals file.\n'
- u'This has higher priority than maxPricipals.\n'
- u'-1 : create all principals from the file.'
- ),
- required = False,
- default = -1,
- )
-
- maxPrincipals = zope.schema.Int(
- title = _(u'Max principals'),
- description = _(u'The maximum number of principals to create.'),
- required = False,
- default = -1,
- )
-
- pauLocation = zope.schema.TextLine(
- title = _(u'PAU location'),
- description = _(u'Path to the PAU inside the site manager.'),
- required = False,
- default = u'default/pau',
- )
-
-
-class SamplePrincipals(object):
-
- implements(ISampleDataPlugin)
-
- name = 'lovely.principals'
- dependencies = []
- schema = ISamplePrincipalParameters
-
- maxPrincipals = None
- minPrincipals = None
-
- def generate(self, context, param={}, seed=None):
- """Generate sample pricipals"""
- self.minPrincipals = int(param['minPrincipals'])
- if self.minPrincipals<0:
- self.minPrincipals = None
- self.maxPrincipals = int(param['maxPrincipals'])
- if self.maxPrincipals<0:
- self.maxPrincipals = None
- originalSite = hooks.getSite()
- hooks.setSite(context)
- sm = zope.component.getSiteManager(context)
- self.pau = sm
- for loc in param['pauLocation'].split('/'):
- self.pau = self.pau[loc]
-
- numCreated = 0
- self.logins = []
- generator = DataGenerator(str(seed) + self.name)
- principals = generator.readCSV('testprincipals.txt')
- for info in principals:
- if ( self.maxPrincipals is not None
- and numCreated>=self.maxPrincipals):
- break
- login = unicode(info[1])
- if login in self.logins:
- # ignore duplicate principals
- continue
- self._createPrincipal(info)
- numCreated+=1
-
- if ( self.minPrincipals is not None
- and numCreated<self.minPrincipals):
- for i in range(self.minPrincipals-numCreated):
- info = ['group','login%i'%i,'name%i'%i,'%i'%i]
- self._createPrincipal(info)
-
- hooks.setSite(originalSite)
-
- def _createPrincipal(self, info):
- login = unicode(info[1])
- self.logins.append(login)
- if login in self.pau['members']:
- return
- groupId = unicode(info[0])
- name = unicode(info[2])
- password = unicode(info[3])
- principal = principalfolder.InternalPrincipal(login,
- password, name, passwordManagerName="SHA1")
- zope.event.notify(
- zope.lifecycleevent.ObjectCreatedEvent(principal))
- self.pau['members'][login] = principal
-
Deleted: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/principal.txt
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/principal.txt 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/principal.txt 2006-09-03 10:51:30 UTC (rev 69944)
@@ -1,64 +0,0 @@
-================================
-Principal Sample Data Generation
-================================
-
-This gerator creates principals from a CSV file.
-
- >>> from z3c.sampledata.principal import SamplePrincipals
- >>> generator = SamplePrincipals()
-
-Before we can use the generator we need to setup principal authentication.
-
- >>> import zope.event
- >>> from zope.lifecycleevent import ObjectCreatedEvent
- >>> from zope.app.authentication.interfaces import IAuthenticatorPlugin
- >>> from zope.app.security.interfaces import IAuthentication
- >>> from zope.app.authentication.authentication import PluggableAuthentication
- >>> from zope.app.authentication.principalfolder import PrincipalFolder
-
- >>> sm = root.getSiteManager()
- >>> default = sm['default']
- >>> pau = PluggableAuthentication()
- >>> zope.event.notify(ObjectCreatedEvent(pau))
- >>> default['pau'] = pau
- >>> sm.registerUtility(pau, IAuthentication)
- >>> # we can do this always
- >>> pau.credentialsPlugins = ('Session Credentials', )
- >>> pfNames = (u'members',)
- >>> pau.authenticatorPlugins = pfNames
- >>> for name in pfNames:
- ... if name in pau:
- ... continue
- ... pf = PrincipalFolder(name +'.')
- ... default['pau'][name] = pf
- ... sm.registerUtility(pf, IAuthenticatorPlugin, name)
-
-Now that everything is set up we can generate the principals for the root
-object.
-
-We can define a maximum number of users.
-
- >>> generator.generate(root, param={'minPrincipals':-1,
- ... 'maxPrincipals': 2,
- ... 'pauLocation':'default/pau'})
- >>> len(pau['members'])
- 2
-
-With both parameter set to -1 all members from "testprincipals.txt" are generated.
-
- >>> generator.generate(root, param={'minPrincipals':-1,
- ... 'maxPrincipals':-1,
- ... 'pauLocation':'default/pau'})
- >>> principal = pau['members']['batlogg']
- >>> principal.title
- u'Jodok Batlogg'
-
-We can define a minimum number of users.
-
- >>> numMembers = len(pau['members'])
- >>> generator.generate(root, param={'minPrincipals': numMembers+10,
- ... 'maxPrincipals':-1,
- ... 'pauLocation':'default/pau'})
- >>> len(pau['members']) == numMembers+10
- True
-
Deleted: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/site.py
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/site.py 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/site.py 2006-09-03 10:51:30 UTC (rev 69944)
@@ -1,94 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006 Lovely Systems and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Sample generator for site generation.
-
-Contains some general purpose generators related to site specific data.
-
-$Id$
-"""
-__docformat__ = "reStructuredText"
-
-import zope.interface
-import zope.component
-import zope.event
-import zope.schema
-import zope.lifecycleevent
-from zope.interface import implements
-from zope.app.component import hooks
-
-from zope.app.component.site import LocalSiteManager
-from zope.app.folder.folder import Folder
-from zope.app.intid import IntIds
-from zope.app.intid.interfaces import IIntIds
-
-from interfaces import ISampleDataPlugin
-
-from z3c.sampledata import _
-
-
-class ISampleSiteParameters(zope.interface.Interface):
- """The parameters for the site creation."""
-
- sitename = zope.schema.TextLine(
- title = _(u'Sitename'),
- required = True,
- default = u'',
- )
-
-
-class SampleSite(object):
-
- implements(ISampleDataPlugin)
-
- name = 'lovely.sampledata.site'
- dependencies = []
- schema = ISampleSiteParameters
-
- def generate(self, context, param={}, seed=None):
- """Generate the site inside context"""
- name = param['sitename']
- folder = Folder()
- zope.event.notify(zope.lifecycleevent.ObjectCreatedEvent(folder))
- context[name] = folder
- sm = LocalSiteManager(folder)
- folder.setSiteManager(sm)
- hooks.setSite(folder)
- return folder
-
-
-class SampleIntIds(object):
-
- implements(ISampleDataPlugin)
-
- name = 'lovely.sampledata.intids'
- dependencies = []
- schema = None
-
- def generate(self, context, param={}, seed=None):
- """Generate an IntId utility inside context.
-
- 'context' must be a site manager.
- """
- sm = context.getSiteManager()
- default = sm['default']
-
- if 'intid' not in default:
- intid = IntIds()
- zope.event.notify(zope.lifecycleevent.ObjectCreatedEvent(intid))
- default['intid'] = intid
- sm.registerUtility(intid, IIntIds)
- return intid
- else:
- return default['intid']
-
Deleted: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/site.zcml
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/site.zcml 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/site.zcml 2006-09-03 10:51:30 UTC (rev 69944)
@@ -1,40 +0,0 @@
-<configure xmlns="http://namespaces.zope.org/zope">
-
- <configure
- xmlns:zcml="http://namespaces.zope.org/zcml"
- zcml:condition="have devmode">
-
- <!-- This is a configuration for the testing environment -->
-
- <utility
- factory=".site.SampleSite"
- provides="z3c.sampledata.interfaces.ISampleDataPlugin"
- name="z3c.sampledata.site"
- />
-
- <utility
- factory=".site.SampleIntIds"
- provides="z3c.sampledata.interfaces.ISampleDataPlugin"
- name="z3c.sampledata.intids"
- />
-
- <utility
- factory=".principal.SamplePrincipals"
- provides="z3c.sampledata.interfaces.ISampleDataPlugin"
- name="z3c.sampledata.principals"
- />
-
- <SampleManager
- name="Site with intid utility"
- >
- <generator name="z3c.sampledata.site" />
- <generator
- name="z3c.sampledata.intids"
- dependsOn="z3c.sampledata.site"
- contextFrom="z3c.sampledata.site" />
- </SampleManager>
-
- </configure>
-
-</configure>
-
Deleted: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/testprincipals.txt
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/testprincipals.txt 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/testprincipals.txt 2006-09-03 10:51:30 UTC (rev 69944)
@@ -1,6 +0,0 @@
-group.Administrator,batlogg,Jodok Batlogg,bJB
-group.Administrator,jukart,Juergen Kartnaller,jJK
-group.Administrator,dobee,Bernd Dorn,dBD
-group.Administrator,srichter,Stephan Richter,sSR
-group.Administrator,byzo,Michael Breidenbruecker,bMB
-group.Administrator,oli,Oliver Ruhm,oOR
Modified: z3c.sampledata/branches/jukart-features/src/z3c/sampledata/tests.py
===================================================================
--- z3c.sampledata/branches/jukart-features/src/z3c/sampledata/tests.py 2006-09-03 10:38:06 UTC (rev 69943)
+++ z3c.sampledata/branches/jukart-features/src/z3c/sampledata/tests.py 2006-09-03 10:51:30 UTC (rev 69944)
@@ -33,17 +33,17 @@
def test_suite():
-
+
return unittest.TestSuite(
(
DocFileSuite('README.txt',
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
),
- DocFileSuite('principal.txt',
+ DocFileSuite('generator/principals.txt',
setUp=setUp, tearDown=tearDown,
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
),
))
-
+
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
More information about the Checkins
mailing list