[migration] enhance RqlForIterator so we can do 'for e in rqliter(...).entities()' stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 20 Aug 2010 08:17:04 +0200
branchstable
changeset 6125 46b9cbbc1e37
parent 6124 c5900230809b
child 6126 aca6a2c357fd
[migration] enhance RqlForIterator so we can do 'for e in rqliter(...).entities()'
server/migractions.py
--- a/server/migractions.py	Fri Aug 20 08:16:03 2010 +0200
+++ b/server/migractions.py	Fri Aug 20 08:17:04 2010 +0200
@@ -1405,9 +1405,7 @@
     def __iter__(self):
         return self
 
-    def next(self):
-        if self._rsetit is not None:
-            return self._rsetit.next()
+    def _get_rset(self):
         rql, kwargs = self.rql, self.kwargs
         if kwargs:
             msg = '%s (%s)' % (rql, kwargs)
@@ -1417,11 +1415,23 @@
             if not self._h.confirm('Execute rql: %s ?' % msg):
                 raise StopIteration
         try:
-            rset = self._h._cw.execute(rql, kwargs)
+            return self._h._cw.execute(rql, kwargs)
         except Exception, ex:
             if self._h.confirm('Error: %s\nabort?' % ex):
                 raise
             else:
                 raise StopIteration
+
+    def next(self):
+        if self._rsetit is not None:
+            return self._rsetit.next()
+        rset = self._get_rset()
         self._rsetit = iter(rset)
         return self._rsetit.next()
+
+    def entities(self):
+        try:
+            rset = self._get_rset()
+        except StopIteration:
+            return []
+        return rset.entities()