Author: jmorliaguet
Date: Sun Apr 30 18:54:14 2006
New Revision: 2998

Modified:
   cpsskins/branches/paris-sprint-2006/ftests/test_appsetup.py
   cpsskins/branches/paris-sprint-2006/relations/configure.zcml
   cpsskins/branches/paris-sprint-2006/relations/relations.py
   cpsskins/branches/paris-sprint-2006/setup/README.txt
   cpsskins/branches/paris-sprint-2006/setup/adapters.py
   cpsskins/branches/paris-sprint-2006/setup/configure.zcml
   cpsskins/branches/paris-sprint-2006/setup/manager.py
   cpsskins/branches/paris-sprint-2006/setup/registration.py
   cpsskins/branches/paris-sprint-2006/setup/setting.py
   cpsskins/branches/paris-sprint-2006/setup/test/dummy.py
   cpsskins/branches/paris-sprint-2006/setup/test/resource4.xml
   cpsskins/branches/paris-sprint-2006/standard/io/setting.py
   cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py
Log:

- API update to avoid name conflicts in setting names (we use URIs instead)



Modified: cpsskins/branches/paris-sprint-2006/ftests/test_appsetup.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/ftests/test_appsetup.py (original)
+++ cpsskins/branches/paris-sprint-2006/ftests/test_appsetup.py Sun Apr 30 
18:54:14 2006
@@ -29,10 +29,11 @@
 
 from cpsskins import elements
 from cpsskins.elements.interfaces import IElement, IIdentifiable, IType
+from cpsskins.elements.interfaces import ITypeable
 from cpsskins.setup.interfaces import IResourceType
 from cpsskins.setup.interfaces import IDOMAdapter
 from cpsskins.setup.test.dummy import IDummyResource, DummyDOMAdapter
-from cpsskins.setup.test.dummy import DummyFactory
+from cpsskins.setup.test.dummy import DummyFactory, Identifiable, Typeable
 
 import cpsskins.elements.interfaces
 
@@ -41,8 +42,8 @@
     # export adapters
     gsm.registerAdapter(DummyDOMAdapter, (IDummyResource, Interface),
                         IDOMAdapter)
-    gsm.registerAdapter(elements.element.Identifiable, (IDummyResource,),
-                        IIdentifiable)
+    gsm.registerAdapter(Identifiable, (IDummyResource,), IIdentifiable)
+    gsm.registerAdapter(Typeable, (IDummyResource,), ITypeable)
 
     # register the setting
     gsm.registerUtility(DummyFactory, IFactory, u'dummy')

Modified: cpsskins/branches/paris-sprint-2006/relations/configure.zcml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/relations/configure.zcml        
(original)
+++ cpsskins/branches/paris-sprint-2006/relations/configure.zcml        Sun Apr 
30 18:54:14 2006
@@ -80,4 +80,12 @@
       factory="cpsskins.relations.tool.RelationTool"
   />
 
+
+  <!-- Factory -->
+  <utility
+      factory="cpsskins.relations.relations.RelationFactory"
+      provides="zope.component.interfaces.IFactory"
+      name="relation"
+  />
+
 </configure>

Modified: cpsskins/branches/paris-sprint-2006/relations/relations.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/relations/relations.py  (original)
+++ cpsskins/branches/paris-sprint-2006/relations/relations.py  Sun Apr 30 
18:54:14 2006
@@ -18,15 +18,24 @@
 __docformat__ = "reStructuredText"
 
 from persistent import Persistent
+
+from zope.component.factory import Factory
 from zope.interface import implements
 from zope.security.proxy import removeSecurityProxy as trusted
 
-from cpsskins.relations.interfaces import (
-    IMonadicRelation, IDyadicRelation, ITriadicRelation, IRelatable)
+from cpsskins.relations.interfaces import IRelation
+from cpsskins.relations.interfaces import IMonadicRelation, IDyadicRelation
+from cpsskins.relations.interfaces import ITriadicRelation, IRelatable
 
 class Relation(Persistent):
     """A relation
     """
+    implements(IRelation)
+
+    _predicate = None
+
+    _tuple = ()
+
     def __str__(self):
         return str(self())
 
@@ -133,8 +142,7 @@
     def __repr__(self):
         predicate = str(self()).replace('_', '%s')
         return "<Dyadic relation: '%s'>" % (
-            predicate % (repr(self.first), repr(self.second))
-            )
+            predicate % (repr(self.first), repr(self.second)))
 
 
 class TriadicRelation(Relation):
@@ -209,3 +217,6 @@
     def __repr__(self):
         return self.name
 
+RelationFactory = Factory(Relation, "Relation Factory",
+                       "A Factory that creates relations")
+

Modified: cpsskins/branches/paris-sprint-2006/setup/README.txt
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/README.txt        (original)
+++ cpsskins/branches/paris-sprint-2006/setup/README.txt        Sun Apr 30 
18:54:14 2006
@@ -19,12 +19,12 @@
 - _local resources_ are stored in the site itself (e.g. ZODB). Local resources
   are registered as _local settings_ (using local utilities).
 
-Resources have a unique _name_ which is used to identify them.
+Resources and settings have a URI which is used to identify them.
 
-Global resources can be customized into local resources in order to apply local
-modifications to them.
+Global settings can be customized, for applying local modification in a given
+context.
 
-Customized resources can also be decustomized, i.e the customization be 
removed.
+Customized settings can be decustomized, i.e the customization be removed.
 
 
 Test setup:
@@ -35,6 +35,7 @@
     >>> from zope.component import getUtility
     >>> from zope.interface import implements, Interface
 
+    >>> from cpsskins.elements.interfaces import IIdentifiable
     >>> from cpsskins.setup.interfaces import IResourceManager
     >>> from cpsskins.setup.settings import ISettings
     >>> from cpsskins.setup.test.dummy import IDummyResource, DummyResource
@@ -62,217 +63,214 @@
     >>> root[u'resource2'] = resource2
     >>> root[u'resource3'] = resource3
 
+Resources are identifiable (see the 'Uniform Resource Identifier' section):
+
+    >>> IIdentifiable(resource1).getURI()
+    u'cpsskins://dummy:resource1'
+
 Resources are available via the resource manager:
 
     >>> resources = getUtility(IResourceManager)
 
-But none of the above resources are available yet in the application:
+but none of the above resources have been registered yet in the application:
 
-    >>> resources.lookup(u'resource1') is None
+    >>> resources.lookup(u'cpsskins://dummy:resource1') is None
     True
 
-    >>> resources.lookup(u'resource2') is None
+    >>> resources.lookup(u'cpsskins://dummy:resource2') is None
     True
 
-Registering resources
----------------------
+Registering resources as settings
+---------------------------------
 
-Resources need to be registered, so we register them:
+Registered resources become *application settings*. Instead of accessing the
+resource directly (e.g. 'cpsskins://dummy:resource1') we access it by
+referring to the corresponding setting (e.g. 'cpsskins://[EMAIL PROTECTED]').
 
-    >>> resources.register(name=u'resource1', title=u'Resource 1',
+    >>> resources.register(name=u'setting1', title=u'Setting 1',
     ...                    resource=resource1)
 
-and we look up the registered resource:
+we can look up the setting:
+
+    >>> resources.lookup(u'cpsskins://[EMAIL PROTECTED]')
+    <Setting: cpsskins://[EMAIL PROTECTED]>
 
-    >>> resources.lookup(u'resource1')
+to get the resource itself, we call:
+
+    >>> resources.resolve(u'cpsskins://[EMAIL PROTECTED]')
     <Dummy resource: resource1>
 
-    >>> resources.lookup('resource2')
 
-We can get the complete list of registered resources:
+We can get the complete list of registered settings:
 
     >>> resources.list(type=IDummyResource)
-    [<Dummy resource: resource1>]
+    [<Setting: cpsskins://[EMAIL PROTECTED]>]
 
 Now we register the second resource:
 
-    >>> resources.register(name=u'resource2', title=u'Resource 2',
+    >>> resources.register(name=u'setting2', title=u'Setting 2',
     ...                    resource=resource2)
 
-and look it up in the registry, either by specifying its name:
-
-    >>> resources.lookup(u'resource2')
-    <Dummy resource: resource2>
-
-or by also specifying an interface that it implements to avoid conflict names:
+and look it up in the registry:
 
-    >>> resources.lookup(u'resource2', IDummyResource)
-    <Dummy resource: resource2>
-
-We can also list all registered resources by type:
-
-    >>> resources.list(IDummyResource)
-    [<Dummy resource: resource1>, <Dummy resource: resource2>]
+    >>> resources.lookup(u'cpsskins://[EMAIL PROTECTED]')
+    <Setting: cpsskins://[EMAIL PROTECTED]>
 
 
 Trying to unregister a global resource raises an error:
 
-    >>> resources.isGlobal(u'resource1')
+    >>> resources.isGlobal(u'cpsskins://[EMAIL PROTECTED]')
     True
 
-    >>> resources.unregister(name=u'resource1', context=root)
+    >>> resources.unregister(uri=u'cpsskins://[EMAIL PROTECTED]', context=root)
     Traceback (most recent call last):
     ...
-    ValueError: No such local setting: 'resource1'
+    ValueError: No such local setting: 'cpsskins://[EMAIL PROTECTED]'
 
 so we register a local resource, we do this by passing a context to register():
 
-    >>> resources.register(name=u'resource3', title=u'Resource 3',
+    >>> resources.register(name=u'setting3', title=u'Setting 3',
     ...                    resource=resource3, context=root)
 
 We now have a local resource in the context of the root folder:
 
-    >>> resources.isLocal(name=u'resource3', context=root)
+    >>> resources.isLocal(uri=u'cpsskins://[EMAIL PROTECTED]', context=root)
     True
 
-but for the application and in the context of the root folder there is no
+but for the application in the context of the root folder there is no
 difference between local and global resources:
 
     >>> pprint(resources.list(type=IDummyResource, context=root))
-    [<Dummy resource: resource1>,
-     <Dummy resource: resource3>,
-     <Dummy resource: resource2>]
+    [<Setting: cpsskins://[EMAIL PROTECTED]>,
+     <Setting: cpsskins://[EMAIL PROTECTED]>,
+     <Setting: cpsskins://[EMAIL PROTECTED]>]
 
 
-Unregistering resources
------------------------
+Unregistering settings
+----------------------
 
-when unregistering a resource, a context must be given:
+when unregistering a setting, a context must be given:
 
-    >>> resources.unregister(name='resource3')
+    >>> resources.unregister(uri=u'cpsskins://[EMAIL PROTECTED]')
     Traceback (most recent call last):
     ...
     ValueError: Must specify a context.
 
-and a resource name must be specified:
+and a setting URI must be specified:
 
     >>> resources.unregister(context=root)
     Traceback (most recent call last):
     ...
-    KeyError: 'Must specify a resource name.'
+    KeyError: 'Must specify a setting URI.'
 
 so we pass both:
 
-    >>> resources.unregister(name='resource3', context=root)
+    >>> resources.unregister(uri='cpsskins://[EMAIL PROTECTED]', context=root)
 
-and the resource is no longer available:
+The setting that has been unregistered is no longer available:
 
-    >>> resources.lookup(u'resource3') is None
+    >>> resources.lookup(u'cpsskins://[EMAIL PROTECTED]') is None
     True
 
-    >>> res = resources.list(type=IDummyResource, context=root)
-    >>> resource1 in res
-    True
-
-    >>> resource2 in res
-    True
+    >>> pprint(resources.list(type=IDummyResource, context=root))
+    [<Setting: cpsskins://[EMAIL PROTECTED]>,
+     <Setting: cpsskins://[EMAIL PROTECTED]>]
 
 
-Customizing resources
----------------------
+Customizing settings
+--------------------
 
 Global resources cannot be modified but they can be customized:
 
-The context in which the resource is customized must be given:
+The context in which the resource is to be customized must be given:
 
-    >>> resources.customize(u'resource1')
+    >>> resources.customize(u'cpsskins://[EMAIL PROTECTED]')
     Traceback (most recent call last):
     ...
     ValueError: Must specify a context.
 
 so we pass the context:
 
-    >>> resources.customize(u'resource1', context=root)
+    >>> resources.customize(u'cpsskins://[EMAIL PROTECTED]', context=root)
 
 'resource1' is now registered as a local resource:
 
-    >>> resources.isLocal(u'resource1', context=root)
+    >>> resources.isLocal(u'cpsskins://[EMAIL PROTECTED]', context=root)
     True
 
 the customized resource is still available as a global resource:
 
-    >>> resources.isGlobal(u'resource1')
+    >>> resources.isGlobal(u'cpsskins://[EMAIL PROTECTED]')
     True
 
-but when we look up 'resource1' in the context of the root folder, we get the
-customized resource:
+but when we look up 'cpsskins://[EMAIL PROTECTED]' in the context of the root
+folder, we get the customized resource:
 
-    >>> resources.isCustom(u'resource1', context=root)
+    >>> resources.isCustom(u'cpsskins://[EMAIL PROTECTED]', context=root)
     True
 
 Let us modify the customized resource:
 
-    >>> r1 = resources.lookup(u'resource1', context=root)
-    >>> r1.setTitle('Customized resource 1')
+    >>> custom = resources.resolve(u'cpsskins://[EMAIL PROTECTED]', 
context=root)
+    >>> custom.setTitle(u'Customized resource1')
 
-    >>> r1
-    <Dummy resource: Customized resource 1>
+    >>> custom.title
+    u'Customized resource1'
 
 the global resource is unchanged:
 
-    >>> resources.lookup(u'resource1')
-    <Dummy resource: resource1>
+    >>> resources.resolve(u'cpsskins://[EMAIL PROTECTED]').title
+    u'resource1'
 
 
 Removing customizations
 -----------------------
 
-'resource1' is now customized, to remove the customization we must specify
-the context in which the resource was customized:
+'setting1' is now customized, to remove the customization we must specify
+the context in which the setting was customized:
 
-    >>> resources.decustomize(u'resource1')
+    >>> resources.decustomize(u'cpsskins://[EMAIL PROTECTED]')
     Traceback (most recent call last):
     ...
     ValueError: Must specify a context.
 
-    >>> resources.decustomize(u'resource1', context=root)
+    >>> resources.decustomize(u'cpsskins://[EMAIL PROTECTED]', context=root)
 
-now in the context of the root folder, 'resource1' is the global resource 
-again.
+now in the context of the root folder, 'setting1' is the global setting:
 
-    >>> resources.lookup(u'resource1', context=root)
-    <Dummy resource: resource1>
+    >>> resources.resolve(u'cpsskins://[EMAIL PROTECTED]', context=root).title
+    u'resource1'
 
-    >>> resources.lookup(u'resource1')
-    <Dummy resource: resource1>
+    >>> resources.resolve(u'cpsskins://[EMAIL PROTECTED]').title
+    u'resource1'
 
 
-Registering resources from the filesystem
------------------------------------------
+Registering settings from the filesystem
+----------------------------------------
 
-Global resources can also be stored on the filesystem, they can be defined in
+Global settings can also be stored on the filesystem, they can be defined in
 XML and registered in python:
 
     >>> from cpsskins.setup.registration import register, loadSettings
 
-    >>> register('cpsskins.setup.test', 'resource4.xml')
+    >>> register(u'cpsskins.setup.test', u'resource4.xml')
     >>> loadSettings()
 
-    >>> resources.lookup(u'test.setting4')
+    >>> resources.resolve(u'cpsskins://[EMAIL PROTECTED]')
     <Dummy resource: Dummy resource 4>
 
 
-Reloading resources
--------------------
+Reloading settings
+------------------
 
-File-system resources can be reloaded:
+File-system settingscan be reloaded:
 
     >>> from cpsskins.setup.registration import reloadSetting
-    >>> reloadSetting(u'test.setting4')
+    >>> reloadSetting(u'cpsskins://[EMAIL PROTECTED]')
 
-Resources created through-the-web cannot be reloaded:
+Settings created through-the-web cannot be reloaded:
 
-    >>> reloadSetting(u'resource1')
+    >>> reloadSetting(u'cpsskins://[EMAIL PROTECTED]')
     Traceback (most recent call last):
     ...
     TypeError: The setting is not a file-system setting.
@@ -443,8 +441,9 @@
     >>> getTypeName(portlet_type)
     u'canvas-portlet-standard.actions'
 
-URI
----
+
+Uniform Resource Identifier
+---------------------------
 
 To identify resource *instances* a URI (Uniform Resource Identifier) is used.
 A URI consists of a combination of a type signature's name and a unique
@@ -509,6 +508,15 @@
     ...     return document.toprettyxml(indent=u'  ', encoding=u'utf-8')
 
 
+Export of settings
+------------------
+
+    >>> style = Style()
+    >>> resources.register(name=u'style1', title=u'Style 1', resource=style)
+
+    >>> setting = resources.lookup(u'style1')
+    >>> print toXML(setting, u'settings')
+
 Export of styles
 ----------------
 

Modified: cpsskins/branches/paris-sprint-2006/setup/adapters.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/adapters.py       (original)
+++ cpsskins/branches/paris-sprint-2006/setup/adapters.py       Sun Apr 30 
18:54:14 2006
@@ -20,6 +20,7 @@
 from zope.component import adapts
 from zope.interface import implements
 
+from cpsskins.elements.interfaces import IIdentifiable, ITypeable
 from cpsskins.relations.interfaces import IRelatable
 from cpsskins.setup.interfaces import IResource, ISetting
 
@@ -47,3 +48,32 @@
     def __str__(self):
         return self.context.name
 
+class Identifiable(object):
+    """This adapter makes elements uniquely identifiable.
+    """
+    adapts(ISetting)
+    implements(IIdentifiable)
+
+    def __init__(self, context):
+        self.context = context
+
+    def getURI(self):
+        context = self.context
+
+        resource = IResource(context).getResource()
+        type_name = ITypeable(resource).getTypeName()
+
+        return u'cpsskins://[EMAIL PROTECTED]' % (type_name, context.name)
+
+class Typeable(object):
+    """This adapter makes elements uniquely identifiable.
+    """
+    adapts(ISetting)
+    implements(ITypeable)
+
+    def __init__(self, context):
+        self.context = context
+
+    def getTypeName(self):
+        return u'dummy'
+

Modified: cpsskins/branches/paris-sprint-2006/setup/configure.zcml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/configure.zcml    (original)
+++ cpsskins/branches/paris-sprint-2006/setup/configure.zcml    Sun Apr 30 
18:54:14 2006
@@ -21,6 +21,11 @@
       factory="cpsskins.setup.adapters.Resource"
   />
 
+  <!-- this adapter makes settings identifiable -->
+  <adapter
+      factory="cpsskins.setup.adapters.Identifiable"
+  />
+
   <!-- register global application settings -->
   <subscriber
       handler=".registration.loadSettingsEvent"

Modified: cpsskins/branches/paris-sprint-2006/setup/manager.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/manager.py        (original)
+++ cpsskins/branches/paris-sprint-2006/setup/manager.py        Sun Apr 30 
18:54:14 2006
@@ -24,10 +24,12 @@
 from zope.component import getGlobalSiteManager
 from zope.component import providedBy
 
+from cpsskins.elements.interfaces import IIdentifiable, IType
 from cpsskins.setup.interfaces import IResourceManager, IResource
 from cpsskins.setup.interfaces import ISetting, IGlobalSetting, ILocalSetting
 from cpsskins.setup.setting import GlobalSetting, LocalSetting
 from cpsskins.setup.utils import getType, getTypeName, getContentType
+from cpsskins.relations.interfaces import IRelatable
 from cpsskins.utils import getThemeManager
 
 class ResourceManager(object):
@@ -41,7 +43,7 @@
         self.gsm = getGlobalSiteManager()
 
 
-    ### Registration of resources  #####################################
+    ### Registration of settings  #####################################
 
     def register(self, name=u'', title=u'', resource=None, filename=None,
                        custom=False, context=None):
@@ -51,7 +53,8 @@
         if context is None:
             setting = GlobalSetting(name=name, title=title,
                                     resource=resource, filename=filename)
-            self.gsm.registerUtility(setting, ISetting, name)
+            uri = IIdentifiable(setting).getURI()
+            self.gsm.registerUtility(setting, ISetting, uri)
 
         # register as a local utility
         else:
@@ -61,82 +64,74 @@
             setting = LocalSetting(name=name, title=title,
                                    resource=resource, custom=custom)
             settings[name] = setting
-            settings.registerUtility(setting, ISetting, name)
+            uri = IIdentifiable(setting).getURI()
+            settings.registerUtility(setting, ISetting, uri)
 
-    def unregister(self, name=u'', context=None):
+    def unregister(self, uri=u'', context=None):
         """Unregister the setting.
         """
-        if not name:
-            raise KeyError("Must specify a resource name.")
+        if not uri:
+            raise KeyError("Must specify a setting URI.")
 
         if context is None:
             raise ValueError("Must specify a context.")
 
         settings = getThemeManager(context).getSettings()
-        setting = settings.queryUtility(ISetting, name)
+        setting = settings.queryUtility(ISetting, uri)
         if setting is None or not setting.isLocal():
-            raise ValueError("No such local setting: '%s'" % name)
+            raise ValueError("No such local setting: '%s'" % uri)
 
-        settings.unregisterUtility(provided=ISetting, name=name)
+        settings.unregisterUtility(provided=ISetting, name=uri)
 
-
-    ### Finding resources  ############################################
-
-    def lookup(self, name=u'', type=None, context=None, default=None):
-        if not name:
-            raise KeyError("Must specify a resource name.")
+    def lookup(self, uri=u'', context=None, default=None):
+        """Look up a setting by uri.
+        """
+        if not uri:
+            raise KeyError("Must specify a setting URI.")
 
         setting = None
 
         if context is not None:
             settings = getThemeManager(context).getSettings()
-            setting = settings.queryUtility(ISetting, name)
+            setting = settings.queryUtility(ISetting, uri)
 
         if context is None or setting is None:
-            setting = self.gsm.queryUtility(ISetting, name)
+            setting = self.gsm.queryUtility(ISetting, uri)
 
         if setting is None:
             return default
 
-        resource_getter = IResource(setting, None)
-        if resource_getter is not None:
-            resource = resource_getter.getResource()
-            if type and not type in list(providedBy(resource)):
-                return default
-            return resource
-        return default
+        return setting
 
     def list(self, type=None, context=None):
-        items = {}
         entries = list(self.gsm.getUtilitiesFor(ISetting))
         if context is not None:
             settings = getThemeManager(context).getSettings()
             entries.extend(list(settings.getUtilitiesFor(ISetting)))
 
-        for name, setting in entries:
-            resource_getter = IResource(setting, None)
-            if resource_getter is None:
+        settings = []
+        for uri, setting in entries:
+            resource = IResource(setting).getResource()
+            if type and not type.providedBy(resource):
                 continue
-            resource = resource_getter.getResource()
-            if type and not type in list(providedBy(resource)):
-                continue
-            items[name] = resource
-        return items.values()
+            settings.append(setting)
+        return settings
+
+    ### Resolving resources  ###########################################
 
     def resolve(self, uri, context=None):
         if not uri.startswith('cpsskins://'):
-            raise ValueError("Unkown URI scheme in '%s'" % uri)
+            raise ValueError("Unknown URI scheme in '%s'" % uri)
 
         resource = None
         location = uri[11:]
 
         if '@' in location:
-            type_name, resource_id = uri.split('@')
-            type = getContentType(type_name)
-            resource = self.lookup(name=resource_id, type=type, 
context=context)
+            setting = self.lookup(uri, context)
+            resource = IResource(setting).getResource()
 
         elif ':' in location:
-            type_name, resource_id = uri.split(':')
+            type_name, resource_id = location.split(':')
             type = getContentType(type_name)
             # TODO
 
@@ -147,53 +142,54 @@
 
     ### Customization  ################################################
 
-    def isGlobal(self, name=u''):
-        setting = self.gsm.queryUtility(ISetting, name)
+    def isGlobal(self, uri=u''):
+        setting = self.gsm.queryUtility(ISetting, uri)
         if setting is None:
-            raise ValueError("No such setting: '%s'." % name)
+            raise ValueError("No such setting: '%s'." % uri)
         return IGlobalSetting.providedBy(setting)
 
-    def isLocal(self, name=u'', context=None):
+    def isLocal(self, uri=u'', context=None):
         settings = getThemeManager(context).getSettings()
-        setting = settings.queryUtility(ISetting, name)
+        setting = settings.queryUtility(ISetting, uri)
 
         if setting is None:
-            raise ValueError("No such setting: '%s'." % name)
+            raise ValueError("No such setting: '%s'." % uri)
         return ILocalSetting.providedBy(setting)
 
-    def isCustom(self, name=u'', context=None):
+    def isCustom(self, uri=u'', context=None):
         settings = getThemeManager(context).getSettings()
-        setting = settings.queryUtility(ISetting, name)
+        setting = settings.queryUtility(ISetting, uri)
         if setting is None:
-            raise ValueError("No such setting: '%s'." % name)
+            raise ValueError("No such setting: '%s'." % uri)
         return ILocalSetting.providedBy(setting) and setting.custom
 
-    def customize(self, name=u'', context=None):
+    def customize(self, uri=u'', context=None):
         if context is None:
             raise ValueError("Must specify a context.")
 
-        setting = self.gsm.queryUtility(ISetting, name)
+        setting = self.gsm.queryUtility(ISetting, uri)
         if setting is None:
-            raise ValueError("No such setting: '%s'." % name)
+            raise ValueError("No such setting: '%s'." % uri)
 
         resource = None
         resource_getter = IResource(setting)
         if resource_getter is not None:
             resource = deepcopy(resource_getter.getResource())
 
-        self.register(name=name, title=setting.title, resource=resource,
+        setting_name = unicode(IRelatable(setting))
+        self.register(name=setting_name, title=setting.title, 
resource=resource,
                       context=context, custom=True)
 
-    def decustomize(self, name=u'', context=None):
-        if not name:
-            raise KeyError("Must specify a resource name.")
+    def decustomize(self, uri=u'', context=None):
+        if not uri:
+            raise KeyError("Must specify a URI.")
 
         if context is None:
             raise ValueError("Must specify a context.")
 
-        if self.gsm.queryUtility(ISetting, name) is None:
+        if self.gsm.queryUtility(ISetting, uri) is None:
             raise ValueError("No such customized setting.")
 
-        self.unregister(name=name, context=context)
+        self.unregister(uri, context)
 
 

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 Apr 30 
18:54:14 2006
@@ -28,6 +28,7 @@
 from zope.component import getUtility, queryUtility, createObject
 from zope.component import getGlobalSiteManager, getMultiAdapter
 
+from cpsskins.relations.interfaces import IRelatable
 from cpsskins.setup.interfaces import IResourceManager, IDOMAdapter
 from cpsskins.setup.interfaces import ISetting, IResource
 
@@ -68,27 +69,28 @@
 
         logger.debug("loaded settings in %s", filename)
 
-def _loadResourceFromXML(setting_def=None, name=u'', title=u'', filename=u''):
+def _loadResourceFromXML(setting_def=None, uri=u'', title=u'', filename=u''):
     resources = getUtility(IResourceManager)
 
     resource_defs = setting_def.getElementsByTagName('*')
     if not resource_defs:
-        logger.debug("no resource found for %s" % name)
+        logger.debug("no resource found for %s" % uri)
         return None
 
     resource_def = resource_defs[0]
 
-    setting = queryUtility(ISetting, name, None)
+    setting = queryUtility(ISetting, uri, None)
     if setting is None:
         # create the resource
         resource = createObject(resource_def.tagName)
-        resources.register(name=name, title=title,
+        setting_name = uri.split('@')[-1] # TODO: use API
+        resources.register(name=setting_name, title=title,
                            resource=resource, filename=filename)
-        logger.debug("new setting added: '%s'", name)
+        logger.debug("new setting added: '%s'", uri)
     else:
         resource = IResource(setting).getResource()
         setting.title = title
-        logger.debug("reloaded setting %s in %s", name, filename)
+        logger.debug("reloaded setting %s in %s", uri, filename)
 
     # load the data
     #getMultiAdapter(IDOMAdapter, (resource, resource_def)).load()
@@ -116,10 +118,10 @@
 # Reloading settings
 #######################################################################
 
-def reloadSetting(name=u''):
+def reloadSetting(uri=u''):
     """Reload a setting by name.
     """
-    setting = getGlobalSiteManager().queryUtility(ISetting, name)
+    setting = getGlobalSiteManager().queryUtility(ISetting, uri)
     filename = setting.filename
 
     if not filename:
@@ -127,7 +129,7 @@
 
     _reload(setting_name=name, filename=filename)
 
-def _reload(setting_name=u'', filename=u''):
+def _reload(uri=u'', filename=u''):
     """Reload the settings in a file
     """
     try:
@@ -137,12 +139,12 @@
         return
 
     for setting_def in dom.getElementsByTagName('setting'):
-        name = setting_def.getAttribute('name')
+        setting_uri = setting_def.getAttribute('uri')
         title = setting_def.getAttribute('title')
-        if setting_name and name != setting_name:
+        if setting_uri and uri != setting_uri:
             continue
 
-        _loadResourceFromXML(setting_def, name, title, filename)
+        _loadResourceFromXML(setting_def, uri, title, filename)
 
     if not name:
         logger.debug("reloaded all settings in %s", filename)

Modified: cpsskins/branches/paris-sprint-2006/setup/setting.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/setting.py        (original)
+++ cpsskins/branches/paris-sprint-2006/setup/setting.py        Sun Apr 30 
18:54:14 2006
@@ -21,6 +21,7 @@
 from zope.app.container.contained import Contained
 from zope.interface import implements
 
+from cpsskins.elements.interfaces import IIdentifiable
 from cpsskins.setup.interfaces import IGlobalSetting, ILocalSetting
 
 class Setting(object):
@@ -33,6 +34,9 @@
         self.resource.__parent__ = self
         self.resource.__name__ = name
 
+    def __repr__(self):
+        return u'<Setting: %s>' % IIdentifiable(self).getURI()
+
     def __call__(self):
         return self.resource
 

Modified: cpsskins/branches/paris-sprint-2006/setup/test/dummy.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/test/dummy.py     (original)
+++ cpsskins/branches/paris-sprint-2006/setup/test/dummy.py     Sun Apr 30 
18:54:14 2006
@@ -23,6 +23,7 @@
 from zope.component.factory import Factory
 from zope.interface import Interface, implements
 
+from cpsskins.elements.interfaces import IIdentifiable, ITypeable
 from cpsskins.setup.io import BaseDOMAdapter
 from cpsskins.setup.interfaces import IDOMAdapter
 
@@ -56,3 +57,23 @@
     def save(self):
         """ """
 
+class Identifiable:
+
+    implements(IIdentifiable)
+
+    def __init__(self, context):
+        self.context = context
+
+    def getURI(self):
+        identifier = self.context.title.replace(u' ', u'_')
+        return u'cpsskins://dummy:%s' % identifier
+
+class Typeable:
+
+    implements(ITypeable)
+
+    def __init__(self, context):
+        self.context = context
+
+    def getTypeName(self):
+        return u'dummy'

Modified: cpsskins/branches/paris-sprint-2006/setup/test/resource4.xml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/test/resource4.xml        
(original)
+++ cpsskins/branches/paris-sprint-2006/setup/test/resource4.xml        Sun Apr 
30 18:54:14 2006
@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="utf-8" ?>
-<setting name="test.setting4" title="Test setting 4">
+<setting name="cpsskins://[EMAIL PROTECTED]" title="Test setting 4">
   <dummy name="dummy.resource" title="Dummy resource 4" />
 </setting>

Modified: cpsskins/branches/paris-sprint-2006/standard/io/setting.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/io/setting.py  (original)
+++ cpsskins/branches/paris-sprint-2006/standard/io/setting.py  Sun Apr 30 
18:54:14 2006
@@ -36,7 +36,7 @@
 
         setting_el = document.createElement(u'setting')
         setting_el.setAttribute(u'title', context.title)
-        #element.setAttribute(u'uri', IIdentifiable(resource).getURI())
+        setting_el.setAttribute(u'uri', IIdentifiable(context).getURI())
         node.appendChild(setting_el)
 
         # export the resource

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 Sun Apr 
30 18:54:14 2006
@@ -42,7 +42,6 @@
         self.context = context
         self.request = request
 
-
     ### Settings  #####################################################
 
     def getSettingInfo(self):
@@ -166,15 +165,15 @@
         archive = TarArchive(mode='r', data=file.read())
         mgr = getThemeManager(self.context)
 
+        uri_mapping = {}
+
         # themes
         themes_data = archive[u'themes.xml']
+        self.importThemes(themes_data)
 
-        uri_mapping = {}
         # storages
         for storage_id in u'formats', u'displays', u'portlets':
             storage = mgr[storage_id]
-            storage.purge()
-
             data = archive[u'%s.xml' % storage_id]
             uri_mapping.update(self.importStorage(storage_id, data))
 
@@ -188,11 +187,15 @@
         for el in root.childNodes:
             if el.nodeType != Node.ELEMENT_NODE:
                 continue
+
+            relation = createObject(u'relation')
+            print relation
             importer = getMultiAdapter((relation, el), IDOMAdapter)
             importer.setDocument(document)
             importer.setURIMapping(uri_mapping)
-            importer.load(dom)
+            importer.load()
 
+        document.unlink()
 
     ### Snapshots  ####################################################
 
@@ -238,12 +241,10 @@
     def exportStorage(self, name=u''):
         """Export the storage as XML.
         """
-        context = self.context
-        request = self.request
         if not name:
             raise KeyError("Must specify a storage name.")
 
-        mgr = getThemeManager(context)
+        mgr = getThemeManager(self.context)
         storage = mgr[name]
 
         document = DOMImplementation().createDocument(None, name, None)
@@ -255,15 +256,18 @@
             exporter.writeAsAttributes((u'title', u'description'))
             exporter.save()
 
-        return document.toprettyxml(indent=u'  ', encoding=u'utf-8')
+        xml = document.toprettyxml(indent=u'  ', encoding=u'utf-8')
+        document.unlink()
+        return xml
 
     def importStorage(self, name=u'', xml=u''):
-        request = self.request
         if not name:
             raise KeyError("Must specify a storage name.")
 
         mgr = getThemeManager(self.context)
+
         storage = mgr[name]
+        storage.purge()
 
         document = parseString(xml)
         root = document.documentElement
@@ -273,14 +277,15 @@
         for el in root.childNodes:
             if el.nodeType != Node.ELEMENT_NODE:
                 continue
-            typename = el.tagName
-            obj = createObject(typename)
+            obj = createObject(el.tagName)
+
             importer = getMultiAdapter((obj, el), IDOMAdapter)
             importer.setDocument(document)
             importer.load()
 
             uri_mapping.update(importer.mapping)
 
+        document.unlink()
         return uri_mapping
 
 
@@ -289,17 +294,28 @@
     def exportThemes(self):
         """Export the themes
         """
-        context = self.context
-        request = self.request
-
         document = DOMImplementation().createDocument(None, u'themes', None)
         root = document.documentElement
 
-        for theme in getThemeManager(context).getThemes():
+        for theme in getThemeManager(self.context).getThemes():
             exporter = getMultiAdapter((theme, root), IDOMAdapter)
             exporter.setDocument(document)
             exporter.writeAsAttributes((u'title', u'description'))
             exporter.save()
 
-        return document.toprettyxml(indent=u'  ', encoding=u'utf-8')
+        xml = document.toprettyxml(indent=u'  ', encoding=u'utf-8')
+        document.unlink()
+        return xml
 
+    def importThemes(self, xml=u''):
+        """Import themes from XML
+        """
+        document = parseString(xml)
+        root = document.documentElement
+
+        uri_mapping = {}
+
+        # TODO
+
+        document.unlink()
+        return uri_mapping
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to