pyversions.py generates wrong output with version_only option

Bug #92287 reported by Pascal R.
6
Affects Status Importance Assigned to Milestone
python-central (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

Binary package hint: python-central

On Ubuntu 6.10 running pyversions -vd should return '2.4' but it returns 'in/python2.4'
this also affects post-install configurations with pycentral.

the pyversions.py script is installed in two locations and two versions (!?):
/usr/share/pycentral-data/pyversions.py
/usr/share/python/pyversions.py

Both can be fixed this way:
* search location of this text:

def default_version(version_only=False):
    global _default_version
    if not _default_version:
        _default_version = link = os.readlink('/usr/bin/python')
    if version_only:
        return _default_version[6:]
    else:
        return _default_version

* replace the line:

        return _default_version[6:]

* with this line:

        return _default_version.split('python')[-1]

Is this the right place to post this bugreport/fix? This was my first one.

Revision history for this message
Filip Salomonsson (filip-salomonsson) wrote :

This occurs if /usr/bin/python is a symbolic link whose target is an absolute path, not just "python2.x". It's not on my system, but apparently it can be.

Another, related, issue is that update-alternatives may make /usr/bin/python a link to /etc/alternatives/python, which, in turn, is a link to /usr/bin/python2.x. The original function does not cater for such circumstances.

I believe the attached patch fixes both issues, but I haven't tested it (beyond verifying that the results are as correct as before on my own box).

Revision history for this message
Pascal R. (niun) wrote :

this patch works on my system (Ubuntu 6.10) and it is better than my prior posted patch, because it sets the global variable _default_version to the correct value.

Changed in python-central:
status: New → Fix Committed
Revision history for this message
Matthias Klose (doko) wrote :

You never should modify files by yourself in /usr (except /usr/local); doing so will make your system unreliable (and as seen here break it in some cases). Using alternatives is not possible: you'll break all those modules and extensions that are available for one python version only.

If you do want to set another default for your own use, use /usr/local/bin, or ~/bin.

closing the report.

Changed in python-central:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.