Author: jmorliaguet
Date: Mon Jun 19 21:02:33 2006
New Revision: 3460

Modified:
   cpsskins/branches/paris-sprint-2006/locations/README.txt
   cpsskins/branches/paris-sprint-2006/storage/locations.py

Log:

- added methods to get location paths



Modified: cpsskins/branches/paris-sprint-2006/locations/README.txt
==============================================================================
--- cpsskins/branches/paris-sprint-2006/locations/README.txt    (original)
+++ cpsskins/branches/paris-sprint-2006/locations/README.txt    Mon Jun 19 
21:02:33 2006
@@ -175,6 +175,12 @@
     {(u'', u'f1'): <Location 'folder 1' at f1>,
      (u'', u'f1', 'f2'): <Location 'folder 1/2' at f1/f2>}
 
+we can obtain the list of locations with:
+
+    >>> locations.getPaths()
+    [(u'f1', 'f2'), (u'f1',)]
+
+
 now we want to find the location of 'f1/f2/f3':
 
     >>> locations.find(u'f1/f2/f3')
@@ -210,7 +216,7 @@
     >>> l3
     <Location 'C' at f1/f3>
 
-means that the 'l3' location has a scope covering f1/f3 and all immediate 
+means that the 'l3' location has a scope covering f1/f3 and all immediate
 sublocation paths (f1/f3/...) but not (f1/f3/.../...)
 
 
@@ -286,12 +292,28 @@
     >>> locations.find(u'f1', root=u'pages')
     <Location 'G' at f1 for 'pages'>
 
-    >>> l8 = Location(title=u'H', path=(u'f1',), data=u'H', root=u'themes')
+    >>> l8 = Location(title=u'H', path=(u'f1',), data=u'H', root=u'engines')
     >>> locations.add(l8)
 
-    >>> locations.find(u'f1', root=u'themes')
-    <Location 'H' at f1 for 'themes'>
+    >>> locations.find(u'f1', root=u'engines')
+    <Location 'H' at f1 for 'engines'>
+
+we get the list of location paths with:
+
+    >>> locations.getPaths(u'pages')
+    [(u'f1',)]
+
+or with:
+
+    >>> locations.getPaths(u'engines')
+    [(u'f1',)]
+
+
+to obtain all the paths we use:
 
+    >>> locations.getAllPaths() # doctest: +NORMALIZE_WHITESPACE
+    [(u'f1', 'f2'), (u'f1', u'f3'), (u'f1',), (u'f1', u'f4'), (u'f1', u'f5'),
+    (u'f1', u'f6')]
 
 finally we remove the locations:
 

Modified: cpsskins/branches/paris-sprint-2006/storage/locations.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/storage/locations.py    (original)
+++ cpsskins/branches/paris-sprint-2006/storage/locations.py    Mon Jun 19 
21:02:33 2006
@@ -17,6 +17,7 @@
 """
 __docformat__ = "reStructuredText"
 
+from sets import Set
 from zope.app.container.constraints import contains
 from zope.interface import implements
 
@@ -31,6 +32,12 @@
     def find(path):
         """Find a location by its path"""
 
+    def getPaths(root):
+        """Get a list of locations by root."""
+
+    def getAllPaths():
+        """Get a list of locations independently of roots."""
+
 class LocationStorage(Storage):
     """A BTree-based location storage
 
@@ -72,4 +79,16 @@
                 return l
         return None
 
+    def getPaths(self, root=u''):
+        locations = Set()
+        for key in self.keys():
+            if key[0] != root:
+                continue
+            locations.add(key[1:])
+        return list(locations)
 
+    def getAllPaths(self):
+        locations = Set()
+        for key in self.keys():
+            locations.add(key[1:])
+        return list(locations)
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to