Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <mpg@redhat.com>2007-01-27 13:31:38 (GMT)
committer Marco Pesenti Gritti <mpg@redhat.com>2007-01-27 13:31:38 (GMT)
commitfbdc1579f487b094bfe2a4368db44cbbb2c086b2 (patch)
tree7ed5df7f22cf732fa9e83b46491ad98c80aee2e1 /tools
parent204aac8658020eb9a2b0014c17012abe6ae83ab9 (diff)
parentae5f1ed2c591359f81a1392841e5f07a1ed1a5a4 (diff)
Merge branch 'master' of git+ssh://dev.laptop.org/git/sugar
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile.am3
-rwxr-xr-xtools/sugar-install-bundle56
2 files changed, 58 insertions, 1 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am
index c4cd3bb..fb3f598 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1 +1,2 @@
-bin_SCRIPTS = sugar-setup-activity
+bin_SCRIPTS = sugar-install-bundle \
+ sugar-setup-activity
diff --git a/tools/sugar-install-bundle b/tools/sugar-install-bundle
new file mode 100755
index 0000000..0945c29
--- /dev/null
+++ b/tools/sugar-install-bundle
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+import sys
+import os
+import zipfile
+import dbus
+
+from sugar import env
+
+DBUS_SERVICE = "org.laptop.Shell"
+DBUS_PATH = "/org/laptop/Shell"
+
+# We check here that all the files in the .xo are inside one only dir (bundle_root_dir).
+def get_bundle_root_dir(file_names):
+ bundle_root_dir = None
+ for file_name in file_names:
+ if not bundle_root_dir:
+ bundle_root_dir = file_name.partition('/')[0]
+ if not bundle_root_dir.endswith('.activity'):
+ raise 'Incorrect bundle.'
+ else:
+ if not file_name.startswith(bundle_root_dir):
+ raise 'Incorrect bundle.'
+
+ return bundle_root_dir
+
+bus = dbus.SessionBus()
+proxy_obj = bus.get_object(DBUS_SERVICE, DBUS_PATH)
+dbus_service = dbus.Interface(proxy_obj, DBUS_SERVICE)
+
+bundle_dir = env.get_user_activities_dir()
+
+zip_file = zipfile.ZipFile(sys.argv[1])
+file_names = zip_file.namelist()
+bundle_root_dir = get_bundle_root_dir(file_names)
+bundle_path = os.path.join(bundle_dir, bundle_root_dir)
+
+# FIXME: we need to support installing different versions of the same bundle.
+if os.path.exists(bundle_path):
+ raise IOError, 'This bundle is already installed as ' + bundle_path
+
+if os.spawnlp(os.P_WAIT, 'unzip', 'unzip', sys.argv[1], '-d', bundle_dir):
+ raise RuntimeError, 'An error occurred while extracting the .xo contents.'
+
+# notify shell of new bundle
+if not dbus_service.add_bundle(bundle_path):
+ # error, let's delete the just expanded bundle.
+ for root, dirs, files in os.walk(bundle_path, topdown=False):
+ for name in files:
+ os.remove(os.path.join(root, name))
+ for name in dirs:
+ os.rmdir(os.path.join(root, name))
+ os.rmdir(bundle_path)
+
+ raise RuntimeError, 'Bundle is not well-formed.'
+
+print "%s: '%s' installed." % (sys.argv[0], sys.argv[1])