Author: jmorliaguet Date: Sun Jun 18 20:22:48 2006 New Revision: 3453 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 cpsskins/branches/paris-sprint-2006/storage/storage.py
Log: - implemented location scopes (the same notation as in CPSSkins / CPSPortlets) 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 20:22:48 2006 @@ -127,11 +127,11 @@ >>> l1 = Location(name=u'folder 1', path=(u'f1',), data=u'd1') >>> l1 - <Location at: f1 ('folder 1')> + <Location 'folder 1' at f1> >>> l2 = Location(name=u'folder 1/2', path=(u'f1', 'f2'), data=u'd1/2') >>> l2 - <Location at: f1/f2 ('folder 1/2')> + <Location 'folder 1/2' at f1/f2> to get the location's data, we call the location: @@ -172,32 +172,120 @@ >>> from pprint import pprint >>> pprint(dict(locations)) - {(u'f1',): <Location at: f1 ('folder 1')>, - (u'f1', 'f2'): <Location at: f1/f2 ('folder 1/2')>} + {(u'f1',): <Location 'folder 1' at f1>, + (u'f1', 'f2'): <Location 'folder 1/2' at f1/f2>} now we want to find the location of 'f1/f2/f3': >>> locations.find(u'f1/f2/f3') - <Location at: f1/f2 ('folder 1/2')> + <Location 'folder 1/2' at f1/f2> or get the location of 'f1/f2' >>> locations.find(u'f1/f2') - <Location at: f1/f2 ('folder 1/2')> + <Location 'folder 1/2' at f1/f2> or 'f1': >>> locations.find(u'f1') - <Location at: f1 ('folder 1')> + <Location 'folder 1' at f1> >>> locations.find(u'f2') is None True +scopes +...... -we remove the locations: +so far the locations that we have created did not specify any scope. By +default their scope was (0, 0), meaning: + +- starting from the location's path to all sublocations + +By specifying a scope we can restrict the paths covered by a location, for +instance: + + >>> l3 = Location(name=u'C', path=(u'f1', u'f3'), data=u'C', scope=(0, 1)) + >>> locations.add(l3) + + >>> l3 + <Location 'C' at f1/f3> + +means that the 'l3' location has a scope covering f1/f3 and all immediate +sublocation paths (f1/f3/...) but not (f1/f3/.../...) + + + >>> locations.find(u'f1/f3') + <Location 'C' at f1/f3> + + >>> locations.find(u'f1/f3/f4') + <Location 'C' at f1/f3> + + >>> locations.find(u'f1/f3/f4/f5') + <Location 'folder 1' at f1> + +l4 has a scope covering 'f1/f4' and sublocations of level 1 and 2: + + >>> l4 = Location(name=u'D', path=(u'f1', u'f4'), data=u'D', scope=(0, 2)) + >>> locations.add(l4) + + >>> locations.find(u'f1/f4') + <Location 'D' at f1/f4> + + >>> locations.find(u'f1/f4/f5') + <Location 'D' at f1/f4> + + >>> locations.find(u'f1/f4/f5/f6') + <Location 'D' at f1/f4> + + >>> locations.find(u'f1/f4/f5/f6/f7') + <Location 'folder 1' at f1> + + >>> locations.find(u'f1/f4/f5/f6/f7/f8') + <Location 'folder 1' at f1> + +l5 has a scope covering the 'f1/f5' location's immediate sublocations only: + + >>> l5 = Location(name=u'E', path=(u'f1', u'f5'), data=u'E', scope=(1, 1)) + >>> locations.add(l5) + + >>> locations.find(u'f1/f5') + <Location 'folder 1' at f1> + + >>> locations.find(u'f1/f5/f6') + <Location 'E' at f1/f5> + +l6 has a scope covering the 'f1/f6' location's sublocations of level 2 or +more: + + >>> l6 = Location(name=u'F', path=(u'f1', u'f6'), data=u'F', scope=(2, 0)) + >>> locations.add(l6) + + >>> locations.find(u'f1/f6') + <Location 'folder 1' at f1> + + >>> locations.find(u'f1/f6/f7') + <Location 'folder 1' at f1> + + >>> locations.find(u'f1/f6/f7/f8') + <Location 'F' at f1/f6> + + >>> locations.find(u'f1/f6/f7/f8/f9') + <Location 'F' at f1/f6> + + >>> locations.find(u'f1/f6/f7/f8/f9/f10') + <Location 'F' at f1/f6> + +finally we remove the locations: >>> locations.remove(l1) >>> locations.remove(l2) + >>> locations.remove(l3) + >>> list(locations) + [(u'f1', u'f4'), (u'f1', u'f5'), (u'f1', u'f6')] + +or we purge the entire storage: + + >>> locations.purge() - >>> list(locations.keys()) + >>> list(locations) [] 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 20:22:48 2006 @@ -35,7 +35,7 @@ self.scope = scope def __repr__(self): - return "<Location at: %s ('%s')>" % (str(self), self.name) + return "<Location '%s' at %s>" % (self.name, str(self)) 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 20:22:48 2006 @@ -48,7 +48,7 @@ self[path] = location def remove(self, locations): - if not isinstance(locations, list): + if not isinstance(locations, (list, tuple)): locations = [locations] for location in locations: if location.path not in self: @@ -58,13 +58,17 @@ def find(self, path): if isinstance(path, basestring): path = tuple(path.split(u'/')) - if path in self: - return self[path] path_len = len(path) for i in range(path_len): p = path[0:path_len-i] - if p in self: - return self[p] + if p not in self: + continue + l = self[p] + start, end = l.scope + dist = path_len - len(p) + if (start == 0 or dist >= start) and (end == 0 or dist <= end): + return l return None + Modified: cpsskins/branches/paris-sprint-2006/storage/storage.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/storage/storage.py (original) +++ cpsskins/branches/paris-sprint-2006/storage/storage.py Sun Jun 18 20:22:48 2006 @@ -95,7 +95,7 @@ return self[name] def purge(self): - self.remove(list(self)) + self.remove(list(self.values())) def __setitem__(self, key, object): self._SampleContainer__data[key] = object -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins