Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 69523 - cleanup patch
Summary: cleanup patch
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core (show other bugs)
Hardware: All All
: High minor (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-30 11:06 UTC by Ludovic Aubry
Modified: 2005-07-31 00:57 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
The patch (cleanup.patch,50.93 KB, patch)
2004-10-30 11:08 UTC, Ludovic Aubry
Details | Diff
cleanup patch against cvs-20041110 (cleanup2.patch,84.36 KB, patch)
2004-11-12 09:26 UTC, Ludovic Aubry
Details | Diff
smaller more tested version against cvs-20041128 (cleanup3.patch,78.80 KB, patch)
2004-12-04 14:14 UTC, Ludovic Aubry
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ludovic Aubry 2004-10-30 11:06:53 UTC
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
Comment 1 Ludovic Aubry 2004-10-30 11:08:30 UTC
Created attachment 42918 [details, diff]
The patch

diff -ur portage-2.0.51-r2 portage-patches
Comment 2 Jason Stubbs (RETIRED) gentoo-dev 2004-11-02 06:01:23 UTC
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. :(
Comment 3 Ludovic Aubry 2004-11-02 13:54:57 UTC
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

Comment 4 Ludovic Aubry 2004-11-12 09:26:10 UTC
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
Comment 5 Ludovic Aubry 2004-12-04 14:14:01 UTC
Created attachment 45291 [details, diff]
smaller more tested version against cvs-20041128

A new version synced against portage cvs from 20041128
Comment 6 Jason Stubbs (RETIRED) gentoo-dev 2005-07-31 00:57:18 UTC
This is in HEAD but won't be going into stable as there were several issues 
that came out after use.