classification
Title: let platform.uname try harder
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: lemburg Nosy List: benjamin.peterson, jjt009, lemburg
Priority: low Keywords: easy, patch

Created on 2008-05-19 00:16 by benjamin.peterson, last changed 2008-06-13 15:12 by benjamin.peterson. This issue is now closed.

Files
File name Uploaded Description Edit
platform.patch jjt009, 2008-06-11 22:46 Patch for platform.py to correct bug 2912
platform2.diff benjamin.peterson, 2008-06-12 21:56
platform3.diff benjamin.peterson, 2008-06-13 14:20
platform4.diff benjamin.peterson, 2008-06-13 14:59
Messages (18)
msg67052 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-05-19 00:15
Sometimes os.uname (which is used to bootstrap platform.uname) can
return 'unknown' for some items. The fallback code in platform.uname can
usually fill these blanks in. However, this is only used when os.uname
is not present. It would be useful if platform tried to fill these
unknowns in.
msg67796 - (view) Author: James Thomas (jjt009) Date: 2008-06-07 02:26
I can work on this task.
msg67798 - (view) Author: James Thomas (jjt009) Date: 2008-06-07 04:08
i'm looking at the source and there doesn't appear to be a function
uname within os.py. are we just considering the uname function in
platform.py?
msg67799 - (view) Author: James Thomas (jjt009) Date: 2008-06-07 05:14
much handling code already seems to exist under the line
except AttributeError:
in platform.py (function uname(), lines 1101-1161 platform.py)
i'm not too familiar with the Python codebase (i just began developing
with Python a few days back)
msg67804 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-06-07 12:43
Thanks for volunteering, James! I think you misunderstood the task. Do
you see how in platform's uname, it only tries to find missing values
for os.uname if os.uname doesn't exist? Sometimes os.uname exists, but
it doesn't provide all the values. Your task is to modify platform.uname
to try to fill in missing values in os.uname if they are present.
msg67913 - (view) Author: James Thomas (jjt009) Date: 2008-06-10 19:33
Alright, that makes things much clearer. 
I'm looking at this code snippet in platform.py:
    if system == 'unknown':
        system = ''
    if node == 'unknown':
        node = ''
    if release == 'unknown':
        release = ''
    if version == 'unknown':
        version = ''
    if machine == 'unknown':
        machine = ''
    if processor == 'unknown':
        processor = ''

So essentially what you want me to do is add code that tries to replace
the ''s with meaningful information. From what I understand, os.uname()
is only defined in posix-based systems (it is imported from the module
posix, after all). That means that 'unknown' is returned because the
uname command is unable to retrieve the necessary information. Are there
any alternatives to uname that could provide me with system info?
msg67914 - (view) Author: James Thomas (jjt009) Date: 2008-06-10 19:39
Ah, ok, the code under except AttributeError: gives me some good ideas.
Should I use the methods utilized there to extract information from the
system?
msg67924 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-06-10 21:16
>Ah, ok, the code under except AttributeError: gives me some good ideas.
>Should I use the methods utilized there to extract information from the
>system?

Right on! You don't need to write any new code, just make sure the code
under the except AttributeError is utilized even if os.uname returns
blank spots.
msg68029 - (view) Author: James Thomas (jjt009) Date: 2008-06-11 22:46
Here is the patch (apply to platform.py)
msg68098 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-06-12 21:56
Thanks for doing this. Would you please try on Windows the patch, I'm
attaching now?
msg68108 - (view) Author: James Thomas (jjt009) Date: 2008-06-13 00:04
Your patch works perfectly on windows. Thanks for your help.
msg68111 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-06-13 00:16
Marc, could you look at this please?
msg68139 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2008-06-13 09:18
There are two patches. Which one do you want me to look at ?

Note that platform.py should stay Python 1.5.2 compatible, ie. no new
builtins, no True/False.

The second patch also appears to mix tabs/spaces.
msg68162 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-06-13 14:20
Ok. I ran it through reindent.py and removed the True and False.
msg68165 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2008-06-13 14:55
On 2008-06-13 16:20, Benjamin Peterson wrote:
> Benjamin Peterson <musiccomposition@gmail.com> added the comment:
> 
> Ok. I ran it through reindent.py and removed the True and False.

Thanks, but the all() is still there :-)

You can change that to:

... or not filter(None, [system, node, release, version, machine]):

should work on all Python versions.
msg68166 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-06-13 14:59
Wow, I really admire you for keeping it compatible with Python 1.5. As
you may have noticed, I'm addicted to new feature. :)
msg68167 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2008-06-13 15:05
On 2008-06-13 16:59, Benjamin Peterson wrote:
> Benjamin Peterson <musiccomposition@gmail.com> added the comment:
> 
> Wow, I really admire you for keeping it compatible with Python 1.5. As
> you may have noticed, I'm addicted to new feature. :)

Yeah, well... it's a hobby :-)

We can probably bump that to Python 2.1 or even 2.3 after 2.6
is out.

The main reason for keeping 1.5.2 compatibility was mxCGIPython
which started platform.py in the first place. Since it turned out
to be useful for all kinds of things, it's good to be able to
backport any changes to installations still using older Python
versions.

The patches look OK now.

Thanks,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jun 13 2008)
 >>> Python/Zope Consulting and Support ...        http://www.egenix.com/
 >>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
2008-07-07: EuroPython 2008, Vilnius, Lithuania            23 days to go

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::

    eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
     D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
            Registered at Amtsgericht Duesseldorf: HRB 46611
msg68168 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-06-13 15:12
Ok. I applied the patch in r64233.
History
Date User Action Args
2008-06-13 15:12:04benjamin.petersonsetstatus: open -> closed
resolution: fixed
messages: + msg68168
2008-06-13 15:05:58lemburgsetmessages: + msg68167
2008-06-13 14:59:22benjamin.petersonsetfiles: + platform4.diff
messages: + msg68166
2008-06-13 14:55:44lemburgsetmessages: + msg68165
2008-06-13 14:20:12benjamin.petersonsetfiles: + platform3.diff
messages: + msg68162
2008-06-13 09:18:18lemburgsetmessages: + msg68139
2008-06-13 00:16:36benjamin.petersonsetassignee: lemburg
messages: + msg68111
nosy: + lemburg
2008-06-13 00:04:16jjt009setmessages: + msg68108
2008-06-12 21:56:24benjamin.petersonsetfiles: + platform2.diff
messages: + msg68098
2008-06-11 22:46:27jjt009setfiles: + platform.patch
keywords: + patch
messages: + msg68029
2008-06-10 21:16:08benjamin.petersonsetmessages: + msg67924
2008-06-10 19:39:50jjt009setmessages: + msg67914
2008-06-10 19:33:40jjt009setmessages: + msg67913
2008-06-07 12:43:35benjamin.petersonsetmessages: + msg67804
2008-06-07 05:14:34jjt009setmessages: + msg67799
2008-06-07 04:08:17jjt009setmessages: + msg67798
2008-06-07 02:26:03jjt009setnosy: + jjt009
messages: + msg67796
2008-05-19 00:19:10benjamin.petersonsetpriority: low
components: + Library (Lib)
2008-05-19 00:16:36benjamin.petersonsetversions: + Python 2.6
2008-05-19 00:16:10benjamin.petersoncreate