Author: jmorliaguet
Date: Sun May 21 22:28:47 2006
New Revision: 3188

Modified:
   cpsskins/branches/paris-sprint-2006/setup/archives.py
   cpsskins/branches/paris-sprint-2006/setup/io/utils.py
   cpsskins/branches/paris-sprint-2006/setup/registration.py

Log:

- added a file-system archive for reading directly from the file-system
  (used by settings)



Modified: cpsskins/branches/paris-sprint-2006/setup/archives.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/archives.py       (original)
+++ cpsskins/branches/paris-sprint-2006/setup/archives.py       Sun May 21 
22:28:47 2006
@@ -37,7 +37,8 @@
         """Return the archive's data."""
 
 class TarArchive:
-
+    """A TAR archive (gzipped).
+    """
     implements(IArchive)
 
     def __init__(self, mode='r', data=''):
@@ -47,7 +48,7 @@
 
     def __setitem__(self, k, v):
         if self.mode == 'r':
-            raise TypeError("This tar archive is read-only.")
+            raise IOError("This tar archive is read-only.")
         stream = StringIO(v)
         info = TarInfo(k)
         info.size = len(v)
@@ -56,13 +57,32 @@
 
     def __getitem__(self, k):
         if self.mode == 'w':
-            raise TypeError("This tar archive is write-only.")
+            raise IOError("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.")
+            raise IOError("This tar archive is read-only.")
         self.archive.close()
         return self.stream.getvalue()
 
+class FileSystemArchive(object):
+    """An archive that reads data from the file-system.
+    """
+    implements(IArchive)
+
+    def __init__(self):
+        pass
+
+    def __setitem__(self, k, v):
+        raise IOError("File-system archives are read-only.")
+
+    def __getitem__(self, k):
+        file = open(k)
+        data = file.read()
+        file.close()
+        return data
+
+    def __call__(self):
+        pass

Modified: cpsskins/branches/paris-sprint-2006/setup/io/utils.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/io/utils.py       (original)
+++ cpsskins/branches/paris-sprint-2006/setup/io/utils.py       Sun May 21 
22:28:47 2006
@@ -220,10 +220,10 @@
     archive[u'settings.xml'] = document.toprettyxml(indent=u'  ',
                                                     encoding=u'utf-8')
 
-def importSettings(archive=None, context=None):
+def importSettings(archive=None, context=None, filepath=u'settings.xml'):
     """Import settings from the archive
     """
-    document = parseString(archive[u'settings.xml'])
+    document = parseString(archive[filepath])
     root = document.documentElement
 
     uri_mapping = {}

Modified: cpsskins/branches/paris-sprint-2006/setup/registration.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/registration.py   (original)
+++ cpsskins/branches/paris-sprint-2006/setup/registration.py   Sun May 21 
22:28:47 2006
@@ -28,7 +28,7 @@
 from zope.component import getUtility, createObject, getMultiAdapter
 from zope.component import getGlobalSiteManager
 
-from cpsskins.setup.archives import TarArchive
+from cpsskins.setup.archives import TarArchive, FileSystemArchive
 from cpsskins.setup.interfaces import IResourceManager, IResource
 from cpsskins.setup.io.interfaces import IDOMAdapter
 from cpsskins.setup.io.utils import importSite, importSettings
@@ -80,12 +80,10 @@
 def loadSettings():
     """Load all registered settings.
     """
+    archive = FileSystemArchive()
     for setting_file in settings_files:
         filepath = setting_file['filepath']
-        file = open(filepath)
-        archive = {'settings.xml': file.read()}
-        file.close()
-        importSettings(archive, context=None)
+        importSettings(archive, context=None, filepath=filepath)
         setting_file['refresh_date'] = time.time()
         logger.debug("loaded settings from %s", filepath)
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to