Author: jmorliaguet Date: Sun Jun 18 21:19:10 2006 New Revision: 3455 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: - added location roots / namespaces 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 21:19:10 2006 @@ -125,11 +125,11 @@ >>> from cpsskins.locations import Location - >>> l1 = Location(name=u'folder 1', path=(u'f1',), data=u'd1') + >>> l1 = Location(title=u'folder 1', path=(u'f1',), data=u'd1') >>> l1 <Location 'folder 1' at f1> - >>> l2 = Location(name=u'folder 1/2', path=(u'f1', 'f2'), data=u'd1/2') + >>> l2 = Location(title=u'folder 1/2', path=(u'f1', 'f2'), data=u'd1/2') >>> l2 <Location 'folder 1/2' at f1/f2> @@ -154,8 +154,8 @@ if two locations have a same path, they are equal: - >>> lA = Location(name=u'A', path=(u'f1', u'f2'), data=u'A') - >>> lB = Location(name=u'B', path=(u'f1', u'f2'), data=u'B') + >>> lA = Location(title=u'A', path=(u'f1', u'f2'), data=u'A') + >>> lB = Location(title=u'B', path=(u'f1', u'f2'), data=u'B') >>> lA == lB True @@ -172,8 +172,8 @@ >>> from pprint import pprint >>> pprint(dict(locations)) - {(u'f1',): <Location 'folder 1' at f1>, - (u'f1', 'f2'): <Location 'folder 1/2' at f1/f2>} + {(u'', u'f1'): <Location 'folder 1' at f1>, + (u'', u'f1', 'f2'): <Location 'folder 1/2' at f1/f2>} now we want to find the location of 'f1/f2/f3': @@ -204,7 +204,7 @@ 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)) + >>> l3 = Location(title=u'C', path=(u'f1', u'f3'), data=u'C', scope=(0, 1)) >>> locations.add(l3) >>> l3 @@ -225,7 +225,7 @@ 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)) + >>> l4 = Location(title=u'D', path=(u'f1', u'f4'), data=u'D', scope=(0, 2)) >>> locations.add(l4) >>> locations.find(u'f1/f4') @@ -245,7 +245,7 @@ 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)) + >>> l5 = Location(title=u'E', path=(u'f1', u'f5'), data=u'E', scope=(1, 1)) >>> locations.add(l5) >>> locations.find(u'f1/f5') @@ -257,7 +257,7 @@ 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)) + >>> l6 = Location(title=u'F', path=(u'f1', u'f6'), data=u'F', scope=(2, 0)) >>> locations.add(l6) >>> locations.find(u'f1/f6') @@ -275,13 +275,27 @@ >>> locations.find(u'f1/f6/f7/f8/f9/f10') <Location 'F' at f1/f6> +namespaces +.......... + +Namespaces can be created by specifying a location root: + + >>> l7 = Location(title=u'G', path=(u'f1',), data=u'G', root=u'pages') + >>> locations.add(l7) + + >>> 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') + >>> locations.add(l8) + + >>> locations.find(u'f1', root=u'themes') + <Location 'H' at f1 for 'themes'> + + 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: 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 21:19:10 2006 @@ -28,14 +28,18 @@ """ implements(ILocation) - def __init__(self, name=u'', path=(), data=u'', scope=(0, 0)): - self.name = name + def __init__(self, title=u'', path=(), data=u'', scope=(0, 0), root=u''): + self.title = title self.path = path self.data = data self.scope = scope + self.root = root def __repr__(self): - return "<Location '%s' at %s>" % (self.name, str(self)) + path = str(self) + if self.root: + path = u"%s for '%s'" % (path, self.root) + return "<Location '%s' at %s>" % (self.title, path) def __call__(self): return self.data @@ -61,7 +65,5 @@ def __eq__(self, other): return self.path == other.path - LocationFactory = Factory(Location) - 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 21:19:10 2006 @@ -42,29 +42,31 @@ implements(ILocationStorage) def add(self, location, name=u''): - path = location.path - if path in self: - del self[path] - self[path] = location + key = (location.root,) + location.path + if key in self: + del self[key] + self[key] = location def remove(self, locations): if not isinstance(locations, (list, tuple)): locations = [locations] for location in locations: - if location.path not in self: + key = (location.root,) + location.path + if key not in self: continue - del self[location.path] + del self[key] - def find(self, path): + def find(self, path, root=u''): if isinstance(path, basestring): path = tuple(path.split(u'/')) path_len = len(path) for i in range(path_len): p = path[0:path_len-i] - if p not in self: + key = (root,) + p + if key not in self: continue - l = self[p] + l = self[key] start, end = l.scope if (start == 0 or i >= start) and (end == 0 or i <= end): return l -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins