Hi all,

For a deployment without a schoolserver I needed a script to install bundles (.xo and .xol) from a USB flash drive. I wanted to use the script for initial installation of bundles, installing upgrades and reinstall by mistake erased activities. I know the option with the customization.zip, but I don't want to reboot.

To call sugar-install-bundles in a script seemed to be a good solution:

for i in ${USB_BUNDLES_DIR}/*.xo*; do
        sugar-install-bundle $i
done

But I faced to problems:
1. sugar-install-bundle doesn't support installing content/library bundles
2. sugar-install-bundle doesn't support upgrading from an old version of a bundle to a newer one

So I wrote a version of sugar-install-bundle that solves these two problems (see attachment).

It is slow, but it works.

Best regards,
Philipp
#!/usr/bin/env python
import sys
import gobject
import bitfrost.update.actutils as actutils
import bitfrost.update.actinfo as actinfo
from sugar.bundle.contentbundle import ContentBundle

from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
loop = gobject.MainLoop()
from sugar.activity.registry import get_registry
registry = get_registry()

def cmd_help():
    print 'Usage: sugar-install-bundle [ bundlename ] \n\n\
    Install an activity bundle (.xo). \n'

if len(sys.argv) != 2:
    cmd_help()
    sys.exit(2)

bundleHelper = actutils.BundleHelper(sys.argv[1])
if not bundleHelper.is_installed():
    bundleHelper.install_or_upgrade(registry)
    print "sugar-install-bundle: Installed new bundle '%s'" % (sys.argv[1])
else:
    if bundleHelper.is_activity:
        bundleVersion = bundleHelper.bundle.get_activity_version()
        installedVersion = 
registry.get_activity(bundleHelper.bundle.get_bundle_id()).version
    else:
        bundleVersion = bundleHelper.bundle.get_library_version()
        installedLibrary = ContentBundle(bundleHelper.bundle.get_root_dir())
        installedVersion = installedLibrary.get_library_version()
    if bundleVersion > installedVersion:
        bundleHelper.install_or_upgrade(registry)
        print "sugar-install-bundle: Upgraded bundle '%s' from version '%s' to 
'%s'" % \
            (sys.argv[1], installedVersion, bundleVersion)
    else:
        print "sugar-install-bundle: Bundle '%s' (version '%s') is not newer 
than " \
            "installed version '%s'" % (sys.argv[1], bundleVersion, 
installedVersion)
_______________________________________________
Devel mailing list
Devel@lists.laptop.org
http://lists.laptop.org/listinfo/devel

Reply via email to