loops/external
helmutm 8e8797a4d1 work in progress: sub-elements, e.g. for annotations and state information - export OK
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2478 fd906abe-77d9-0310-91a1-e0d9ade77398
2008-03-28 13:22:55 +00:00
..
testdata/import added export/import of resources and resource relations, storing resource data (text/content) in files 2008-03-23 21:37:28 +00:00
__init__.py added node export/import to external package; deprecate old node export/import 2008-03-05 17:22:34 +00:00
annotation.py work in progress: sub-elements, e.g. for annotations and state information - export OK 2008-03-28 13:22:55 +00:00
base.py work in progress: sub-elements, e.g. for annotations and state information - export OK 2008-03-28 13:22:55 +00:00
browser.py work in progress: sub-elements, e.g. for annotations and state information, for export/import 2008-03-28 12:42:47 +00:00
configure.zcml work in progress: sub-elements, e.g. for annotations and state information - export OK 2008-03-28 13:22:55 +00:00
element.py work in progress: sub-elements, e.g. for annotations and state information, for export/import 2008-03-28 12:42:47 +00:00
exportimport.pt merged Dojo 1.0 branch 2008-02-10 09:56:42 +00:00
external.py added node export/import to external package; deprecate old node export/import 2008-03-05 17:22:34 +00:00
interfaces.py work in progress: sub-elements, e.g. for annotations and state information, for export/import 2008-03-28 12:42:47 +00:00
loops_std.dmp added an example export file for easy set up of new loops sites 2008-03-19 09:35:23 +00:00
pyfunc.py work in progress: sub-elements, e.g. for annotations and state information, for export/import 2008-03-28 12:42:47 +00:00
README.txt work in progress: sub-elements, e.g. for annotations and state information, for export/import 2008-03-28 12:42:47 +00:00
tests.py added export/import of resources and resource relations, storing resource data (text/content) in files 2008-03-23 21:37:28 +00:00

===============================================================
loops - Linked Objects for Organization and Processing Services
===============================================================

  ($Id$)

  >>> from zope import component
  >>> from zope.traversing.api import getName

Let's set up a loops site with basic and example concepts and resources.

  >>> from zope.app.testing.setup import placefulSetUp, placefulTearDown
  >>> site = placefulSetUp(True)

  >>> from loops.tests.setup import TestSite
  >>> t = TestSite(site)
  >>> concepts, resources, views = t.setup()
  >>> loopsRoot = site['loops']
  >>> len(concepts), len(resources), len(views)
  (11, 3, 0)


Importing loops Objects
=======================

Reading object information from an external source
--------------------------------------------------

  >>> from loops.external.pyfunc import PyReader

  >>> input = "concept('myquery', u'My Query', 'query', viewName='mystuff.html')"
  >>> reader = PyReader()
  >>> elements = reader.read(input)
  >>> elements
  [{'type': 'query', 'name': 'myquery', 'viewName': 'mystuff.html', 'title': u'My Query'}]

Creating the corresponding objects
----------------------------------

  >>> from loops.external.base import Loader

  >>> loader = Loader(loopsRoot)
  >>> loader.load(elements)
  >>> len(concepts), len(resources), len(views)
  (12, 3, 0)

  >>> from loops.common import adapted
  >>> adapted(concepts['myquery']).viewName
  'mystuff.html'

Working with resources
----------------------

  >>> import os
  >>> from loops.external.tests import dataDirectory
  >>> loader.resourceDirectory = os.path.join(dataDirectory, 'import')

  >>> input = ("resource('doc04.txt', u'Document 4', 'textdocument')\n"
  ...          "resourceRelation('myquery', 'doc04.txt', 'standard')")
  >>> reader = PyReader()
  >>> elements = reader.read(input)
  >>> loader.load(elements)

  >>> sorted(resources)
  [u'd001.txt', u'd002.txt', u'd003.txt', u'doc04.txt']

Working with nodes
------------------

  >>> input = ("node('home', u'Home', '', u'menu', body=u'Welcome')\n"
  ...          "node('myquery', u'My Query', 'home', u'page', "
  ...          "     target='concepts/myquery')")
  >>> reader = PyReader()
  >>> elements = reader.read(input)
  >>> loader.load(elements)

Sub-elements
------------

  >>> from loops.external import annotation

  >>> input = """concept('myquery', u'My Query', 'query', viewName='mystuff.html')[
  ...     annotations(creators='john')]"""
  >>> elements = reader.read(input)
  >>> elements[0].subElements
  [{'creators': 'john'}]

  >>> loader.load(elements)
  [('creators', 'john')]

Exporting loops Objects
=======================

Extracting elements
-------------------

  >>> from loops.external.base import Extractor
  >>> extractor = Extractor(loopsRoot, os.path.join(dataDirectory, 'export'))
  >>> elements = list(extractor.extract())
  >>> len(elements)
  20

Writing object information to the external storage
--------------------------------------------------

  >>> from loops.external.pyfunc import PyWriter
  >>> from cStringIO import StringIO

  >>> output = StringIO()
  >>> writer = PyWriter()
  >>> writer.write(elements, output)
  >>> print output.getvalue()
  type(u'customer', u'Customer', options=u'', typeInterface=u'', viewName=u'')...
  type(u'query', u'Query', options=u'', typeInterface='loops.query.IQueryConcept',
       viewName=u'')...
  concept(u'myquery', u'My Query', u'query', options=u'', viewName='mystuff.html')...
  child(u'projects', u'customer', u'standard')...
  resource(u'doc04.txt', u'Document 4', u'textdocument', contentType='text/restructured')
  resourceRelation(u'myquery', u'doc04.txt', u'standard')
  node('home', u'Home', '', u'menu', body=u'Welcome')
  node('myquery', u'My Query', 'home', u'page', target=u'concepts/myquery')...

Writing subElements
-------------------

  >>> input = """concept('myquery', u'My Query', 'query', viewName='mystuff.html')[
  ...     annotations(creators='john'),
  ...     annotations(modified='2007-08-12')]"""
  >>> elements = reader.read(input)
  >>> output = StringIO()
  >>> writer.write(elements, output)
  >>> print output.getvalue()
  concept('myquery', u'My Query', 'query', viewName='mystuff.html')[
      annotations(creators='john'),
      annotations(modified='2007-08-12')]...


The Export/Import View
======================

  >>> from loops.external.browser import ExportImport
  >>> from zope.publisher.browser import TestRequest

  >>> input = {'field.data': output, 'resourceDirectory': dataDirectory}
  >>> view = ExportImport(loopsRoot, TestRequest(input))
  >>> view.upload()
  False


Fin de Partie
=============

  >>> placefulTearDown()

  >>> exportDir = os.path.join(dataDirectory, 'export')
  >>> for fname in os.listdir(exportDir):
  ...     path = os.path.join(exportDir, fname)
  ...     if not os.path.isdir(path):
  ...         os.unlink(path)