The attached patch (against 2.0.51-r2) pr9ovides minor cleanups to portage.py and emerge: + removes all usage of string module functions such as : string.split string.join string.replace string.strip string.zfill string.rjust + uses constants from portage_const instead of redefining them in portage.py + uses "string".startswith "string".endswith where it makes sense + simplified some functions : - relparse in portage.py - ververify in portage.py should be faster - depgraph.match in emerge + in some places I've replaced the except SystemError:... except: with a single except ValueError + It also fixes two small bugs: in emerge: 903: self.pkgsettings["USE"] was splitted with split(xx, " ") instead of split(xx) elsewhere uses split(xx) wich is a little different (splits on tabs also) in portage.py: in the function ververify there is a : return 1 vercache[myorigval]=1 which prevents the value from being cached in the function do_upgrade: strip() the line before checking if it's a comment only I've done some limited testing: emerge --pretend package emerge info emerge sync I'm pretty sure I haven't covered all code paths so please proofread if you apply it
Created attachment 42918 [details, diff] The patch diff -ur portage-2.0.51-r2 portage-patches
I've added the ververify fix but will leave the rest for the time being. The exceptions will all get an overhaul shortly. The emerge usage of split(" ") is safe as pkgsettings["USE"] is guaranteed to be only space-separated. The string -> str changes, I'm personally not certain about - depends on their python2.2 support. The other bits sound good, but I haven't actually had time to look at the patch yet. :(
About the string -> str changes, this is from the doc string of module string.py: """Warning: most of the code you see here isn't normally used nowadays. With Python 1.6, many of these functions are implemented as methods on the standard string object. They used to be implemented by a built-in module called strop, but strop is now obsolete itself.""" The main purpose of the patch was to remove idioms that are not normally seen in recent python code. Unfortunately it touches a lot of places and needs time to review. As a small advantage I see a small 1-2% speedup doing emerge info
Created attachment 43792 [details, diff] cleanup patch against cvs-20041110 Cleans up about the same things as previous patch: string module functions -> string methods dict.has_key(k) -> k in dict for x in dict.keys() -> for x in dict when applicable del list[list.index(x)] -> list.remove(x) a couple algorithm simplifications ... One change of semantic: pkgsplit and catpkgsplit return tuples
Created attachment 45291 [details, diff] smaller more tested version against cvs-20041128 A new version synced against portage cvs from 20041128
This is in HEAD but won't be going into stable as there were several issues that came out after use.