22 'document':( ('fichier', 'annee','mois','jour','type'), |
22 'document':( ('fichier', 'annee','mois','jour','type'), |
23 [('concerne','affaire'), |
23 [('concerne','affaire'), |
24 ] ), |
24 ] ), |
25 }) |
25 }) |
26 |
26 |
27 |
27 |
28 |
28 |
29 DATA = { 'societe': [ ('CETIAD', 'Dijon'), |
29 DATA = { 'societe': [ ('CETIAD', 'Dijon'), |
30 ('EDF_R&D', 'Clamart'), |
30 ('EDF_R&D', 'Clamart'), |
31 ('Logilab', 'Paris'), |
31 ('Logilab', 'Paris'), |
32 ], |
32 ], |
95 for data in DATA[self._entity]: |
95 for data in DATA[self._entity]: |
96 yield data[0] |
96 yield data[0] |
97 for nom, entity in self.schema.get_relations(self._entity) : |
97 for nom, entity in self.schema.get_relations(self._entity) : |
98 yield nom+'/' |
98 yield nom+'/' |
99 yield entity+'/' |
99 yield entity+'/' |
100 |
100 |
101 def ls(path) : |
101 def ls(path) : |
102 p = PathParser(SCHEMA,path) |
102 p = PathParser(SCHEMA,path) |
103 p.parse() |
103 p.parse() |
104 return list(p.get_list()) |
104 return list(p.get_list()) |
105 |
105 |
111 self.path = path |
111 self.path = path |
112 self._components = iter([comp for comp in self.path.split('/') if comp]) |
112 self._components = iter([comp for comp in self.path.split('/') if comp]) |
113 self._e_type = None |
113 self._e_type = None |
114 self._restrictions = [] |
114 self._restrictions = [] |
115 self._alphabet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') |
115 self._alphabet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') |
116 |
116 |
117 def parse(self): |
117 def parse(self): |
118 self._var = self._alphabet.pop(0) |
118 self._var = self._alphabet.pop(0) |
119 self._e_type = self._components.next() |
119 self._e_type = self._components.next() |
120 e_type = self._e_type.capitalize() |
120 e_type = self._e_type.capitalize() |
121 self._restrictions.append('%s is %s' % (self._var, e_type)) |
121 self._restrictions.append('%s is %s' % (self._var, e_type)) |
122 try: |
122 try: |
123 self.process_entity() |
123 self.process_entity() |
124 except StopIteration : |
124 except StopIteration : |
125 pass |
125 pass |
126 return 'Any %s WHERE %s' % (self._var, ', '.join(self._restrictions)) |
126 return 'Any %s WHERE %s' % (self._var, ', '.join(self._restrictions)) |
127 |
127 |
128 def process_entity(self) : |
128 def process_entity(self) : |
129 _next = self._components.next() |
129 _next = self._components.next() |
130 if _next in self.schema.get_attrs(self._e_type) : |
130 if _next in self.schema.get_attrs(self._e_type) : |
131 attr = _next |
131 attr = _next |
132 try: |
132 try: |
145 try: |
145 try: |
146 _next = self._components.next() |
146 _next = self._components.next() |
147 self._restrictions.append('%s is %s' % (r_var, _next.capitalize())) |
147 self._restrictions.append('%s is %s' % (r_var, _next.capitalize())) |
148 except StopIteration: |
148 except StopIteration: |
149 raise |
149 raise |
150 self.process_entity() |
150 self.process_entity() |
151 |
151 |
152 |
152 |
153 def to_rql(path) : |
153 def to_rql(path) : |
154 p = SytPathParser(SCHEMA,path) |
154 p = SytPathParser(SCHEMA,path) |
155 return p.parse() |
155 return p.parse() |
156 |
156 |