Identifying platform in Python code

Identifying platform in Python code

Jeffrey Barish
Karma: 48
2007-06-04 16:00 UTC
How do I determine in my code that I am running on the N800? Neither
os.name nor sys.platform gets the job done. The former returns "posix",
the latter "linux2", and I get the same strings when I run on Ubuntu.
--
Jeffrey Barish
  •  Reply

Re: Identifying platform in Python code

Allan Doyle
Karma: 25
2007-06-04 16:13 UTC
On Jun 4, 2007, at 12:00, Jeffrey Barish wrote:

> How do I determine in my code that I am running on the N800? Neither
> os.name nor sys.platform gets the job done. The former returns
> "posix",
> the latter "linux2", and I get the same strings when I run on Ubuntu.

You can parse it out of something like

import commands
id = commands.getoutput("uname -a")

if id has "Linux Nokia-N800" in it, it's an N800
if id has "Linux Nokia770" in it, it's a 770

This may change over time with newer versions of the OS but it works
for now.


--
Allan Doyle
http://museum.mit.edu/mwow
+1.781.433.2695
  •  Reply

Re: Identifying platform in Python code

Frantisek Dufka
Karma: 642
2007-06-04 19:49 UTC
Jeffrey Barish wrote:
> How do I determine in my code that I am running on the N800? Neither
> os.name nor sys.platform gets the job done. The former returns "posix",
> the latter "linux2", and I get the same strings when I run on Ubuntu.

Check /etc/osso_software_version file. This is the firmware version.
RX-34 on the beginning means N800. Of course this is not very portable
and may fail in future but currently it work for both N770 and N800.

Frantisek
  •  Reply

Re: Identifying platform in Python code

Daniel Stone
Karma: 29
2007-06-04 21:44 UTC
On Mon, Jun 04, 2007 at 09:49:39PM +0200, ext Frantisek Dufka wrote:
> Jeffrey Barish wrote:
> > How do I determine in my code that I am running on the N800? Neither
> > os.name nor sys.platform gets the job done. The former returns "posix",
> > the latter "linux2", and I get the same strings when I run on Ubuntu.
>
> Check /etc/osso_software_version file. This is the firmware version.
> RX-34 on the beginning means N800. Of course this is not very portable
> and may fail in future but currently it work for both N770 and N800.

If you're going to check the filesystem, hit up /proc/component_version.

Cheers,
Daniel
  •  Reply

Re: Identifying platform in Python code

Frantisek Dufka
Karma: 642
2007-06-05 06:56 UTC
Daniel Stone wrote:
> On Mon, Jun 04, 2007 at 09:49:39PM +0200, ext Frantisek Dufka wrote:
>> Jeffrey Barish wrote:
>>> How do I determine in my code that I am running on the N800? Neither
>>> os.name nor sys.platform gets the job done. The former returns "posix",
>>> the latter "linux2", and I get the same strings when I run on Ubuntu.
>> Check /etc/osso_software_version file. This is the firmware version.
>> RX-34 on the beginning means N800. Of course this is not very portable
>> and may fail in future but currently it work for both N770 and N800.
>
> If you're going to check the filesystem, hit up /proc/component_version.
>

Right, forgot about that one. /proc/component_version is better for
knowing specific hardware, osso_software_version is better if you are
interested in which specific firmware is installed (and in fact for N770
hacker edition it contains RX-34 by mistake so component_version is
safer bet).

But the real question is why you want to know it in the first place.
Maybe there is better way to check some specific feature instead of
checking hardware version.
  •  Reply

Re: Identifying platform in Python code

Fred Pacquier
Karma: 34
2007-06-05 16:42 UTC
Frantisek Dufka a écrit :
>
> Right, forgot about that one. /proc/component_version is better for
> knowing specific hardware, osso_software_version is better if you are
> interested in which specific firmware is installed (and in fact for
> N770 hacker edition it contains RX-34 by mistake so component_version
> is safer bet).
> But the real question is why you want to know it in the first place.
> Maybe there is better way to check some specific feature instead of
> checking hardware version.

I am not the OP but I also had the same need a while ago and was happy
to see these answers. I had found the "uname" hack by myself but maybe
the file checking is better as it saves importing another module.

My specific problem was determining the screen resolution at the start
of a pyGame app, to run it fullscreen on the tablet, and windowed on
other platforms. This does not seem possible from pyGame itself, the
only workaround I could find was to also import gtk just to use its
gtk.gdk.screen_width() and gtk.gdk.screen_height() functions once.

As this is a lot of overhead for the tablet, I preferred to detect that
platform first and set the values manually, and only use gtk detection
for more powerful platforms. If there's a better way I'd love to know it :-)
  •  Reply

Re: Identifying platform in Python code

Marius Gedminas
Karma: 552
2007-06-05 16:59 UTC
On Tue, Jun 05, 2007 at 06:42:41PM +0200, Fred Pacquier wrote:
> My specific problem was determining the screen resolution at the start
> of a pyGame app, to run it fullscreen on the tablet, and windowed on
> other platforms. This does not seem possible from pyGame itself,

How about taking the largest one from pygame.display.list_modes()?

> the
> only workaround I could find was to also import gtk just to use its
> gtk.gdk.screen_width() and gtk.gdk.screen_height() functions once.

Both approaches will fail when you have a dual-head system -- you'll see
a large combined display size (e.g. 2308x1024 for a 1024x768+1280x1024
dual-head mode that crashes pygame when you try to switch to it). With
gtk.gdk you can at least find the number of screens and their
resolutions.

> As this is a lot of overhead for the tablet, I preferred to detect that
> platform first and set the values manually, and only use gtk detection
> for more powerful platforms. If there's a better way I'd love to know it :-)

Marius Gedminas
--
Gates' Law: Every 18 months, the speed of software halves.
  •  Reply

Re: Identifying platform in Python code

Fred Pacquier
Karma: 34
2007-06-05 19:53 UTC
Marius Gedminas a écrit :

> On Tue, Jun 05, 2007 at 06:42:41PM +0200, Fred Pacquier wrote:
>> My specific problem was determining the screen resolution at the start
>> of a pyGame app, to run it fullscreen on the tablet, and windowed on
>> other platforms. This does not seem possible from pyGame itself,
>
> How about taking the largest one from pygame.display.list_modes()?

Thanks Marius for the heads-up : I had toyed with that function while
exploring the pyGame API, but only on the desktop, and had found it next
to useless, at least with Windows.

I had not thought of trying it under maemo, where it returns only the
(800,480) tuple. So it might be a good "IT detector" with no additional
import or filesystem access.

> Both approaches will fail when you have a dual-head system -- you'll see
> a large combined display size (e.g. 2308x1024 for a 1024x768+1280x1024
> dual-head mode that crashes pygame when you try to switch to it). With
> gtk.gdk you can at least find the number of screens and their
> resolutions.


Hmm, I'll admit I hadn't even *thought* of such a possibility :-)
ATM it's not a problem because the app is mostly for my own use, I just
need a common code base that will adapt to the various platforms and
screens I use it on - none of which is multi-headed. But I'll keep it in
mind if/when that happens...

Thanks,
fp
  •  Reply