On Wed, Feb 16, 2005 at 08:55:21PM +0100, Thomas de Grenier de Latour wrote:
> On Wed, 16 Feb 2005 20:10:33 +0100
> Stefan Sperling <[EMAIL PROTECTED]> wrote:
>
> >
> > So hopefully this will speed up cache updates as well :)
> >
>
> >>> Updating Portage cache:
> Traceback (most recent call last):
> File "/usr/bin/emerge", line 2601, in ?
> mynodes.sort()
> AttributeError: 'generator' object has no attribute 'sort'
Ok, python code that expects something sortable instead of iterators
should use list(retval) to wrap the return value. I just grep'ed
through the portage and gentoolkit code and it it seems, that only this
line of code is dangerous.
>
> That doesn't kill the idea of using generators in some cases
> though (and that's a good idea indeed), but just means it will
> need a bit more care. Actually, i dont think it is the right way
> to modify cp_all() return type (even if you fix all its usages in
> portage, it will still break some external tools). The patch
> should probably rather add a new function, and try to use it where
> possible. My 2 cents...
Yes, your are absolutely right. Maybe we should introduce
cp_all_generator()
and use
cp_all()
to wrap the return value of cp_all_generator() for
iterator-unsafe-code. Patch enclosed.
juergen
--- portage_old.py 2005-02-17 00:23:04.990957928 +0100
+++ portage.py 2005-02-17 00:25:23.282934352 +0100
@@ -5368,14 +5368,18 @@
def cp_all(self):
"returns a list of all keys in our tree"
- biglist=[]
+ return list(self.cp_all_generator())
+
+ def cp_all_generator(self):
+ "yield all keys in our tree"
for x in self.mysettings.categories:
+ biglist=[]
for oroot in self.porttrees:
for y in
listdir(oroot+"/"+x,EmptyOnError=1,ignorecvs=1):
mykey=x+"/"+y
if not mykey in biglist:
biglist.append(mykey)
- return biglist
+ yield(mykey)
def p_list(self,mycp):
returnme=[]
--
[email protected] mailing list