work in progress: loops.integrator: more on DirectoryCollectionProvider; added loops.setup.addAndConfigureObject()

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1688 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2007-04-14 09:08:39 +00:00
parent 0de607514d
commit 03021dc798
8 changed files with 56 additions and 40 deletions

View file

@ -122,7 +122,7 @@ type manager.
>>> from loops.concept import ConceptTypeSourceList
>>> types = ConceptTypeSourceList(cc1)
>>> sorted(t.title for t in types)
[u'Domain', u'Predicate', u'Query', u'Topic', u'Type', u'Unknown Type']
[u'Customer', u'Domain', u'Predicate', u'Query', u'Topic', u'Type', u'Unknown Type']
Using a PredicateSourceList we can retrieve a list of the available
predicates.
@ -195,7 +195,8 @@ types and predicates.
>>> component.provideAdapter(LoopsTerms, (IIterableSource, IBrowserRequest), ITerms)
>>> sorted((t.title, t.token) for t in view.conceptTypes())
[(u'Domain', '.loops/concepts/domain'),
[(u'Customer', '.loops/concepts/customer'),
(u'Domain', '.loops/concepts/domain'),
(u'Predicate', '.loops/concepts/predicate'),
(u'Query', '.loops/concepts/query'),
(u'Topic', '.loops/concepts/topic'),
@ -490,8 +491,8 @@ view; these views we have to provide as multi-adapters:
>>> view = ConfigureView(m111, TestRequest(form = form))
>>> tt = view.targetTypes()
>>> len(tt)
9
>>> sorted((t.token, t.title) for t in view.targetTypes())[0]
10
>>> sorted((t.token, t.title) for t in view.targetTypes())[1]
('.loops/concepts/domain', u'Domain')
>>> view.update()
True
@ -718,7 +719,7 @@ or resource.
>>> from loops.view import NodeTraverser
>>> magic = '.target' + util.getUidForObject(note)
>>> magic = '.target' + util.getUidForObject(resources['d001.txt'])
>>> url = 'http://127.0.0.1/loops/views/m1/m11/m111/' + magic + '/@@node.html'
>>> #request = TestRequest(environ=dict(SERVER_URL=url))
>>> request = TestRequest()
@ -740,7 +741,7 @@ target object's view here:
[<loops.browser.common.Action object ...>]
>>> action = view.virtualTarget.getActions()[0]
>>> action.url
'http://127.0.0.1/loops/views/m1/m11/m111/.target57'
'http://127.0.0.1/loops/views/m1/m11/m111/.target23'
Import/Export

View file

@ -42,7 +42,7 @@ and methods of the external collect object.
>>> from loops.integrator.collection import ExternalCollectionAdapter
>>> tExternalCollection = concepts['extcollection']
>>> coll01 = addObject(concepts, Concept, 'coll01',
... title=u'Collection One', type=tExternalCollection)
... title=u'Collection One', conceptType=tExternalCollection)
>>> aColl01 = ExternalCollectionAdapter(coll01)
An external collection carries a set of attributes that control the access

View file

@ -36,7 +36,7 @@ from loops.interfaces import IResource, IConcept
from loops.integrator.interfaces import IExternalCollection
from loops.integrator.interfaces import IExternalCollectionProvider
from loops.resource import Resource
from loops.setup import addObject
from loops.setup import addAndConfigureObject
from loops.type import TypeInterfaceSourceList
@ -70,13 +70,12 @@ class DirectoryCollectionProvider(object):
def collect(self, client):
directory = self.getDirectory(client)
pattern = re.compile(client.pattern or '.*')
result = []
for path, dirs, files in os.walk(directory):
if files:
result.extend(os.path.join(path[len(directory)+1:], f)
for f in files
if pattern.match(f))
return result
if '.svn' in dirs:
del dirs[dirs.index('.svn')]
for f in files:
if pattern.match(f):
yield os.path.join(path[len(directory)+1:], f)
def createExtFileObjects(self, client, addresses, extFileType=None):
if extFileType is None:
@ -85,8 +84,10 @@ class DirectoryCollectionProvider(object):
directory = self.getDirectory(client)
for addr in addresses:
name = addr
obj = addObject(rm, Resource, name,
title=addr.decode('UTF-8'), type=extFileType,
obj = addAndConfigureObject(
rm, Resource, name,
title=addr.decode('UTF-8'),
type=extFileType,
externalAddress=addr,
storage='fullpath',
storageParams=dict(subdirectory=directory))

View file

@ -13,7 +13,7 @@ from loops.concept import Concept
from loops.resource import Resource
from loops.integrator.interfaces import IExternalCollection
from loops.knowledge.setup import SetupManager as KnowledgeSetupManager
from loops.setup import SetupManager, addObject
from loops.setup import SetupManager, addAndConfigureObject
from loops.tests.setup import TestSite as BaseTestSite
dataDir = os.path.join(os.path.dirname(__file__), 'testdata')
@ -29,11 +29,11 @@ class TestSite(BaseTestSite):
concepts, resources, views = self.baseSetup()
tType = concepts.getTypeConcept()
tExtFile = addObject(concepts, Concept, 'extfile',
title=u'External File', type=tType,
tExtFile = addAndConfigureObject(concepts, Concept, 'extfile',
title=u'External File', conceptType=tType,
typeInterface=IExternalFile)
tExtCollection = addObject(concepts, Concept, 'extcollection',
title=u'External Collection', type=tType,
tExtCollection = addAndConfigureObject(concepts, Concept, 'extcollection',
title=u'External Collection', conceptType=tType,
typeInterface=IExternalCollection)
self.indexAll(concepts, resources)

View file

@ -231,12 +231,13 @@ class Resource(Image, Contained):
newTi = removeSecurityProxy(newType.typeInterface)
newOptions = {}
if newTi is not None:
newAdapted = newTi(context)
# make sure we use options of new type:
newOptions = newType.optionsDict
object.__setattr__(newAdapted, 'options', newOptions)
newAdapted = newTi(context, None)
if newAdapted is not None:
# make sure we use options of new type:
newOptions = newType.optionsDict
object.__setattr__(newAdapted, 'options', newOptions)
#print 'migrateStorage:', newAdapted, newOptions, oldAdapted, oldAdapted.storageName
if newOptions.get('storage') != oldAdapted.storageName:
if newAdapted is not None and newOptions.get('storage') != oldAdapted.storageName:
data = oldAdapted.data
#print 'data', data
oldAdapted.data = '' # clear old storage

View file

@ -28,6 +28,7 @@ from zope import component
from zope.component import adapts
from zope.interface import implements, Interface
from cybertools.typology.interfaces import IType
from loops.interfaces import ILoops, ITypeConcept
from loops.interfaces import IFile, IImage, ITextDocument, INote
from loops.concept import ConceptManager, Concept
@ -90,7 +91,7 @@ class SetupManager(object):
#ITypeConcept(image).typeInterface = IImage
ITypeConcept(textdocument).typeInterface = ITextDocument
ITypeConcept(note).typeInterface = INote
#ITypeConcept(note).viewName = 'note.html'
ITypeConcept(note).viewName = 'note.html' # leads to error in DocTest
hasType.conceptType = predicate
standard.conceptType = predicate
@ -107,3 +108,15 @@ def addObject(container, class_, name, **kw):
notify(ObjectCreatedEvent(obj))
notify(ObjectModifiedEvent(obj))
return obj
def addAndConfigureObject(container, class_, name, **kw):
basicAttributes = ('title', 'description', 'conceptType', 'resourceType')
basicKw = dict([(k, kw[k]) for k in kw if k in basicAttributes])
obj = addObject(container, class_, name, **basicKw)
ti = IType(obj).typeInterface
adapted = ti is not None and ti(obj) or obj
adapterAttributes = [k for k in kw if k not in basicAttributes]
for attr in adapterAttributes:
setattr(obj, attr, kw[attr])
notify(ObjectModifiedEvent(obj))
return obj

View file

@ -70,17 +70,17 @@ class TestSite(object):
tFile = concepts['file']
tCustomer = addObject(concepts, Concept, 'customer', title=u'Customer',
type=tType)
conceptType=tType)
dProjects = addObject(concepts, Concept, 'projects',
title=u'Project Domain', type=tDomain)
title=u'Project Domain', conceptType=tDomain)
tCustomer.assignParent(dProjects)
d001 = addObject(resources, Resource, 'd001.txt',
title=u'Doc 001', type=tTextDocument)
title=u'Doc 001', resourceType=tTextDocument)
d002 = addObject(resources, Resource, 'd002.txt',
title=u'Doc 002', type=tTextDocument)
title=u'Doc 002', resourceType=tTextDocument)
d003 = addObject(resources, Resource, 'd003.txt',
title=u'Doc 003', type=tTextDocument)
title=u'Doc 003', resourceType=tTextDocument)
self.indexAll(concepts, resources)
return concepts, resources, views

View file

@ -67,25 +67,25 @@ class TestSite(object):
tTextDocument = concepts['textdocument']
tCustomer = addObject(concepts, Concept, 'customer', title=u'Customer',
type=tType)
conceptType=tType)
dProjects = addObject(concepts, Concept, 'projects',
title=u'Project Domain', type=tDomain)
title=u'Project Domain', conceptType=tDomain)
tCustomer.assignParent(dProjects)
cust1 = addObject(concepts, Concept, 'cust1',
title=u'Customer 1', type=tCustomer)
title=u'Customer 1', conceptType=tCustomer)
cust2 = addObject(concepts, Concept, 'cust2',
title=u'Customer 2', type=tCustomer)
title=u'Customer 2', conceptType=tCustomer)
cust3 = addObject(concepts, Concept, 'cust3',
title=u'Customer 3', type=tCustomer)
title=u'Customer 3', conceptType=tCustomer)
d001 = addObject(resources, Resource, 'd001.txt',
title=u'Doc 001', type=tTextDocument)
title=u'Doc 001', resouceType=tTextDocument)
d001.assignConcept(cust1)
d002 = addObject(resources, Resource, 'd002.txt',
title=u'Doc 002', type=tTextDocument)
title=u'Doc 002', resouceType=tTextDocument)
d002.assignConcept(cust3)
d003 = addObject(resources, Resource, 'd003.txt',
title=u'Doc 003', type=tTextDocument)
title=u'Doc 003', resouceType=tTextDocument)
d003.assignConcept(cust1)
for c in concepts.values():