Author: jmorliaguet
Date: Mon May 15 22:20:06 2006
New Revision: 3142

Modified:
   cpsskins/branches/paris-sprint-2006/configuration/setup/metaconfigure.py
   cpsskins/branches/paris-sprint-2006/configuration/setup/metadirectives.py
   cpsskins/branches/paris-sprint-2006/setup/registration.py

Log:

- implemented the registration of settings from the filesystem



Modified: 
cpsskins/branches/paris-sprint-2006/configuration/setup/metaconfigure.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/configuration/setup/metaconfigure.py    
(original)
+++ cpsskins/branches/paris-sprint-2006/configuration/setup/metaconfigure.py    
Mon May 15 22:20:06 2006
@@ -19,11 +19,15 @@
 
 from zope.configuration.exceptions import ConfigurationError
 
-from cpsskins.setup.registration import registerSite
+from cpsskins.setup.registration import registerSite, registerSettings
 
-def setup(_context, name=u'', path=u''):
+def setup(_context, name=u'', site=u'', settings=u''):
 
-    if not path:
-        raise ConfigurationError("Must specify a site path.")
+    if not site and not settings:
+        raise ConfigurationError("Must specify a site or settings.")
 
-    registerSite(path)
+    if site:
+        registerSite(site)
+
+    if settings:
+        registerSettings(settings)

Modified: 
cpsskins/branches/paris-sprint-2006/configuration/setup/metadirectives.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/configuration/setup/metadirectives.py   
(original)
+++ cpsskins/branches/paris-sprint-2006/configuration/setup/metadirectives.py   
Mon May 15 22:20:06 2006
@@ -33,11 +33,17 @@
         default=u'',
         )
 
-    path = Path(
+    site = Path(
         title=_(u"Site"),
         description=_(u"The path of the site to load."),
         required=False,
         default=u'',
         )
 
+    settings = Path(
+        title=_(u"Site"),
+        description=_(u"The path of the site to load."),
+        required=False,
+        default=u'',
+        )
 

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   Mon May 15 
22:20:06 2006
@@ -28,9 +28,10 @@
 from zope.component import getUtility, createObject, getMultiAdapter
 from zope.component import getGlobalSiteManager
 
+from cpsskins.setup.archives import TarArchive
 from cpsskins.setup.interfaces import IResourceManager, IResource
 from cpsskins.setup.io.interfaces import IDOMAdapter
-from cpsskins.setup.io.utils import importSite
+from cpsskins.setup.io.utils import importSite, importSettings
 from cpsskins.thememanager import ThemeManagementFolder, IThemeManagementFolder
 
 logger = logging.getLogger("cpsskins")
@@ -40,11 +41,11 @@
 
 ### Registration  #####################################################
 
-def registerSite(filename):
-    site_files.append(filename)
+def registerSite(filepath):
+    site_files.append({'filepath': filepath, 'refresh_date': None})
 
-def registerSettings(filename):
-    settings_files.append(filename)
+def registerSettings(filepath):
+    settings_files.append({'filepath': filepath, 'refresh_date': None})
 
 ### Loading sites, settings  ##########################################
 
@@ -64,11 +65,12 @@
 def loadSites():
     """Load all registered sites.
     """
-    for filename in site_files:
-        file = open(filename)
+    for site_file in site_files:
+        filepath = site_file['filepath']
+        file = open(filepath)
         importSite(file)
         file.close()
-        logger.debug("loaded site from %s", filename)
+        logger.debug("loaded site from %s", filepath)
 
 ### Settings  #########################################################
 
@@ -78,22 +80,14 @@
 def loadSettings():
     """Load all registered settings.
     """
-    resources = getUtility(IResourceManager)
-
-    for filename in settings_files:
-        dom = parse(filename)
-        for setting_def in dom.getElementsByTagName('setting'):
-            name = setting_def.getAttribute('name')
-            title = setting_def.getAttribute('title')
-            resource = _loadResourceFromXML(setting_def, name, title)
-            if resource is None:
-                continue
-            resources.register(name, title=title,
-                               resource=resource, filename=filename)
-
-            file['refresh_date'] = time.time()
-
-        logger.debug("loaded settings from %s", filename)
+    for setting_file in settings_files:
+        filepath = setting_file['filepath']
+        file = open(filepath)
+        archive = TarArchive(mode='r', data=file.read())
+        file.close()
+        importSettings(archive, context=None)
+        setting_file['refresh_date'] = time.time()
+        logger.debug("loaded settings from %s", filepath)
 
 # To refactor: see cpsskins.setup.io.utils
 
@@ -128,13 +122,13 @@
 def refreshSettings():
     """Refresh all settings that have been modified on the filesystem.
     """
-    for file in settings_files:
-        refresh_date = file.get('refresh_date', 0)
-        filename = file['filename']
-        if refresh_date > os.path.getmtime(filename):
+    for setting_file in settings_files:
+        refresh_date = setting_file.get('refresh_date', 0)
+        filepath = setting_file['filepath']
+        if refresh_date > os.path.getmtime(filepath):
             continue
-        _reload(filename=filename)
-        file['refresh_date'] = time.time()
+        _reload(filepath=filepath)
+        setting_file['refresh_date'] = time.time()
 
 def reloadSetting(uri=u''):
     """Reload a setting by name.
@@ -146,15 +140,15 @@
     if not filename:
         raise TypeError("The setting is not a file-system setting.")
 
-    _reload(uri=uri, filename=filename)
+    _reload(uri=uri, filepath=filepath)
 
-def _reload(uri=u'', filename=u''):
+def _reload(uri=u'', filepath=u''):
     """Reload the settings in a file
     """
     try:
-        dom = parse(filename)
+        dom = parse(filepath)
     except ExpatError:
-        logger.warning("could not parse %s - not reloading", filename)
+        logger.warning("could not parse %s - not reloading", filepath)
         return
 
     for setting_def in dom.getElementsByTagName('setting'):
@@ -165,8 +159,8 @@
         if uri != setting_uri:
             continue
 
-        _loadResourceFromXML(setting_def, name, title, filename)
+        _loadResourceFromXML(setting_def, name, title, filepath)
 
     if not uri:
-        logger.debug("reloaded all settings in %s", filename)
+        logger.debug("reloaded all settings in %s", filepath)
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to