Add bundle instantiation helpers
Add some helper functions for use by upcoming changes in the Sugar shell.
This commit is contained in:
committed by
Daniel Narvaez
parent
ad3c163023
commit
f4c1bd152a
@@ -14,3 +14,37 @@
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user