From c5fa4dfd5960c9d3275a7507bc340a872d494fce Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Mon, 16 May 2016 23:36:01 -0500 Subject: [PATCH 1/2] Fix regression for GTK2 activities caused by 2f2b2d2 The issue was caused by importing from activityfactory which caused GObject to be imported. This conflicts with GTK2. (Reported by James Cameron) The idea is that we should create the sugar profile's activity root if it doesn't exist yet, when running outside Sugar. --- bin/sugar-activity | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/bin/sugar-activity b/bin/sugar-activity index 12809b10..9f1ba97b 100755 --- a/bin/sugar-activity +++ b/bin/sugar-activity @@ -35,11 +35,12 @@ DBusGMainLoop(set_as_default=True) from sugar3.activity import activityhandle from sugar3 import config from sugar3.bundle.activitybundle import ActivityBundle -from sugar3.activity.activityfactory import get_environment from sugar3 import logger from sugar3.bundle.bundle import MalformedBundleException +from distutils.dir_util import mkpath + def create_activity_instance(constructor, handle): activity = constructor(handle) activity.show() @@ -124,7 +125,22 @@ def main(): activity_class = bundle.get_command().split(" ")[1] if 'SUGAR_VERSION' not in os.environ: - environ = get_environment(bundle) + profile_id = os.environ.get('SUGAR_PROFILE', 'default') + home_dir = os.environ.get('SUGAR_HOME', os.path.expanduser('~/.sugar')) + base = os.path.join(home_dir, profile_id) + activity_root = os.path.join(base, bundle.get_bundle_id()) + + instance_dir = os.path.join(activity_root, 'instance') + mkpath(instance_dir) + + data_dir = os.path.join(activity_root, 'data') + mkpath(data_dir) + + tmp_dir = os.path.join(activity_root, 'tmp') + mkpath(tmp_dir) + + os.environ['SUGAR_ACTIVITY_ROOT'] = activity_root + os.environ['SUGAR_BUNDLE_PATH'] = bundle.get_path() os.environ['SUGAR_BUNDLE_ID'] = bundle.get_bundle_id() os.environ['SUGAR_BUNDLE_NAME'] = bundle.get_name() From a462f14c55dac67ce4572c42fc9f444a1b3625fa Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Tue, 17 May 2016 03:50:09 -0500 Subject: [PATCH 2/2] Properly make a random activity_id outside Sugar. --- bin/sugar-activity | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bin/sugar-activity b/bin/sugar-activity index 9f1ba97b..bda69754 100755 --- a/bin/sugar-activity +++ b/bin/sugar-activity @@ -40,6 +40,9 @@ from sugar3 import logger from sugar3.bundle.bundle import MalformedBundleException from distutils.dir_util import mkpath +import time +import hashlib +import random def create_activity_instance(constructor, handle): activity = constructor(handle) @@ -165,7 +168,10 @@ def main(): activity_constructor = getattr(module, class_name) if not options.activity_id: - options.activity_id = bundle.get_name() + # Generate random hash + data = '%s%s' % (time.time(), random.randint(10000, 100000)) + random_hash = hashlib.sha1(data).hexdigest() + options.activity_id = random_hash options.bundle_id = bundle.get_bundle_id() activity_handle = activityhandle.ActivityHandle(