Author: jmorliaguet
Date: Thu Jun 22 16:09:37 2006
New Revision: 3491

Modified:
   cpsskins/branches/paris-sprint-2006/setup/io/migration.py

Log:

- trying to be more generic - recurse through the entire theme



Modified: cpsskins/branches/paris-sprint-2006/setup/io/migration.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/io/migration.py   (original)
+++ cpsskins/branches/paris-sprint-2006/setup/io/migration.py   Thu Jun 22 
16:09:37 2006
@@ -18,10 +18,8 @@
 __docformat__ = "reStructuredText"
 
 from xml.dom.minidom import parseString
-from zope.component import getUtility
+from zope.component import getUtility, createObject
 
-from cpsskins.elements.theme import Theme
-from cpsskins.elements.themepage import ThemePage
 from cpsskins.setup.archives import TarArchive
 from cpsskins.setup.interfaces import IResourceManager
 from cpsskins.standard.fields.image import WebImage
@@ -30,6 +28,22 @@
 class Migration(object):
     """Migration utility for importing CPSSkins v2 themes
     """
+
+    meta_types = {
+        'Portal Theme': 'cpsskins.canvas.theme',
+        'Theme Page': 'cpsskins.canvas.themepage',
+        'Page Block': 'cpsskins.canvas.pageblock',
+        'Cell': 'cpsskins.canvas.cell',
+        'Slot': 'cpsskins.canvas.slot',
+    }
+
+    children_types = {
+        'Portal Theme': ('Theme Page',),
+        'Theme Page': ('Page Block',),
+        'Page Block': ('Cell',),
+        'Cell': ('Slot',),
+    }
+
     def __init__(self, file):
         self.file = file
 
@@ -65,16 +79,26 @@
         theme_name = theme_node.getAttribute('name')
         props = self.getProperties(theme_node, 'title', 'author', 'copyright',
                                   'license')
-        theme = Theme(**props)
+        theme = createObject('cpsskins.canvas.theme', **props)
         self.themes.addTheme(theme, name=theme_name)
 
-        page_names = self.getObjects(doc.childNodes[0], 'Theme Page').keys()
-        for page_name in page_names:
-            page_path = 'themes/%s/%s.xml' % (theme_name, page_name)
-            page_node = parseString(archive[page_path])
-            props = self.getProperties(page_node, 'title')
-            page = ThemePage(**props)
-            themes.addPage(theme, page)
+        self.importObject(theme_node, theme, 'themes/%s' % theme_name)
+
+    def importObject(self, node, obj, current_path):
+        archive = self.archive
+        meta_type = node.getAttribute('meta_type')
+        meta_types = self.meta_types
+        children_types = self.children_types[meta_type]
+        names = self.getObjects(node, children_types).keys()
+        for name in names:
+            path = '%s/%s.xml' % (current_path, name)
+            child_doc = parseString(archive[path])
+            child_node = child_doc.childNodes[0]
+            child_type = child_node.getAttribute('meta_type')
+            props = self.getProperties(child_node, 'title')
+            obj[name] = createObject(meta_types[child_type], **props)
+
+            self.importObject(child_node, obj, current_path + '/' + name)
 
     def importImages(self, theme_name):
         resources = self.resources
@@ -100,12 +124,12 @@
             info[str(name)] = value
         return info
 
-    def getObjects(self, node=None, type=u''):
+    def getObjects(self, node=None, types=()):
         info = {}
         for obj in node.getElementsByTagName('object'):
             name = obj.getAttribute('name')
             meta_type = obj.getAttribute('meta_type')
-            if type and type != meta_type:
+            if type and meta_type not in types:
                 continue
             info[name] = meta_type
         return info
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to