Author: jmorliaguet
Date: Sun Apr 30 20:04:18 2006
New Revision: 2999

Modified:
   cpsskins/branches/paris-sprint-2006/profiles/default/color.xml
   cpsskins/branches/paris-sprint-2006/profiles/default/perspectives.xml
   cpsskins/branches/paris-sprint-2006/setup/README.txt
   cpsskins/branches/paris-sprint-2006/setup/adapters.py
   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/resource4.xml
Log:

- we use URIs to register settings



Modified: cpsskins/branches/paris-sprint-2006/profiles/default/color.xml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/profiles/default/color.xml      
(original)
+++ cpsskins/branches/paris-sprint-2006/profiles/default/color.xml      Sun Apr 
30 20:04:18 2006
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="utf-8" ?>
 <settings>
-  <setting name="redcolor" title="Red color">
+  <setting uri="cpsskins://[EMAIL PROTECTED]" title="Red color">
     <color value="#ff0000" />
   </setting>
-  <setting name="greencolor" title="Green color">
+  <setting uri="cpsskins://[EMAIL PROTECTED]" title="Green color">
     <color value="#00ff00" />
   </setting>
 </settings>

Modified: cpsskins/branches/paris-sprint-2006/profiles/default/perspectives.xml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/profiles/default/perspectives.xml       
(original)
+++ cpsskins/branches/paris-sprint-2006/profiles/default/perspectives.xml       
Sun Apr 30 20:04:18 2006
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="utf-8" ?>
 <settings>
-  <setting name="perspective.global" title="Global perspective">
-    <perspective name="perspective.global" title="Global perspective" />
+  <setting uri="cpsskins://[EMAIL PROTECTED]" title="Global perspective">
+    <perspective uri="cpsskins://perspective:global" title="Global 
perspective" />
   </setting>
-  <setting name="perspective.global2" title="Global perspective 2">
-    <perspective name="perspective.global" title="Global perspective 2" />
+  <setting uri="cpsskins://[EMAIL PROTECTED]" title="Global perspective 2">
+    <perspective uri="cpsskins://perspective:global2" title="Global 
perspective 2" />
   </setting>
 </settings>

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 
20:04:18 2006
@@ -87,7 +87,7 @@
 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'setting1', title=u'Setting 1',
+    >>> resources.register(uri=u'cpsskins://[EMAIL PROTECTED]', 
title=u'Setting 1',
     ...                    resource=resource1)
 
 we can look up the setting:
@@ -108,7 +108,7 @@
 
 Now we register the second resource:
 
-    >>> resources.register(name=u'setting2', title=u'Setting 2',
+    >>> resources.register(uri=u'cpsskins://[EMAIL PROTECTED]', 
title=u'Setting 2',
     ...                    resource=resource2)
 
 and look it up in the registry:
@@ -129,7 +129,7 @@
 
 so we register a local resource, we do this by passing a context to register():
 
-    >>> resources.register(name=u'setting3', title=u'Setting 3',
+    >>> resources.register(uri=u'cpsskins://[EMAIL PROTECTED]', 
title=u'Setting 3',
     ...                    resource=resource3, context=root)
 
 We now have a local resource in the context of the root folder:
@@ -512,7 +512,8 @@
 ------------------
 
     >>> style = Style()
-    >>> resources.register(name=u'style1', title=u'Style 1', resource=style)
+    >>> resources.register(uri=u'cpsskins://[EMAIL PROTECTED]',
+    ...                    title=u'Style 1', resource=style)
 
     >>> setting = resources.lookup(u'style1')
     >>> print toXML(setting, u'settings')
@@ -711,7 +712,8 @@
     >>> print color
     #ff0000
 
-    >>> resources.register(name=u'red', title=u'Color red', resource=color)
+    >>> resources.register(uri=u'cpsskins://[EMAIL PROTECTED]',
+    ...                    title=u'Color red', resource=color)
 
     >>> ITypeable(color).getTypeName()
     u'field-color'

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 
20:04:18 2006
@@ -46,7 +46,7 @@
         self.context = context
 
     def __str__(self):
-        return self.context.name
+        return self.context.uri
 
 class Identifiable(object):
     """This adapter makes elements uniquely identifiable.
@@ -58,12 +58,7 @@
         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)
+        return self.context.uri
 
 class Typeable(object):
     """This adapter makes elements uniquely identifiable.

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 
20:04:18 2006
@@ -45,26 +45,24 @@
 
     ### Registration of settings  #####################################
 
-    def register(self, name=u'', title=u'', resource=None, filename=None,
+    def register(self, uri=u'', title=u'', resource=None, filename=None,
                        custom=False, context=None):
         """Register the setting as a utility.
         """
         # register as a global utility
         if context is None:
-            setting = GlobalSetting(name=name, title=title,
+            setting = GlobalSetting(uri=uri, title=title,
                                     resource=resource, filename=filename)
-            uri = IIdentifiable(setting).getURI()
             self.gsm.registerUtility(setting, ISetting, uri)
 
         # register as a local utility
         else:
             settings = getThemeManager(context).getSettings()
             chooser = INameChooser(settings)
-            name = name or chooser.chooseName(title, object)
-            setting = LocalSetting(name=name, title=title,
+            name = uri or chooser.chooseName(title, object)
+            setting = LocalSetting(uri=uri, title=title,
                                    resource=resource, custom=custom)
             settings[name] = setting
-            uri = IIdentifiable(setting).getURI()
             settings.registerUtility(setting, ISetting, uri)
 
     def unregister(self, uri=u'', context=None):
@@ -176,8 +174,7 @@
         if resource_getter is not None:
             resource = deepcopy(resource_getter.getResource())
 
-        setting_name = unicode(IRelatable(setting))
-        self.register(name=setting_name, title=setting.title, 
resource=resource,
+        self.register(uri=uri, title=setting.title, resource=resource,
                       context=context, custom=True)
 
     def decustomize(self, uri=u'', context=None):

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 
20:04:18 2006
@@ -57,13 +57,13 @@
         filename = file['filename']
         dom = parse(filename)
         for setting_def in dom.getElementsByTagName('setting'):
-            name = setting_def.getAttribute('name')
+            uri = setting_def.getAttribute('uri')
             title = setting_def.getAttribute('title')
-            resource = _loadResourceFromXML(setting_def, name, title)
+            resource = _loadResourceFromXML(setting_def, uri, title)
             if resource is None:
                 continue
-            resources.register(name=name, title=title, resource=resource,
-                               filename=filename)
+            resources.register(uri, title=title,
+                               resource=resource, filename=filename)
 
             file['refresh_date'] = time.time()
 
@@ -79,13 +79,12 @@
 
     resource_def = resource_defs[0]
 
-    setting = queryUtility(ISetting, uri, None)
+    setting = resources.lookup(uri)
     if setting is None:
         # create the resource
         resource = createObject(resource_def.tagName)
-        setting_name = uri.split('@')[-1] # TODO: use API
-        resources.register(name=setting_name, title=title,
-                           resource=resource, filename=filename)
+        resources.register(uri=uri, title=title, resource=resource,
+                           filename=filename)
         logger.debug("new setting added: '%s'", uri)
     else:
         resource = IResource(setting).getResource()
@@ -121,13 +120,14 @@
 def reloadSetting(uri=u''):
     """Reload a setting by name.
     """
-    setting = getGlobalSiteManager().queryUtility(ISetting, uri)
+    resources = getUtility(IResourceManager)
+    setting = resources.lookup(uri)
     filename = setting.filename
 
     if not filename:
         raise TypeError("The setting is not a file-system setting.")
 
-    _reload(setting_name=name, filename=filename)
+    _reload(uri=uri, filename=filename)
 
 def _reload(uri=u'', filename=u''):
     """Reload the settings in a file
@@ -146,5 +146,5 @@
 
         _loadResourceFromXML(setting_def, uri, title, filename)
 
-    if not name:
+    if not uri:
         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 
20:04:18 2006
@@ -26,13 +26,13 @@
 
 class Setting(object):
 
-    def __init__(self, name=u'', title=u'', resource=None):
-        self.name = name
+    def __init__(self, uri=u'', title=u'', resource=None):
+        self.uri = uri
         self.title = title
         self.resource = resource
         # add a reference from the resource to the setting
         self.resource.__parent__ = self
-        self.resource.__name__ = name
+        self.resource.__name__ = uri
 
     def __repr__(self):
         return u'<Setting: %s>' % IIdentifiable(self).getURI()

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 20:04:18 2006
@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="utf-8" ?>
-<setting name="cpsskins://[EMAIL PROTECTED]" title="Test setting 4">
-  <dummy name="dummy.resource" title="Dummy resource 4" />
+<setting uri="cpsskins://[EMAIL PROTECTED]" title="Test setting 4">
+  <dummy title="Dummy resource 4" />
 </setting>
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to