[Sugar-devel] [PATCH sugar 2/2] sugar-install-bundle: skip older bundles by default, accept multiple bundles

Sascha Silbe silbe at activitycentral.com
Mon Sep 5 06:10:34 EDT 2011

If the user has already installed a newer version of an activity,
sugar-install-bundle shouldn't overwrite it. Since there might be cases where
this is still useful we provide an option to force installing the bundle even
if it's the same or even an older version.

The changes necessary to parse the CLI options also add back the support for
installing multiple bundles in one invocation.

Signed-off-by: Sascha Silbe <silbe at activitycentral.com>
 bin/sugar-install-bundle |   34 +++++++++++++++++++++++-----------
 1 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/bin/sugar-install-bundle b/bin/sugar-install-bundle
index d0b6fc5..47b0084 100644
--- a/bin/sugar-install-bundle
+++ b/bin/sugar-install-bundle
@@ -1,17 +1,26 @@
 #!/usr/bin/env python
 import gettext
+from optparse import OptionParser
 import sys
 from sugar.bundle.activitybundle import ActivityBundle
+from sugar.bundle.bundle import AlreadyInstalledException
 from jarabe import config
+from jarabe.model import bundleregistry
 from dbus.mainloop.glib import DBusGMainLoop
-def cmd_help():
-    print _('Usage: sugar-install-bundle [ bundlename ] \n\n'
-            'Install an activity bundle (.xo). \n')
+def install_bundle(name, force):
+    bundle = ActivityBundle(name)
+    registry = bundleregistry.get_registry()
+    try:
+        registry.install(bundle, force_downgrade=force)
+    except AlreadyInstalledException:
+        print _("%s: %r or newer is already installed") % (sys.argv[0], name)
+    else:
+        print _('%s: %r installed.') % (sys.argv[0], name)
 gettext.bindtextdomain('sugar', config.locale_path)
@@ -19,13 +28,16 @@ gettext.bindtextdomain('sugar-toolkit', config.locale_path)
 _ = gettext.gettext
-if len(sys.argv) != 2:
-    cmd_help()
-    sys.exit(2)
+parser = OptionParser(usage=_('usage: %prog [options] {bundle}'),
+                      description=_('Install an activity bundle (.xo)'))
+parser.add_option('-f', '--force', dest='force',
+                  help=_("Install bundle even if it isn't newer than"
+                         " what's currently installed"),
+                  action='store_true', default=False)
+options, args = parser.parse_args()
+if not args:
+    parser.error(_('no bundle given'))
-bundle = ActivityBundle(sys.argv[1])
-print _('%s: %r installed.') % (sys.argv[0], sys.argv[1])
+for file_name in args:
+    install_bundle(file_name, options.force)

More information about the Sugar-devel mailing list