Author: jmorliaguet
Date: Sun Nov 27 12:35:31 2005
New Revision: 1941

Modified:
   cpsskins/branches/jmo-perspectives/configuration/resources/metaconfigure.py
   cpsskins/branches/jmo-perspectives/engines/sitedesigner/browser.py
   cpsskins/branches/jmo-perspectives/engines/sitedesigner/configure.zcml
   cpsskins/branches/jmo-perspectives/engines/sitedesigner/site_designer.pt
   cpsskins/branches/jmo-perspectives/setup/interfaces.py
Log:

- added a proof-of-concept filesystem exporter of settings



Modified: 
cpsskins/branches/jmo-perspectives/configuration/resources/metaconfigure.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/configuration/resources/metaconfigure.py 
(original)
+++ cpsskins/branches/jmo-perspectives/configuration/resources/metaconfigure.py 
Sun Nov 27 12:35:31 2005
@@ -18,8 +18,11 @@
 __docformat__ = "reStructuredText"
 
 from zope.configuration.exceptions import ConfigurationError
-from zope.xmlpickle import xmlpickle
 from zope.component import providedBy, provideUtility
+from zope.interface import alsoProvides
+from zope.xmlpickle import xmlpickle
+
+from cpsskins.setup.interfaces import IResourceType
 
 def resources(_context, type=None, file=None):
 
@@ -44,4 +47,5 @@
                             "the promised interface.")
 
         provideUtility(resource, type, resource.name)
+        alsoProvides(type, IResourceType)
 

Modified: cpsskins/branches/jmo-perspectives/engines/sitedesigner/browser.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/engines/sitedesigner/browser.py  
(original)
+++ cpsskins/branches/jmo-perspectives/engines/sitedesigner/browser.py  Sun Nov 
27 12:35:31 2005
@@ -17,13 +17,37 @@
 """
 __docformat__ = "reStructuredText"
 
+import time
+import zipfile
+
+from tarfile import TarFile, TarInfo
+from cStringIO import StringIO
+
 from zope.app.publisher.browser import BrowserView
 from zope.component import getUtilitiesFor, getUtility
 from zope.app.interface import queryType
 from zope import xmlpickle 
 
-from cpsskins.setup.interfaces import (ISetting, ISettingType,
-                                       IResource, IResourceManager)
+from cpsskins.setup.interfaces import (
+    ISetting, ISettingType, IResourceType, IResource, IResourceManager)
+
+
+setting_xml = """
+<configure
+    xmlns="http://namespaces.zope.org/cpsskins";>
+
+  <resources
+      type="%(resource_type)s"
+      file="%(resource_filename)s"
+  />
+
+  <perspective
+      name="%(setting_name)s"
+      resource="%(resource_name)s"
+  />
+
+</configure>
+"""
 
 class SiteDesignerView(BrowserView):
 
@@ -33,8 +57,8 @@
         info = {}
         # get all settings
         for name, setting in getUtilitiesFor(ISetting):
-            type_name = queryType(setting, ISettingType).__name__
-            info.setdefault(type_name, []).append({'name': name,
+            setting_type = queryType(setting, ISettingType).__name__
+            info.setdefault(setting_type, []).append({'name': name,
                 'setting': setting, 'customized': False})
         return info
 
@@ -49,16 +73,46 @@
         target = self.request.get('HTTP_REFERER', '.')
         self.request.response.redirect(target)
 
-    def exportResource(self, name=u''):
-        """Export the resource as XML.
+    def exportSetting(self, name=u''):
+        """Export the setting as a zip file.
         """
         if not name:
             raise KeyError("Must specify a setting's name.")
 
         setting =  getUtility(ISetting, name)
         resource = IResource(setting).getResource()
+        resource_type = queryType(resource, IResourceType)
+
+        archive_filename = '%s.tgz' % name.replace(' ', '_')
+        resource_filename = '%s.xml' % name
 
         response = self.request.response
-        response.setHeader('content-type', 'text/xml')
-        return xmlpickle.dumps(resource)
+        response.setHeader('content-type', 'application/x-gzip')
+        response.setHeader('Content-disposition',
+                           'attachment; filename=%s' % archive_filename)
+
+        # TODO to move to cpsskins.setup
+        pickle = xmlpickle.dumps(resource)
+        archive = StringIO()
+        file = TarFile.open(archive_filename, 'w:gz', archive)
+
+        # export the resource
+        info = TarInfo(resource_filename)
+        info.size = len(pickle)
+        info.mtime = time.time()
+        file.addfile(info, StringIO(pickle))
+
+        # write the zcml
+        info = TarInfo('%s.zcml' % name)
+        setting_zcml = setting_xml % {
+            'resource_type': resource_type.__identifier__,
+            'setting_name': name,
+            'resource_name': resource.name,
+            'resource_filename': resource_filename,
+            }
+        info.size = len(setting_zcml)
+        info.mtime = time.time()
+        file.addfile(info, StringIO(setting_zcml))
 
+        file.close()
+        return archive.getvalue()

Modified: cpsskins/branches/jmo-perspectives/engines/sitedesigner/configure.zcml
==============================================================================
--- cpsskins/branches/jmo-perspectives/engines/sitedesigner/configure.zcml      
(original)
+++ cpsskins/branches/jmo-perspectives/engines/sitedesigner/configure.zcml      
Sun Nov 27 12:35:31 2005
@@ -41,8 +41,8 @@
     />
 
     <page
-        name="exportResource"
-        attribute="exportResource"
+        name="exportSetting"
+        attribute="exportSetting"
     />
 
   </pages>

Modified: 
cpsskins/branches/jmo-perspectives/engines/sitedesigner/site_designer.pt
==============================================================================
--- cpsskins/branches/jmo-perspectives/engines/sitedesigner/site_designer.pt    
(original)
+++ cpsskins/branches/jmo-perspectives/engines/sitedesigner/site_designer.pt    
Sun Nov 27 12:35:31 2005
@@ -50,6 +50,7 @@
                 <tal:block define="name info/name">
                   <a tal:attributes="href string:@@customizeSetting?name=$name"
                      tal:condition="info/setting/readonly">[customize]</a>
+                  <a tal:attributes="href 
string:@@exportSetting?name=$name">[export]</a>
                 </tal:block>
               </li>
             </ul>

Modified: cpsskins/branches/jmo-perspectives/setup/interfaces.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/setup/interfaces.py      (original)
+++ cpsskins/branches/jmo-perspectives/setup/interfaces.py      Sun Nov 27 
12:35:31 2005
@@ -27,6 +27,9 @@
 class ISettingType(IInterface):
     """ """
 
+class IResourceType(IInterface):
+    """ """
+
 class ISetting(Interface):
     """ """
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to