1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
From 8d4d7de12b2288827b01af64562a6a19194d5761 Mon Sep 17 00:00:00 2001
From: Sascha Silbe <silbe@activitycentral.com>
Date: Mon, 5 Sep 2011 15:10:34 +0000
Subject: [PATCH sugar 67/74] 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>
---
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.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)
--
1.7.6
|