Detecting OS platform in Python
Nikita the Spider
NikitaTheSpider at gmail.com
Fri Jan 11 11:23:47 EST 2008
In article <mailman.457.1200021308.896.python-list at python.org>,
Mike Meyer <mwm-keyword-python.b4bdba at mired.org> wrote:
> On Thu, 10 Jan 2008 18:37:59 -0800 (PST) Devraj <devraj at gmail.com> wrote:
>
> > Hi everyone,
> >
> > My Python program needs reliably detect which Operating System its
> > being run on, infact it even needs to know which distribution of say
> > Linux its running on. The reason being its a GTK application that
> > needs to adapt itself to be a Hildon application if run on devices
> > like the N800.
>
> I don't think it can be done.
[...]
> ...trying to figure out what features you have
> available by guessing based on the platform type is generally the
> wrong way to approach this kind of problem - only in part because you
> wind up reduced to a series of heuristics to figure out the
> platform. And once you've done that, you could wind up being wrong.
>
> Generally, you're better of probing the platform to find out if it has
> the facilities you're looking for. For python, that generally means
> trying to import the modules you need, and catching failures; or
> possibly looking for attributes on modules if they adopt to the
> environment around them.
Much agreed. I just went through this with my SHM module. Compilation
was failing because of a variation in ipc_perm in ipc.h on various
platforms. I didn't feel confident at all that I could compile a list of
all of the variations let alone keep it accurate and updated. The
clincher was when I found that OS X >= 10.4 has two flavors of ipc_perm
and which gets used depends on a compile flag, so identifying the OS
would not have been useful in that case.
OP, I don't know what a Hildon or N800 is, but is it possible that the
same OS fingerprint could show up on different devices? If so then
you're really out of luck. I think you'll be much better off if you
focus less on the OS and more on the features it offers.
Good luck
--
Philip
http://NikitaTheSpider.com/
Whole-site HTML validation, link checking and more
More information about the Python-list
mailing list