[Sugar-devel] ObjectChooser() Issue?

James Cameron quozl at laptop.org
Sun Nov 21 19:11:50 EST 2010

On Sat, Nov 20, 2010 at 04:37:24PM -0500, Art Hunkins wrote:
> This code tests for the presence of an XO-1 (thanks originally to Walter):
>   if os.path.exists("/sys/power/olpc-pm"):
> Normally this is also a test for Sugar 0.82. I want, however, also
> to test for Sugar *upgrades* on the XO-1; I don't want the same
> result as for 0.82 (as, for example, if 0.84 is installed).

This is not a test for Sugar version.

> So, do I use the same test, or do I need some other (if so, what)?

If you need to test for Sugar version, use config.version ... which is
what "About my computer" uses:

from jarabe import config
print config.version

Test this on all the versions you support; I'm not sure if it works for
all versions.  ;-)

> (Another way of phrasing the question: is the above essentially a
> hardware or a software test?)

Checking for /sys/power/olpc-pm is a software test, however the software
component (a kernel module that is compiled into the kernel) is not
meant to be present except on XO-1 or XO-1.5.

Walter has shown a different method.

Yet another hardware detection method can be found in hw.py in the
Record activity, and here it is below:

# Copyright (C) 2010, One Laptop per Child
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

import os

def _get_dmi(node):
    path = os.path.join('/sys/class/dmi/id', node)
        return open(path).readline().strip()
        return None

def get_xo_version():
    if _get_dmi('product_name') != 'XO':
        return 0
    version = _get_dmi('product_version')
    if version == '1':
        return 1
    if version == '1.5':
        return 1.5
        return 0

James Cameron

More information about the Sugar-devel mailing list