Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Silbe <silbe@activitycentral.com>2011-09-05 15:10:34 (GMT)
committer Anish Mangal <anish@activitycentral.com>2012-02-01 12:33:31 (GMT)
commit4f1696b6a4753ebb2700f4ff136d92a65fe8263c (patch)
tree736826b782dc77de721bb6f0cff444bf074521ed
parent3d70833c969ed9a4375a0f9348c3b356443beb4e (diff)
sugar-install-bundle: skip older bundles by default, accept multiple bundles
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@activitycentral.com> Reviewed-by: James Cameron <quozl@laptop.org>
-rw-r--r--bin/sugar-install-bundle34
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.textdomain('sugar')
_ = 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'))
DBusGMainLoop(set_as_default=True)
-
-bundle = ActivityBundle(sys.argv[1])
-bundle.install()
-
-print _('%s: %r installed.') % (sys.argv[0], sys.argv[1])
+for file_name in args:
+ install_bundle(file_name, options.force)