Author: jmorliaguet
Date: Sun Jun 18 16:46:25 2006
New Revision: 3449

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

Log:

- basic implementation, scopes are not taken into account



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    Sun Jun 18 
16:46:25 2006
@@ -127,11 +127,11 @@
 
     >>> l1 = Location(name=u'folder 1', path=(u'f1',), data=u'd1')
     >>> l1
-    <Location at: /f1 ('folder 1')>
+    <Location at: f1 ('folder 1')>
 
     >>> l2 = Location(name=u'folder 1/2', path=(u'f1', 'f2'), data=u'd1/2')
     >>> l2
-    <Location at: /f1/f2 ('folder 1/2')>
+    <Location at: f1/f2 ('folder 1/2')>
 
 to get the location's data, we call the location:
 
@@ -160,6 +160,44 @@
     >>> lA == lB
     True
 
+We create a location storage:
 
+    >>> from cpsskins.storage.locations import LocationStorage
+    >>> locations = LocationStorage()
 
+we add the locations to the storage:
 
+    >>> locations.add(l1)
+    >>> locations.add(l2)
+
+    >>> from pprint import pprint
+    >>> pprint(dict(locations))
+    {u'f1': <Location at: f1 ('folder 1')>,
+     u'f1/f2': <Location at: f1/f2 ('folder 1/2')>}
+
+now we want to find the location of 'f1/f2/f3':
+
+    >>> locations.find(u'f1/f2/f3')
+    <Location at: f1/f2 ('folder 1/2')>
+
+or get the location of 'f1/f2'
+
+    >>> locations.find(u'f1/f2')
+    <Location at: f1/f2 ('folder 1/2')>
+
+or 'f1':
+
+    >>> locations.find(u'f1')
+    <Location at: f1 ('folder 1')>
+
+    >>> locations.find(u'f2') is None
+    True
+
+
+we remove the locations:
+
+    >>> locations.remove(l1)
+    >>> locations.remove(l2)
+
+    >>> list(locations.keys())
+    []

Modified: cpsskins/branches/paris-sprint-2006/locations/location.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/locations/location.py   (original)
+++ cpsskins/branches/paris-sprint-2006/locations/location.py   Sun Jun 18 
16:46:25 2006
@@ -28,14 +28,14 @@
     """
     implements(ILocation)
 
-    def __init__(self, name=u'', path=(), data=u'', scope=()):
+    def __init__(self, name=u'', path=(), data=u'', scope=(0, 0)):
         self.name = name
         self.path = path
         self.data = data
         self.scope = scope
 
     def __repr__(self):
-        return "<Location at: /%s ('%s')>" % (str(self), self.name)
+        return "<Location at: %s ('%s')>" % (str(self), self.name)
 
     def __call__(self):
         return self.data

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    Sun Jun 18 
16:46:25 2006
@@ -28,6 +28,9 @@
     """ """
     contains(ILocation)
 
+    def find(path):
+        """Find a location by its path"""
+
 class LocationStorage(Storage):
     """A BTree-based location storage
 
@@ -38,3 +41,29 @@
     """
     implements(ILocationStorage)
 
+    def add(self, location, name=u''):
+        path = str(location)
+        if path in self:
+            del self[path]
+        self[path] = location
+
+    def remove(self, locations):
+        if not isinstance(locations, list):
+            locations = [locations]
+        for location in locations:
+            if str(location) not in self:
+                continue
+            del self[str(location)]
+
+    def find(self, path):
+        if path in self:
+            return self[path]
+
+        spath = path.split(u'/')
+        spath_len = len(spath)
+        for i in range(spath_len):
+            p = u'/'.join(spath[0:spath_len-i])
+            if p in self:
+                return self[p]
+        return None
+
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to