Author: jmorliaguet
Date: Thu May  4 22:24:50 2006
New Revision: 3045

Added:
   cpsskins/branches/paris-sprint-2006/setup/archives.py   (contents, props 
changed)
Modified:
   cpsskins/branches/paris-sprint-2006/setup/utils.py
   cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py

Log:

- moved TarArchive to setup.archives



Added: cpsskins/branches/paris-sprint-2006/setup/archives.py
==============================================================================
--- (empty file)
+++ cpsskins/branches/paris-sprint-2006/setup/archives.py       Thu May  4 
22:24:50 2006
@@ -0,0 +1,68 @@
+##############################################################################
+#
+# 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 time
+
+from StringIO import StringIO
+from tarfile import TarFile
+from tarfile import TarInfo
+
+from zope.interface import Interface, implements
+
+class IArchive(Interface):
+
+    def __setitem__(k, v):
+        """Add an item to the archive."""
+
+    def __getitem__(k):
+        """Get an item from the archive."""
+
+    def __call__():
+        """Return the archive's data."""
+
+class TarArchive:
+
+    implements(IArchive)
+
+    def __init__(self, mode='r', data=''):
+        self.mode = mode
+        self.stream = StringIO(data)
+        self.archive = TarFile.open('', '%s:gz' % mode, self.stream)
+
+    def __setitem__(self, k, v):
+        if self.mode == 'r':
+            raise TypeError("This tar archive is read-only.")
+        stream = StringIO(v)
+        info = TarInfo(k)
+        info.size = len(v)
+        info.mtime = time.time()
+        self.archive.addfile(info, stream)
+
+    def __getitem__(self, k):
+        if self.mode == 'w':
+            raise TypeError("This tar archive is write-only.")
+        file = self.archive.extractfile(k)
+        return file.read()
+
+    def __call__(self):
+        if self.mode == 'r':
+            raise TypeError("This tar archive is read-only.")
+        self.archive.close()
+        return self.stream.getvalue()
+

Modified: cpsskins/branches/paris-sprint-2006/setup/utils.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/utils.py  (original)
+++ cpsskins/branches/paris-sprint-2006/setup/utils.py  Thu May  4 22:24:50 2006
@@ -17,13 +17,8 @@
 """
 __docformat__ = "reStructuredText"
 
-import time
 import logging
 
-from StringIO import StringIO
-from tarfile import TarFile
-from tarfile import TarInfo
-
 from zope.component import queryUtility, getUtilitiesFor
 
 from cpsskins.setup.interfaces import INameType
@@ -62,31 +57,3 @@
         names.append(name[0])
     return u'-'.join(names)
 
-class TarArchive:
-
-    def __init__(self, mode='r', data=''):
-        self.mode = mode
-        self.stream = StringIO(data)
-        self.archive = TarFile.open('', '%s:gz' % mode, self.stream)
-
-    def __setitem__(self, k, v):
-        if self.mode == 'r':
-            raise TypeError("This tar archive is read-only.")
-        stream = StringIO(v)
-        info = TarInfo(k)
-        info.size = len(v)
-        info.mtime = time.time()
-        self.archive.addfile(info, stream)
-
-    def __getitem__(self, k):
-        if self.mode == 'w':
-            raise TypeError("This tar archive is write-only.")
-        file = self.archive.extractfile(k)
-        return file.read()
-
-    def __call__(self):
-        if self.mode == 'r':
-            raise TypeError("This tar archive is read-only.")
-        self.archive.close()
-        return self.stream.getvalue()
-

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 Thu May 
 4 22:24:50 2006
@@ -17,26 +17,21 @@
 """
 __docformat__ = "reStructuredText"
 
-import time
-
 from xml.dom.minidom import parseString, DOMImplementation, Node
 
-from zope.app import zapi
 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 createObject, providedBy
+from zope.component import createObject
 
 from cpsskins import minjson as json
 from cpsskins import configuration
+from cpsskins.setup.archives import TarArchive
 from cpsskins.setup.interfaces import ISetting, IGlobalSetting, IDOMAdapter
 from cpsskins.setup.interfaces import IType
 from cpsskins.setup.interfaces import IResourceType, IResourceManager, 
IResource
 from cpsskins.setup.registration import reloadSetting, refreshSettings
-from cpsskins.setup.settings import ISettings
-from cpsskins.setup.utils import TarArchive, getTypeName
 from cpsskins.setup.snapshot import Snapshot
+from cpsskins.setup.utils import getTypeName
 from cpsskins.utils import getThemeManager
 
 class SiteDesignerView:
@@ -132,6 +127,7 @@
 
         for name in settings:
             exporter = getMultiAdapter((settings[name], root), IDOMAdapter)
+            exporter.archive = archive
             exporter.document = document
             exporter.save()
 
@@ -149,6 +145,7 @@
 
         dom = parseString(archive[u'setting.xml'])
         importer = getMultiAdapter((mgr, dom), IDOMAdapter, name=u'settings')
+        importer.archive = archive
         importer.load()
 
 
@@ -196,6 +193,7 @@
             relation = createObject(factory_name)
 
             importer = getMultiAdapter((relation, el), IDOMAdapter)
+            importer.archive = archive
             importer.document = document
             importer.mapping = uri_mapping
             importer.load()
@@ -267,6 +265,7 @@
 
         for id in storage:
             exporter = getMultiAdapter((storage[id], root), IDOMAdapter)
+            exporter.archive = archive
             exporter.document = document
             exporter.fields_as_attributes = u'title', u'description'
             exporter.save()
@@ -302,6 +301,7 @@
             storage.add(obj)
 
             importer = getMultiAdapter((obj, el), IDOMAdapter)
+            importer.archive = archive
             importer.document = document
             importer.object_type = typename
             importer.updateURIMapping()
@@ -322,6 +322,7 @@
 
         for theme in getThemeManager(self.context).getThemes():
             exporter = getMultiAdapter((theme, root), IDOMAdapter)
+            exporter.archive = archive
             exporter.document = document
             exporter.fields_as_attributes = u'title', u'description'
             exporter.ignored_fields = u'slot',
@@ -350,6 +351,7 @@
             mgr.addTheme(theme)
 
             importer = getMultiAdapter((theme, el), IDOMAdapter)
+            importer.archive = archive
             importer.document = document
             importer.object_type = u'canvas'
             importer.updateURIMapping()
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to