added integrator.content package: transparent access to filesystem directories and files
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2443 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
dd66347498
commit
d503e5d0e5
12 changed files with 335 additions and 29 deletions
|
@ -30,7 +30,6 @@ Concepts and Relations
|
||||||
Let's start with creating a few example concepts, putting them in a
|
Let's start with creating a few example concepts, putting them in a
|
||||||
top-level loops container and a concept manager:
|
top-level loops container and a concept manager:
|
||||||
|
|
||||||
>>> from loops.base import Loops
|
|
||||||
>>> from loops.tests.setup import TestSite
|
>>> from loops.tests.setup import TestSite
|
||||||
>>> t = TestSite(site)
|
>>> t = TestSite(site)
|
||||||
>>> concepts, resources, views = t.setup()
|
>>> concepts, resources, views = t.setup()
|
||||||
|
|
|
@ -105,3 +105,20 @@ class IStatement(Interface):
|
||||||
relevance = Attribute('A number denoting the relevance or correctness '
|
relevance = Attribute('A number denoting the relevance or correctness '
|
||||||
'of the statement')
|
'of the statement')
|
||||||
|
|
||||||
|
|
||||||
|
# more to come...
|
||||||
|
|
||||||
|
class IOntologyExporter(Interface):
|
||||||
|
""" An adapter for creating an XML file with all appropriate informations
|
||||||
|
from the context and its children, selecting children via a
|
||||||
|
pattern or a set of selection criteria.
|
||||||
|
|
||||||
|
This may then be used by an external tool for classifying
|
||||||
|
a set of external objects.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class IClassificationImporter(Interface):
|
||||||
|
""" An Adapter for importing an XML file with classification
|
||||||
|
information for a collection of external objects."
|
||||||
|
"""
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 2007 Helmut Merz helmutm@cy55.de
|
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
View class(es) for intergrating external objects.
|
View class(es) for integrating external objects.
|
||||||
|
|
||||||
$Id$
|
$Id$
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -54,4 +54,6 @@
|
||||||
provides="zope.publisher.interfaces.IPublishTraverse"
|
provides="zope.publisher.interfaces.IPublishTraverse"
|
||||||
permission="zope.Public" />
|
permission="zope.Public" />
|
||||||
|
|
||||||
|
<include package=".content" />
|
||||||
|
|
||||||
</configure>
|
</configure>
|
||||||
|
|
72
integrator/content/README.txt
Normal file
72
integrator/content/README.txt
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
===============================================================
|
||||||
|
loops - Linked Objects for Organization and Processing Services
|
||||||
|
===============================================================
|
||||||
|
|
||||||
|
Integration of external sources.
|
||||||
|
|
||||||
|
($Id$)
|
||||||
|
|
||||||
|
|
||||||
|
Setting up a loops Site and Utilities
|
||||||
|
=====================================
|
||||||
|
|
||||||
|
Let's do some basic set up
|
||||||
|
|
||||||
|
>>> from zope import component, interface
|
||||||
|
>>> from zope.traversing.api import getName
|
||||||
|
>>> from zope.app.testing.setup import placefulSetUp, placefulTearDown
|
||||||
|
>>> site = placefulSetUp(True)
|
||||||
|
|
||||||
|
and build a simple loops site with a concept manager and some concepts
|
||||||
|
(with a relation registry, a catalog, and all the type machinery - what
|
||||||
|
in real life is done via standard ZCML setup or via local utility
|
||||||
|
configuration):
|
||||||
|
|
||||||
|
>>> from loops.tests.setup import TestSite
|
||||||
|
>>> t = TestSite(site)
|
||||||
|
>>> concepts, resources, views = t.setup()
|
||||||
|
|
||||||
|
>>> len(concepts) + len(resources)
|
||||||
|
14
|
||||||
|
|
||||||
|
|
||||||
|
Accessing a Directory in the Filesystem
|
||||||
|
=======================================
|
||||||
|
|
||||||
|
Let's just reuse the settings of cybertools.integrator.
|
||||||
|
|
||||||
|
>>> from cybertools.integrator.tests import testDir
|
||||||
|
>>> from cybertools.integrator.filesystem import ContainerFactory, FileFactory
|
||||||
|
>>> component.provideUtility(ContainerFactory(), name='filesystem')
|
||||||
|
>>> component.provideUtility(FileFactory(), name='filesystem')
|
||||||
|
|
||||||
|
>>> from loops.integrator.content.base import ExternalAccess
|
||||||
|
>>> component.provideAdapter(ExternalAccess)
|
||||||
|
|
||||||
|
>>> from loops.setup import addAndConfigureObject
|
||||||
|
>>> from loops.concept import Concept
|
||||||
|
>>> from loops.integrator.content.interfaces import IExternalAccess
|
||||||
|
>>> typeConcept = concepts.getTypeConcept()
|
||||||
|
>>> tExtAccess = addAndConfigureObject(concepts, Concept, 'extaccess',
|
||||||
|
... conceptType=typeConcept, typeInterface=IExternalAccess)
|
||||||
|
|
||||||
|
>>> xa01 = addAndConfigureObject(concepts, Concept, 'xa01',
|
||||||
|
... conceptType=tExtAccess,
|
||||||
|
... providerName='filesystem', baseAddress=testDir)
|
||||||
|
|
||||||
|
>>> from loops.common import adapted
|
||||||
|
>>> xa01_ad =adapted(xa01)
|
||||||
|
|
||||||
|
>>> directory = xa01_ad()
|
||||||
|
>>> sorted(directory)
|
||||||
|
['index.html', 'sub']
|
||||||
|
|
||||||
|
|
||||||
|
Traversing Content Trees
|
||||||
|
========================
|
||||||
|
|
||||||
|
|
||||||
|
Fin de partie
|
||||||
|
=============
|
||||||
|
|
||||||
|
>>> placefulTearDown()
|
4
integrator/content/__init__.py
Normal file
4
integrator/content/__init__.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
"""
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
54
integrator/content/base.py
Normal file
54
integrator/content/base.py
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Access to external objects.
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os, re
|
||||||
|
|
||||||
|
from zope import component
|
||||||
|
from zope.cachedescriptors.property import Lazy
|
||||||
|
from zope.component import adapts
|
||||||
|
from zope.interface import implements
|
||||||
|
|
||||||
|
from cybertools.integrator.interfaces import IContainerFactory
|
||||||
|
from loops.common import AdapterBase, adapted
|
||||||
|
from loops.integrator.content.interfaces import IExternalAccess
|
||||||
|
from loops.interfaces import IConcept
|
||||||
|
from loops.type import TypeInterfaceSourceList
|
||||||
|
|
||||||
|
|
||||||
|
TypeInterfaceSourceList.typeInterfaces += (IExternalAccess,)
|
||||||
|
|
||||||
|
|
||||||
|
class ExternalAccess(AdapterBase):
|
||||||
|
""" A concept adapter for accessing external collection.
|
||||||
|
"""
|
||||||
|
|
||||||
|
implements(IExternalAccess)
|
||||||
|
adapts(IConcept)
|
||||||
|
|
||||||
|
_contextAttributes = list(IExternalAccess) + list(IConcept)
|
||||||
|
|
||||||
|
def __call__(self):
|
||||||
|
factory = component.getUtility(IContainerFactory, self.providerName)
|
||||||
|
address = os.path.join(self.baseAddress, self.address or '')
|
||||||
|
return factory(address, __parent__=self.context)
|
47
integrator/content/browser.py
Normal file
47
integrator/content/browser.py
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
View class(es) for accessing external objects.
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
||||||
|
from zope import interface, component
|
||||||
|
from zope.app.publisher.browser import getDefaultViewName
|
||||||
|
from zope.cachedescriptors.property import Lazy
|
||||||
|
|
||||||
|
from loops.browser.concept import ConceptView
|
||||||
|
from loops.browser.node import NodeView
|
||||||
|
from loops.common import adapted
|
||||||
|
|
||||||
|
|
||||||
|
class ExternalAccessView(NodeView):
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
def adapted(self):
|
||||||
|
return adapted(self.virtualTargetObject)
|
||||||
|
|
||||||
|
def __call__(self):
|
||||||
|
obj = self.adapted()
|
||||||
|
name = getDefaultViewName(obj, self.request)
|
||||||
|
view = component.getMultiAdapter((obj, self.request), name=name)
|
||||||
|
return view()
|
||||||
|
|
||||||
|
def publishTraverse(self, request, name):
|
||||||
|
return self.adapted()[name]
|
50
integrator/content/configure.zcml
Normal file
50
integrator/content/configure.zcml
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
<!-- $Id$ -->
|
||||||
|
|
||||||
|
<configure
|
||||||
|
xmlns:zope="http://namespaces.zope.org/zope"
|
||||||
|
xmlns:browser="http://namespaces.zope.org/browser"
|
||||||
|
i18n_domain="loops">
|
||||||
|
|
||||||
|
<zope:adapter factory="loops.integrator.content.base.ExternalAccess"
|
||||||
|
trusted="True" />
|
||||||
|
<zope:class class="loops.integrator.content.base.ExternalAccess">
|
||||||
|
<require permission="zope.View"
|
||||||
|
interface="loops.integrator.content.interfaces.IExternalAccess" />
|
||||||
|
<require permission="zope.ManageContent"
|
||||||
|
set_schema="loops.integrator.content.interfaces.IExternalAccess" />
|
||||||
|
</zope:class>
|
||||||
|
|
||||||
|
<zope:class class="cybertools.integrator.filesystem.ReadContainer">
|
||||||
|
<require permission="zope.View"
|
||||||
|
interface="zope.app.container.interfaces.IReadContainer" />
|
||||||
|
</zope:class>
|
||||||
|
|
||||||
|
<zope:class class="cybertools.integrator.filesystem.File">
|
||||||
|
<require permission="zope.View"
|
||||||
|
interface="zope.app.file.interfaces.IFile" />
|
||||||
|
</zope:class>
|
||||||
|
|
||||||
|
<zope:class class="cybertools.integrator.filesystem.Image">
|
||||||
|
<require permission="zope.View"
|
||||||
|
interface="zope.app.file.interfaces.IImage" />
|
||||||
|
</zope:class>
|
||||||
|
|
||||||
|
<zope:utility factory="cybertools.integrator.filesystem.ContainerFactory"
|
||||||
|
name="filesystem" />
|
||||||
|
|
||||||
|
<zope:utility factory="cybertools.integrator.filesystem.FileFactory"
|
||||||
|
name="filesystem" />
|
||||||
|
|
||||||
|
<!-- view(s) -->
|
||||||
|
|
||||||
|
<browser:page
|
||||||
|
name="xa"
|
||||||
|
for="loops.interfaces.INode"
|
||||||
|
class="loops.integrator.content.browser.ExternalAccessView"
|
||||||
|
permission="zope.View" />
|
||||||
|
|
||||||
|
<browser:containerViews
|
||||||
|
for="zope.app.container.interfaces.IReadContainer"
|
||||||
|
index="zope.View" />
|
||||||
|
|
||||||
|
</configure>
|
61
integrator/content/interfaces.py
Normal file
61
integrator/content/interfaces.py
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
External content integration interfaces.
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
||||||
|
from zope.interface import Interface, Attribute
|
||||||
|
from zope import interface, component, schema
|
||||||
|
|
||||||
|
from loops.interfaces import IConceptSchema
|
||||||
|
from loops.util import _
|
||||||
|
|
||||||
|
|
||||||
|
class IExternalAccess(IConceptSchema):
|
||||||
|
""" A concept adapter providing access to objects in an external system.
|
||||||
|
"""
|
||||||
|
|
||||||
|
providerName = schema.TextLine(
|
||||||
|
title=_(u'Provider name'),
|
||||||
|
description=_(u'The name of a utility that provides access to the '
|
||||||
|
'external objects, typically a factory of proxy '
|
||||||
|
'objects.'),
|
||||||
|
required=False)
|
||||||
|
baseAddress = schema.TextLine(
|
||||||
|
title=_(u'Base address'),
|
||||||
|
description=_(u'A base path or URL for accessing the external '
|
||||||
|
'object.'),
|
||||||
|
required=True)
|
||||||
|
address = schema.TextLine(
|
||||||
|
title=_(u'Relative address'),
|
||||||
|
description=_(u'Optional second (local) part of the '
|
||||||
|
'external objects\'s address, e.g. a directory name.'),
|
||||||
|
required=False)
|
||||||
|
pattern = schema.TextLine(
|
||||||
|
title=_(u'Selection pattern'),
|
||||||
|
description=_(u'A regular expression for selecting external objects '
|
||||||
|
'that should be made accessible.'),
|
||||||
|
required=False)
|
||||||
|
|
||||||
|
def __call__():
|
||||||
|
""" Return an object representing the top-level external object.
|
||||||
|
This is typically a container proxy.
|
||||||
|
"""
|
23
integrator/content/tests.py
Executable file
23
integrator/content/tests.py
Executable file
|
@ -0,0 +1,23 @@
|
||||||
|
# $Id$
|
||||||
|
|
||||||
|
import unittest, doctest
|
||||||
|
from zope.testing.doctestunit import DocFileSuite
|
||||||
|
from zope.interface.verify import verifyClass
|
||||||
|
#from loops.versioning import versionable
|
||||||
|
|
||||||
|
class Test(unittest.TestCase):
|
||||||
|
"Basic tests for the loops.integrator.content package."
|
||||||
|
|
||||||
|
def testSomething(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def test_suite():
|
||||||
|
flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
|
||||||
|
return unittest.TestSuite((
|
||||||
|
unittest.makeSuite(Test),
|
||||||
|
DocFileSuite('README.txt', optionflags=flags),
|
||||||
|
))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main(defaultTest='test_suite')
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 2007 Helmut Merz helmutm@cy55.de
|
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Intergrator interfaces.
|
Integrator interfaces.
|
||||||
|
|
||||||
$Id$
|
$Id$
|
||||||
"""
|
"""
|
||||||
|
@ -98,28 +98,5 @@ class IExternalCollectionProvider(Interface):
|
||||||
provided. Return the list of objects created.
|
provided. Return the list of objects created.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# classification stuff
|
# classification stuff moved to loops.classifier
|
||||||
|
|
||||||
class IAutoClassifier(Interface):
|
|
||||||
""" An adapter that more or less automagically assigns concepts to a
|
|
||||||
resource using some sort of selection criteria for the concepts
|
|
||||||
that should be considered.
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class IOntologyExporter(Interface):
|
|
||||||
""" An adapter for creating an XML file with all appropriate informations
|
|
||||||
from the context and its children, selecting children via a
|
|
||||||
pattern or a set of selection criteria.
|
|
||||||
|
|
||||||
This may then be used by an external tool for classifying
|
|
||||||
a set of external objects.
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class IClassificationImporter(Interface):
|
|
||||||
""" An Adapter for importing an XML file with classification
|
|
||||||
information for a collection of external objects."
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue