devtools/dataimport.py
branchstable
changeset 3486 ea6bf6f9ba0c
parent 3318 5b47b9f09bca
child 4136 47060a66c97f
child 4212 ab6573088b4a
equal deleted inserted replaced
3470:c9c8b231db7b 3486:ea6bf6f9ba0c
   149     def _put(self, type, item):
   149     def _put(self, type, item):
   150         self.items.append(item)
   150         self.items.append(item)
   151         return len(self.items) - 1
   151         return len(self.items) - 1
   152 
   152 
   153     def add(self, type, item):
   153     def add(self, type, item):
   154         assert isinstance(item, dict), item
   154         assert isinstance(item, dict), 'item is not a dict but a %s' % type(item)
   155         eid = item['eid'] = self._put(type, item)
   155         eid = item['eid'] = self._put(type, item)
   156         self.eids[eid] = item
   156         self.eids[eid] = item
   157         self.types.setdefault(type, []).append(eid)
   157         self.types.setdefault(type, []).append(eid)
   158 
   158 
   159     def relate(self, eid_from, rtype, eid_to):
   159     def relate(self, eid_from, rtype, eid_to):
   170     def get_many(self, name, key):
   170     def get_many(self, name, key):
   171         return self.indexes[name].get(key, [])
   171         return self.indexes[name].get(key, [])
   172 
   172 
   173     def get_one(self, name, key):
   173     def get_one(self, name, key):
   174         eids = self.indexes[name].get(key, [])
   174         eids = self.indexes[name].get(key, [])
   175         assert len(eids) == 1
   175         assert len(eids) == 1, 'expected a single one got %i' % len(eids)
   176         return eids[0]
   176         return eids[0]
   177 
   177 
   178     def find(self, type, key, value):
   178     def find(self, type, key, value):
   179         for idx in self.types[type]:
   179         for idx in self.types[type]:
   180             item = self.items[idx]
   180             item = self.items[idx]