PDA

View Full Version : How to know that I am on Maemo from Python


pbouda
02-05-2010, 04:54 AM
Hi,

is there a quick way to check wether I am on Maemo from within python? I used:

if os.environ.has_key("OSSO_PRODUCT_NAME"):

But this does not seem to work anymore...

Peter

pbouda
02-05-2010, 05:03 AM
Sorry, it works now... don't know what was wrong.

jaem
02-05-2010, 05:03 AM
I'm not sure about how to check for Maemo, per se, but if checking for a Hildon-based UI is sufficient (I don't know what your use-case is, so I'm just throwing it out there), there's some code in the init routines of Aarddict (http://aarddict.org) that you could lift. I'm not a Python coder myself, but I had to fiddle with that bit to get it to load the stock GTK UI on the N900, due to the fact that its Hildon routines were incompatible with the version in Maemo 5.
EDIT: I guess that wasn't what you're looking for, but I'll leave this here for reference, anyway.

fpp
02-05-2010, 05:11 AM
This could help :

import platform

http://docs.python.org/library/platform.html#module-platform

pycage
02-05-2010, 05:12 AM
You could check for the hildon library.


try:
import hildon
except:
hildon = None

...

if (hildon):
print "On Maemo"
else:
print "Not on Maemo"

qwerty12
02-05-2010, 05:14 AM
You could check for the existence of /proc/component_version. As a bonus, that file also contains the product code of the Maemo-running device.

jaem
02-05-2010, 05:34 AM
You could check for the hildon library.
I'm pretty sure that's the code I was thinking of, only, not being a Python coder, I couldn't think of the syntax off the top of my head. Thanks! As I pointed out, though, this checks for Hildon - not a specific Maemo device, or even Maemo itself. So if the OP is using platform/device-specific features, they'll need to do it some other way.

zwer
02-05-2010, 07:00 AM
Or the most fail-safe way - use system call to grab the output from uname -a command. It will also give you the most data, too.

thp
02-05-2010, 07:07 AM
BTW: Hildon is available on e.g. Ubuntu as well, so just checking for hildon might not be enough evidence that you are really running on Maemo. qwerty12's solution of checking for /proc/component_version seems to be a more reliable check.

fpp
02-05-2010, 07:14 AM
Or the most fail-safe way - use system call to grab the output from uname -a command. It will also give you the most data, too.

This is what the 'platform' module gives you, among other things. Part of the returned values is 'Nokia-N900-42-11', which is pretty precise IMHO...

thp
02-05-2010, 07:18 AM
This is what the 'platform' module gives you, among other things. Part of the returned values is 'Nokia-N900-42-11', which is pretty precise IMHO...

That's the hostname. I changed this on the device I have, so it's also not that reliable (uname -a gives "Linux poodonkis 2.6.28-omap1 #1 PREEMPT Thu Dec 17 09:40:52 EET 2009 armv7l unknown" here).

thp
02-05-2010, 07:21 AM
Another data point that might be a bit more reliable: The "Hardware" field in /proc/cpuinfo:

Processor : ARMv7 Processor rev 3 (v7l)
BogoMIPS : 249.96
Features : swp half thumb fastmult vfp edsp neon vfpv3
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x1
CPU part : 0xc08
CPU revision : 3

Hardware : Nokia RX-51 board
Revision : 2101
Serial : 0000000000000000

pycage
02-05-2010, 08:48 AM
This doesn't work on scratchbox, though, which is Maemo, too.

qwerty12
02-05-2010, 09:09 AM
This doesn't work on scratchbox, though, which is Maemo, too.

You'll be happy to know that the Nokia method for checking if one of their programs is running in Scratchbox is to check for the existence of the /scratchbox directory.

pycage
02-05-2010, 09:12 AM
You'll be happy to know that the Nokia method for checking if one of their programs is running in Scratchbox is to check for the existence of the /scratchbox directory.

Huh? /scratchbox exists on my Linux box, too, because I have scratchbox installed on it. Having /scratchbox doesn't mean that you're running in scratchbox, actually.

qwerty12
02-05-2010, 09:17 AM
Huh? /scratchbox exists on my Linux box, too, because I have scratchbox installed on it. Having /scratchbox doesn't mean that you're running in scratchbox, actually.

No point debating it with me (I did say "Nokia method") . If I'm not mistaken, this can be evidenced in some of Diablo's osso-af-init and init.d scripts.
Infact, someone accidently broke the Diablo browser on the N8x0 by having their package create a /scratchbox directory. Upon the next reboot, browserd thought it was running in Scratchbox.

thp
02-05-2010, 09:38 AM
Check if X's resolution is 800x480? ;)

zwer
02-05-2010, 09:45 AM
Do a screengrab on X and then analyze it to definitely conclude if it's running on a Maemo device? ;)