Author: jmorliaguet
Date: Sun Apr 30 14:52:11 2006
New Revision: 2997

Added:
   cpsskins/branches/paris-sprint-2006/configuration/formats/metaconfigure.py   
(contents, props changed)
Removed:
   cpsskins/branches/paris-sprint-2006/tests/test_relation_io.py
Modified:
   cpsskins/branches/paris-sprint-2006/configuration/displays/metaconfigure.py
   cpsskins/branches/paris-sprint-2006/setup/DOM.txt
   cpsskins/branches/paris-sprint-2006/setup/README.txt
   cpsskins/branches/paris-sprint-2006/setup/interfaces.py
   cpsskins/branches/paris-sprint-2006/setup/io.py
   cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py
Log:

- saving work: began working on XML imports



Modified: 
cpsskins/branches/paris-sprint-2006/configuration/displays/metaconfigure.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/configuration/displays/metaconfigure.py 
(original)
+++ cpsskins/branches/paris-sprint-2006/configuration/displays/metaconfigure.py 
Sun Apr 30 14:52:11 2006
@@ -23,13 +23,14 @@
 from zope.app.content.interfaces import IContentType
 from zope.configuration.exceptions import ConfigurationError
 from zope.component.interface import provideInterface
+from zope.component.interfaces import IFactory
 from zope.component import queryUtility
 from zope.interface import alsoProvides
 
 from cpsskins import configuration
 from cpsskins.elements.interfaces import IElementType
 from cpsskins.elements.interfaces import IDisplay
-from cpsskins.setup.interfaces import INameType
+from cpsskins.setup.interfaces import IResourceType, INameType
 
 def display(_context, name=u'', schema=None, factory=None):
 
@@ -62,11 +63,15 @@
     adapter(_context=_context, factory=(factory,), provides=schema,
             for_=(IDisplay,), name=name)
 
+    # register the format factory
+    utility(_context=_context, provides=IFactory, component=factory, name=name)
+
     # register the display
     utility(_context=_context, provides=configuration.IDisplay,
             component=configuration.Display(factory=factory), name=name)
 
     # set up interface types
+    alsoProvides(schema, IResourceType)
     alsoProvides(schema, IContentType)
 
     interface(_context=_context, interface=schema, type=INameType, name=name)

Added: 
cpsskins/branches/paris-sprint-2006/configuration/formats/metaconfigure.py
==============================================================================
--- (empty file)
+++ cpsskins/branches/paris-sprint-2006/configuration/formats/metaconfigure.py  
Sun Apr 30 14:52:11 2006
@@ -0,0 +1,89 @@
+##############################################################################
+#
+# Copyright (c) 2005-2006 Nuxeo 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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+import os
+
+from zope.annotation.interfaces import IAttributeAnnotatable
+from zope.app.component.contentdirective import ClassDirective
+from zope.app.content.interfaces import IContentType
+from zope.configuration.exceptions import ConfigurationError
+from zope.component import queryUtility
+from zope.component.zcml import utility, interface
+from zope.component.interfaces import IFactory
+from zope.interface import alsoProvides
+
+from cpsskins.elements.interfaces import IElementType, IFormat
+from cpsskins.ontology import FormatPredicate, IFormatPredicate
+from cpsskins.setup.interfaces import IResourceType, INameType
+
+registered_formats = []
+
+def getAbsolutePath(_context, file):
+    return os.path.abspath(str(_context.path(file)))
+
+def format(_context, name=u'', schema=None, class_=None, factory=None,
+           predicate=None):
+
+    if not name:
+        raise ConfigurationError("Must specify the format name.")
+
+    if not name.isalpha():
+        raise ConfigurationError(
+            "Format names can only contain alphabetic characters.")
+
+    if name in registered_formats:
+        raise ConfigurationError(
+            "A format with the name '%s' has already been registered." % name)
+
+    if not class_:
+        raise ConfigurationError("Must specify the format content class.")
+
+    if not schema:
+        raise ConfigurationError("Must specify the format schema.")
+
+    if not factory:
+        raise ConfigurationError("Must specify a format factory.")
+
+    if not predicate:
+        raise ConfigurationError("Must specify a format predicate.")
+
+    # zope:content
+    c = ClassDirective(_context=_context, class_=class_)
+    c.implements(_context=_context,interface=(IAttributeAnnotatable,))
+    c.require(_context=_context, permission="zope.View", interface=(schema,))
+    c.require(_context=_context, permission="zope.ManageContent",
+              set_schema=(schema,))
+
+    # register the format factory
+    utility(_context=_context, provides=IFactory, component=factory, name=name)
+
+    # register the predicate
+    utility(_context=_context, provides=IFormatPredicate,
+            component=FormatPredicate(predicate), name=name)
+
+    # set up interface types
+    alsoProvides(schema, IResourceType)
+    alsoProvides(schema, IContentType)
+
+    interface(_context=_context, interface=schema, type=INameType, name=name)
+
+    # set tagged values
+    schema.setTaggedValue('predicate', predicate)
+
+    registered_formats.append(name)

Modified: cpsskins/branches/paris-sprint-2006/setup/DOM.txt
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/DOM.txt   (original)
+++ cpsskins/branches/paris-sprint-2006/setup/DOM.txt   Sun Apr 30 14:52:11 2006
@@ -90,4 +90,8 @@
     </themes>
     <BLANKLINE>
 
+Finally we free the memory:
+
+    >>> doc.unlink()
+
 [1] http://docs.python.org/lib/module-xml.dom.html

Modified: cpsskins/branches/paris-sprint-2006/setup/README.txt
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/README.txt        (original)
+++ cpsskins/branches/paris-sprint-2006/setup/README.txt        Sun Apr 30 
14:52:11 2006
@@ -656,6 +656,21 @@
     </portlets>
     <BLANKLINE>
 
+
+Export of display elements
+-------------------------
+
+    >>> from cpsskins.standard.displays.area import Area
+    >>> area = Area()
+
+    >>> print toXML(area, u'displays')
+    <?xml version="1.0" encoding="utf-8"?>
+    <displays>
+      <area uri="cpsskins://display-area:12345"/>
+    </displays>
+    <BLANKLINE>
+
+
 Export of format elements
 -------------------------
 

Modified: cpsskins/branches/paris-sprint-2006/setup/interfaces.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/interfaces.py     (original)
+++ cpsskins/branches/paris-sprint-2006/setup/interfaces.py     Sun Apr 30 
14:52:11 2006
@@ -111,9 +111,12 @@
     def getDocument():
         """Get the document element"""
 
-    def writeAsAttributes():
+    def writeAsAttributes(attributes):
         """Set the list of fields written as attributes."""
 
+    def setURIMapping(mapping):
+        """Set the URI mapping."""
+
     def save():
         """Save data as a DOM fragment."""
 

Modified: cpsskins/branches/paris-sprint-2006/setup/io.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/io.py     (original)
+++ cpsskins/branches/paris-sprint-2006/setup/io.py     Sun Apr 30 14:52:11 2006
@@ -53,6 +53,9 @@
     def writeAsAttributes(self, attributes):
         self.attributes = attributes
 
+    def setURIMapping(self, mapping):
+        self.mapping = mapping
+
     def save(self):
         """Save data in the DOM fragment.
         """
@@ -123,15 +126,14 @@
             text = node.getAttribute(name)
 
             field_io = IFieldIO(field, None)
-            if field_io is not None:
-                value = field_io.load(text)
+            if field_io is None:
+                raise TypeError("No field adapter found for '%s'." % field)
             else:
-                value = text
-
-            if getattr(context, name, _marker) is _marker:
-                logger.warning("%s has no attribute '%s'", repr(context), name)
-                continue
-            setattr(context, name, value)
+                try:
+                    value = field_io.load(text)
+                    setattr(context, name, value)
+                except:
+                    print text
 
 
 #######################################################################
@@ -170,7 +172,9 @@
 
     def load(self, text):
         # TODO unescape ','
-        return text.split(', ')
+        obj = text.split(', ')
+        self.field.validate(obj)
+        return obj
 
 class IntField(BaseFieldIO):
     """An integer field.

Modified: cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py 
(original)
+++ cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py Sun Apr 
30 14:52:11 2006
@@ -17,13 +17,13 @@
 """
 __docformat__ = "reStructuredText"
 
-from xml.dom.minidom import parseString, DOMImplementation
+from xml.dom.minidom import parseString, DOMImplementation, Node
 
 from zope.app.interface import queryType
 from zope.app.file import File
 from zope.component import getUtilitiesFor, getUtility, getMultiAdapter
 from zope.component import queryUtility, getAllUtilitiesRegisteredFor
-from zope.component import getMultiAdapter
+from zope.component import createObject
 
 from cpsskins import minjson as json
 from cpsskins.elements.interfaces import IType
@@ -165,11 +165,11 @@
     def importSite(self, file=None):
         archive = TarArchive(mode='r', data=file.read())
         mgr = getThemeManager(self.context)
-        uri_mapping = {}
 
         # themes
         themes_data = archive[u'themes.xml']
 
+        uri_mapping = {}
         # storages
         for storage_id in u'formats', u'displays', u'portlets':
             storage = mgr[storage_id]
@@ -182,10 +182,16 @@
         relations = mgr.getRelationStorage()
         relations.purge()
 
-        dom = parseString(archive[u'relations.xml'])
-        importer = getMultiAdapter((relations, self.request), IDataImporter)
-        importer.mapping = uri_mapping
-        importer.load(dom)
+        document = parseString(archive[u'relations.xml'])
+        root = document.documentElement
+
+        for el in root.childNodes:
+            if el.nodeType != Node.ELEMENT_NODE:
+                continue
+            importer = getMultiAdapter((relation, el), IDOMAdapter)
+            importer.setDocument(document)
+            importer.setURIMapping(uri_mapping)
+            importer.load(dom)
 
 
     ### Snapshots  ####################################################
@@ -259,10 +265,23 @@
         mgr = getThemeManager(self.context)
         storage = mgr[name]
 
-        dom = parseString(xml)
-        importer = getMultiAdapter((storage, request), IDataImporter)
-        importer.load(dom)
-        return importer.mapping
+        document = parseString(xml)
+        root = document.documentElement
+
+        uri_mapping = {}
+
+        for el in root.childNodes:
+            if el.nodeType != Node.ELEMENT_NODE:
+                continue
+            typename = el.tagName
+            obj = createObject(typename)
+            importer = getMultiAdapter((obj, el), IDOMAdapter)
+            importer.setDocument(document)
+            importer.load()
+
+            uri_mapping.update(importer.mapping)
+
+        return uri_mapping
 
 
     ### Themes  #######################################################
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to