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:
		
							parent
							
								
									0de607514d
								
							
						
					
					
						commit
						03021dc798
					
				
					 8 changed files with 56 additions and 40 deletions
				
			
		
							
								
								
									
										13
									
								
								README.txt
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								README.txt
									
										
									
									
									
								
							|  | @ -122,7 +122,7 @@ type manager. | ||||||
|   >>> from loops.concept import ConceptTypeSourceList |   >>> from loops.concept import ConceptTypeSourceList | ||||||
|   >>> types = ConceptTypeSourceList(cc1) |   >>> types = ConceptTypeSourceList(cc1) | ||||||
|   >>> sorted(t.title for t in types) |   >>> 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 | Using a PredicateSourceList we can retrieve a list of the available | ||||||
| predicates. | predicates. | ||||||
|  | @ -195,7 +195,8 @@ types and predicates. | ||||||
|   >>> component.provideAdapter(LoopsTerms, (IIterableSource, IBrowserRequest), ITerms) |   >>> component.provideAdapter(LoopsTerms, (IIterableSource, IBrowserRequest), ITerms) | ||||||
| 
 | 
 | ||||||
|   >>> sorted((t.title, t.token) for t in view.conceptTypes()) |   >>> 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'Predicate', '.loops/concepts/predicate'), | ||||||
|    (u'Query', '.loops/concepts/query'), |    (u'Query', '.loops/concepts/query'), | ||||||
|    (u'Topic', '.loops/concepts/topic'), |    (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)) |   >>> view = ConfigureView(m111, TestRequest(form = form)) | ||||||
|   >>> tt = view.targetTypes() |   >>> tt = view.targetTypes() | ||||||
|   >>> len(tt) |   >>> len(tt) | ||||||
|   9 |   10 | ||||||
|   >>> sorted((t.token, t.title) for t in view.targetTypes())[0] |   >>> sorted((t.token, t.title) for t in view.targetTypes())[1] | ||||||
|   ('.loops/concepts/domain', u'Domain') |   ('.loops/concepts/domain', u'Domain') | ||||||
|   >>> view.update() |   >>> view.update() | ||||||
|   True |   True | ||||||
|  | @ -718,7 +719,7 @@ or resource. | ||||||
| 
 | 
 | ||||||
|   >>> from loops.view import NodeTraverser |   >>> 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' |   >>> url = 'http://127.0.0.1/loops/views/m1/m11/m111/' + magic + '/@@node.html' | ||||||
|   >>> #request = TestRequest(environ=dict(SERVER_URL=url)) |   >>> #request = TestRequest(environ=dict(SERVER_URL=url)) | ||||||
|   >>> request = TestRequest() |   >>> request = TestRequest() | ||||||
|  | @ -740,7 +741,7 @@ target object's view here: | ||||||
|   [<loops.browser.common.Action object ...>] |   [<loops.browser.common.Action object ...>] | ||||||
|   >>> action = view.virtualTarget.getActions()[0] |   >>> action = view.virtualTarget.getActions()[0] | ||||||
|   >>> action.url |   >>> 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 | Import/Export | ||||||
|  |  | ||||||
|  | @ -42,7 +42,7 @@ and methods of the external collect object. | ||||||
|   >>> from loops.integrator.collection import ExternalCollectionAdapter |   >>> from loops.integrator.collection import ExternalCollectionAdapter | ||||||
|   >>> tExternalCollection = concepts['extcollection'] |   >>> tExternalCollection = concepts['extcollection'] | ||||||
|   >>> coll01 = addObject(concepts, Concept, 'coll01', |   >>> coll01 = addObject(concepts, Concept, 'coll01', | ||||||
|   ...                    title=u'Collection One', type=tExternalCollection) |   ...                    title=u'Collection One', conceptType=tExternalCollection) | ||||||
|   >>> aColl01 = ExternalCollectionAdapter(coll01) |   >>> aColl01 = ExternalCollectionAdapter(coll01) | ||||||
| 
 | 
 | ||||||
| An external collection carries a set of attributes that control the access | An external collection carries a set of attributes that control the access | ||||||
|  |  | ||||||
|  | @ -36,7 +36,7 @@ from loops.interfaces import IResource, IConcept | ||||||
| from loops.integrator.interfaces import IExternalCollection | from loops.integrator.interfaces import IExternalCollection | ||||||
| from loops.integrator.interfaces import IExternalCollectionProvider | from loops.integrator.interfaces import IExternalCollectionProvider | ||||||
| from loops.resource import Resource | from loops.resource import Resource | ||||||
| from loops.setup import addObject | from loops.setup import addAndConfigureObject | ||||||
| from loops.type import TypeInterfaceSourceList | from loops.type import TypeInterfaceSourceList | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -70,13 +70,12 @@ class DirectoryCollectionProvider(object): | ||||||
|     def collect(self, client): |     def collect(self, client): | ||||||
|         directory = self.getDirectory(client) |         directory = self.getDirectory(client) | ||||||
|         pattern = re.compile(client.pattern or '.*') |         pattern = re.compile(client.pattern or '.*') | ||||||
|         result = [] |  | ||||||
|         for path, dirs, files in os.walk(directory): |         for path, dirs, files in os.walk(directory): | ||||||
|             if files: |             if '.svn' in dirs: | ||||||
|                 result.extend(os.path.join(path[len(directory)+1:], f) |                 del dirs[dirs.index('.svn')] | ||||||
|                                 for f in files |             for f in files: | ||||||
|                                     if pattern.match(f)) |                 if pattern.match(f): | ||||||
|         return result |                     yield os.path.join(path[len(directory)+1:], f) | ||||||
| 
 | 
 | ||||||
|     def createExtFileObjects(self, client, addresses, extFileType=None): |     def createExtFileObjects(self, client, addresses, extFileType=None): | ||||||
|         if extFileType is None: |         if extFileType is None: | ||||||
|  | @ -85,8 +84,10 @@ class DirectoryCollectionProvider(object): | ||||||
|         directory = self.getDirectory(client) |         directory = self.getDirectory(client) | ||||||
|         for addr in addresses: |         for addr in addresses: | ||||||
|             name = addr |             name = addr | ||||||
|             obj = addObject(rm, Resource, name, |             obj = addAndConfigureObject( | ||||||
|                             title=addr.decode('UTF-8'), type=extFileType, |                             rm, Resource, name, | ||||||
|  |                             title=addr.decode('UTF-8'), | ||||||
|  |                             type=extFileType, | ||||||
|                             externalAddress=addr, |                             externalAddress=addr, | ||||||
|                             storage='fullpath', |                             storage='fullpath', | ||||||
|                             storageParams=dict(subdirectory=directory)) |                             storageParams=dict(subdirectory=directory)) | ||||||
|  |  | ||||||
|  | @ -13,7 +13,7 @@ from loops.concept import Concept | ||||||
| from loops.resource import Resource | from loops.resource import Resource | ||||||
| from loops.integrator.interfaces import IExternalCollection | from loops.integrator.interfaces import IExternalCollection | ||||||
| from loops.knowledge.setup import SetupManager as KnowledgeSetupManager | 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 | from loops.tests.setup import TestSite as BaseTestSite | ||||||
| 
 | 
 | ||||||
| dataDir = os.path.join(os.path.dirname(__file__), 'testdata') | dataDir = os.path.join(os.path.dirname(__file__), 'testdata') | ||||||
|  | @ -29,11 +29,11 @@ class TestSite(BaseTestSite): | ||||||
|         concepts, resources, views = self.baseSetup() |         concepts, resources, views = self.baseSetup() | ||||||
| 
 | 
 | ||||||
|         tType = concepts.getTypeConcept() |         tType = concepts.getTypeConcept() | ||||||
|         tExtFile = addObject(concepts, Concept, 'extfile', |         tExtFile = addAndConfigureObject(concepts, Concept, 'extfile', | ||||||
|                                 title=u'External File', type=tType, |                                 title=u'External File', conceptType=tType, | ||||||
|                                 typeInterface=IExternalFile) |                                 typeInterface=IExternalFile) | ||||||
|         tExtCollection = addObject(concepts, Concept, 'extcollection', |         tExtCollection = addAndConfigureObject(concepts, Concept, 'extcollection', | ||||||
|                                 title=u'External Collection', type=tType, |                                 title=u'External Collection', conceptType=tType, | ||||||
|                                 typeInterface=IExternalCollection) |                                 typeInterface=IExternalCollection) | ||||||
| 
 | 
 | ||||||
|         self.indexAll(concepts, resources) |         self.indexAll(concepts, resources) | ||||||
|  |  | ||||||
|  | @ -231,12 +231,13 @@ class Resource(Image, Contained): | ||||||
|         newTi = removeSecurityProxy(newType.typeInterface) |         newTi = removeSecurityProxy(newType.typeInterface) | ||||||
|         newOptions = {} |         newOptions = {} | ||||||
|         if newTi is not None: |         if newTi is not None: | ||||||
|             newAdapted = newTi(context) |             newAdapted = newTi(context, None) | ||||||
|  |             if newAdapted is not None: | ||||||
|                 # make sure we use options of new type: |                 # make sure we use options of new type: | ||||||
|                 newOptions = newType.optionsDict |                 newOptions = newType.optionsDict | ||||||
|                 object.__setattr__(newAdapted, 'options', newOptions) |                 object.__setattr__(newAdapted, 'options', newOptions) | ||||||
|         #print 'migrateStorage:', newAdapted, newOptions, oldAdapted, oldAdapted.storageName |         #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 |             data = oldAdapted.data | ||||||
|             #print 'data', data |             #print 'data', data | ||||||
|             oldAdapted.data = ''            # clear old storage |             oldAdapted.data = ''            # clear old storage | ||||||
|  |  | ||||||
							
								
								
									
										15
									
								
								setup.py
									
										
									
									
									
								
							
							
						
						
									
										15
									
								
								setup.py
									
										
									
									
									
								
							|  | @ -28,6 +28,7 @@ from zope import component | ||||||
| from zope.component import adapts | from zope.component import adapts | ||||||
| from zope.interface import implements, Interface | from zope.interface import implements, Interface | ||||||
| 
 | 
 | ||||||
|  | from cybertools.typology.interfaces import IType | ||||||
| from loops.interfaces import ILoops, ITypeConcept | from loops.interfaces import ILoops, ITypeConcept | ||||||
| from loops.interfaces import IFile, IImage, ITextDocument, INote | from loops.interfaces import IFile, IImage, ITextDocument, INote | ||||||
| from loops.concept import ConceptManager, Concept | from loops.concept import ConceptManager, Concept | ||||||
|  | @ -90,7 +91,7 @@ class SetupManager(object): | ||||||
|         #ITypeConcept(image).typeInterface = IImage |         #ITypeConcept(image).typeInterface = IImage | ||||||
|         ITypeConcept(textdocument).typeInterface = ITextDocument |         ITypeConcept(textdocument).typeInterface = ITextDocument | ||||||
|         ITypeConcept(note).typeInterface = INote |         ITypeConcept(note).typeInterface = INote | ||||||
|         #ITypeConcept(note).viewName = 'note.html' |         ITypeConcept(note).viewName = 'note.html' # leads to error in DocTest | ||||||
|         hasType.conceptType = predicate |         hasType.conceptType = predicate | ||||||
|         standard.conceptType = predicate |         standard.conceptType = predicate | ||||||
| 
 | 
 | ||||||
|  | @ -107,3 +108,15 @@ def addObject(container, class_, name, **kw): | ||||||
|     notify(ObjectCreatedEvent(obj)) |     notify(ObjectCreatedEvent(obj)) | ||||||
|     notify(ObjectModifiedEvent(obj)) |     notify(ObjectModifiedEvent(obj)) | ||||||
|     return 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 | ||||||
|  |  | ||||||
|  | @ -70,17 +70,17 @@ class TestSite(object): | ||||||
|         tFile = concepts['file'] |         tFile = concepts['file'] | ||||||
| 
 | 
 | ||||||
|         tCustomer = addObject(concepts, Concept, 'customer', title=u'Customer', |         tCustomer = addObject(concepts, Concept, 'customer', title=u'Customer', | ||||||
|                            type=tType) |                            conceptType=tType) | ||||||
|         dProjects = addObject(concepts, Concept, 'projects', |         dProjects = addObject(concepts, Concept, 'projects', | ||||||
|                            title=u'Project Domain', type=tDomain) |                            title=u'Project Domain', conceptType=tDomain) | ||||||
|         tCustomer.assignParent(dProjects) |         tCustomer.assignParent(dProjects) | ||||||
| 
 | 
 | ||||||
|         d001 = addObject(resources, Resource, 'd001.txt', |         d001 = addObject(resources, Resource, 'd001.txt', | ||||||
|                            title=u'Doc 001', type=tTextDocument) |                            title=u'Doc 001', resourceType=tTextDocument) | ||||||
|         d002 = addObject(resources, Resource, 'd002.txt', |         d002 = addObject(resources, Resource, 'd002.txt', | ||||||
|                            title=u'Doc 002', type=tTextDocument) |                            title=u'Doc 002', resourceType=tTextDocument) | ||||||
|         d003 = addObject(resources, Resource, 'd003.txt', |         d003 = addObject(resources, Resource, 'd003.txt', | ||||||
|                            title=u'Doc 003', type=tTextDocument) |                            title=u'Doc 003', resourceType=tTextDocument) | ||||||
| 
 | 
 | ||||||
|         self.indexAll(concepts, resources) |         self.indexAll(concepts, resources) | ||||||
|         return concepts, resources, views |         return concepts, resources, views | ||||||
|  |  | ||||||
|  | @ -67,25 +67,25 @@ class TestSite(object): | ||||||
|         tTextDocument = concepts['textdocument'] |         tTextDocument = concepts['textdocument'] | ||||||
| 
 | 
 | ||||||
|         tCustomer = addObject(concepts, Concept, 'customer', title=u'Customer', |         tCustomer = addObject(concepts, Concept, 'customer', title=u'Customer', | ||||||
|                            type=tType) |                            conceptType=tType) | ||||||
|         dProjects = addObject(concepts, Concept, 'projects', |         dProjects = addObject(concepts, Concept, 'projects', | ||||||
|                            title=u'Project Domain', type=tDomain) |                            title=u'Project Domain', conceptType=tDomain) | ||||||
|         tCustomer.assignParent(dProjects) |         tCustomer.assignParent(dProjects) | ||||||
| 
 | 
 | ||||||
|         cust1 = addObject(concepts, Concept, 'cust1', |         cust1 = addObject(concepts, Concept, 'cust1', | ||||||
|                            title=u'Customer 1', type=tCustomer) |                            title=u'Customer 1', conceptType=tCustomer) | ||||||
|         cust2 = addObject(concepts, Concept, 'cust2', |         cust2 = addObject(concepts, Concept, 'cust2', | ||||||
|                            title=u'Customer 2', type=tCustomer) |                            title=u'Customer 2', conceptType=tCustomer) | ||||||
|         cust3 = addObject(concepts, Concept, 'cust3', |         cust3 = addObject(concepts, Concept, 'cust3', | ||||||
|                            title=u'Customer 3', type=tCustomer) |                            title=u'Customer 3', conceptType=tCustomer) | ||||||
|         d001 = addObject(resources, Resource, 'd001.txt', |         d001 = addObject(resources, Resource, 'd001.txt', | ||||||
|                            title=u'Doc 001', type=tTextDocument) |                            title=u'Doc 001', resouceType=tTextDocument) | ||||||
|         d001.assignConcept(cust1) |         d001.assignConcept(cust1) | ||||||
|         d002 = addObject(resources, Resource, 'd002.txt', |         d002 = addObject(resources, Resource, 'd002.txt', | ||||||
|                            title=u'Doc 002', type=tTextDocument) |                            title=u'Doc 002', resouceType=tTextDocument) | ||||||
|         d002.assignConcept(cust3) |         d002.assignConcept(cust3) | ||||||
|         d003 = addObject(resources, Resource, 'd003.txt', |         d003 = addObject(resources, Resource, 'd003.txt', | ||||||
|                            title=u'Doc 003', type=tTextDocument) |                            title=u'Doc 003', resouceType=tTextDocument) | ||||||
|         d003.assignConcept(cust1) |         d003.assignConcept(cust1) | ||||||
| 
 | 
 | ||||||
|         for c in concepts.values(): |         for c in concepts.values(): | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 helmutm
						helmutm