From be91f84a4bf87fa138a20f5b15e8c906b7aa4774 Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Sat, 29 Jun 2013 09:10:32 -0600 Subject: [PATCH] Avoid auto-import of bundle helpers (#4527) The new bundle helpers were being auto-loaded with sugar3.bundle due to their placement in __init__.py. This was causing Gi to be imported, breaking GTK2 activity launches. Move the helpers to a dedicated module. --- src/sugar3/bundle/Makefile.am | 3 ++- src/sugar3/bundle/__init__.py | 34 ------------------------ src/sugar3/bundle/helpers.py | 50 +++++++++++++++++++++++++++++++++++ tests/test_bundle.py | 2 +- 4 files changed, 53 insertions(+), 36 deletions(-) create mode 100644 src/sugar3/bundle/helpers.py diff --git a/src/sugar3/bundle/Makefile.am b/src/sugar3/bundle/Makefile.am index 50b56812..616c3ed4 100644 --- a/src/sugar3/bundle/Makefile.am +++ b/src/sugar3/bundle/Makefile.am @@ -4,4 +4,5 @@ sugar_PYTHON = \ bundle.py \ activitybundle.py \ bundleversion.py \ - contentbundle.py + contentbundle.py \ + helpers.py diff --git a/src/sugar3/bundle/__init__.py b/src/sugar3/bundle/__init__.py index d0237931..85ebcede 100644 --- a/src/sugar3/bundle/__init__.py +++ b/src/sugar3/bundle/__init__.py @@ -14,37 +14,3 @@ # License along with this library; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. - -import os - -from gi.repository import Gio - -from sugar3.bundle.activitybundle import ActivityBundle -from sugar3.bundle.contentbundle import ContentBundle - - -def bundle_from_archive(path, mime_type=None): - """ - Return an appropriate Bundle object for a given file path. - The bundle type is identified by mime_type, which is guessed if not - provided. - """ - if mime_type is None: - mime_type, certainty = Gio.content_type_guess(path, data=None) - if mime_type == ActivityBundle.MIME_TYPE: - return ActivityBundle(path) - elif mime_type == ContentBundle.MIME_TYPE: - return ContentBundle(path) - return None - - -def bundle_from_dir(path): - """ - Return an appropriate Bundle object for a given directory containing - an unzipped bundle. - """ - if os.path.exists(os.path.join(path, 'activity', 'activity.info')): - return ActivityBundle(path) - elif os.path.exists(os.path.join(path, 'library', 'library.info')): - return ContentBundle(path) - return None diff --git a/src/sugar3/bundle/helpers.py b/src/sugar3/bundle/helpers.py new file mode 100644 index 00000000..8be78c0b --- /dev/null +++ b/src/sugar3/bundle/helpers.py @@ -0,0 +1,50 @@ +# Copyright (C) 2013 One Laptop per Child +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +import os + +from gi.repository import Gio + +from sugar3.bundle.activitybundle import ActivityBundle +from sugar3.bundle.contentbundle import ContentBundle + + +def bundle_from_archive(path, mime_type=None): + """ + Return an appropriate Bundle object for a given file path. + The bundle type is identified by mime_type, which is guessed if not + provided. + """ + if mime_type is None: + mime_type, certainty = Gio.content_type_guess(path, data=None) + if mime_type == ActivityBundle.MIME_TYPE: + return ActivityBundle(path) + elif mime_type == ContentBundle.MIME_TYPE: + return ContentBundle(path) + return None + + +def bundle_from_dir(path): + """ + Return an appropriate Bundle object for a given directory containing + an unzipped bundle. + """ + if os.path.exists(os.path.join(path, 'activity', 'activity.info')): + return ActivityBundle(path) + elif os.path.exists(os.path.join(path, 'library', 'library.info')): + return ContentBundle(path) + return None diff --git a/tests/test_bundle.py b/tests/test_bundle.py index 45257fe6..9d343d20 100644 --- a/tests/test_bundle.py +++ b/tests/test_bundle.py @@ -18,7 +18,7 @@ import os import unittest import subprocess -from sugar3.bundle import bundle_from_dir, bundle_from_archive +from sugar3.bundle.helpers import bundle_from_dir, bundle_from_archive from sugar3.bundle.activitybundle import ActivityBundle from sugar3.bundle.contentbundle import ContentBundle