[Sugar-devel] writing activities for all sugars

Tomeu Vizoso tomeu
Wed Nov 26 05:50:54 EST 2008


Hi Erik, sorry about the late reply.

On Fri, Nov 21, 2008 at 10:48 PM, Erik Blankinship <erikb at mediamods.com> wrote:
> The recently updated Map activity is tailored for the g1g1 xo.
>
> Is there a way (and a guide) for how to write activities which can adapt
> themselves for whichever hardware, emulator (jhbuild), distribution, build
> number, and/or sugar os they are running on?  It would be useful if activity
> authors could query this information.  The alternative seems to be bundling
> activities for every variant.

Python is a dynamic language, so there's a rich runtime you can query
to check for capabilities. While in C you would use ifdefs to include
some code that depends on a specific version of a dependency, in
python is recommend to directly check for that capability's presence.

As an example, instead of:

if sugar.version >= 0.82:
    keyHash = util.sha_data(key)
else:
    keyHash = util._sha_data(key)

you would code:

if hasattr(util, 'sha_data'):
    keyHash = util.sha_data(key)
else:
    keyHash = util._sha_data(key)

Have pasted this in
http://sugarlabs.org/go/DevelopmentTeam/Activities/Compatibility with
the hope it can be a start for such info.

About #1657, I'm not sure, any ideas?

Thanks,

Tomeu

> For example, here are two bugs we've encountered in making a "write once,
> run anywhere" sugar activity:
>
> Bug one:
> trac #1657 (scaling within an embedded browser component)
>
> Bug two:
> #joyride ...
> #keyHash = util.sha_data(key)
> #8.2...
> keyHash = util._sha_data(key)
>
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
>
>




More information about the Sugar-devel mailing list