Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Vinet <vince.vinet@gmail.com>2009-04-16 12:48:36 (GMT)
committer Jean-Christophe Savard <savard.jean.christophe@gmail.com>2009-04-16 19:09:39 (GMT)
commit8048909edb0023e2b9788fdc1605263d9bc22a1b (patch)
tree683135e15311dfd3fad6f3afc7e38beac65e6ae8
parentc316d9396fb3d6243e14a482b33d652934d7a173 (diff)
Various fixes in bundler
-rw-r--r--src/sugar/tutorius/bundler.py129
1 files changed, 65 insertions, 64 deletions
diff --git a/src/sugar/tutorius/bundler.py b/src/sugar/tutorius/bundler.py
index fc25b7a..d656f1f 100644
--- a/src/sugar/tutorius/bundler.py
+++ b/src/sugar/tutorius/bundler.py
@@ -28,7 +28,18 @@ from sugar.tutorius import gtkutils, overlayer
from sugar.tutorius.core import Tutorial, State, FiniteStateMachine
from sugar.tutorius.actions import DialogMessage, OnceWrapper, BubbleMessage
from sugar.tutorius.filters import GtkWidgetEventFilter, TimerEvent
-from ConfigParser import SaveConfigParser
+from ConfigParser import SafeConfigParser
+
+def __get_store_root():
+ return os.path.join(os.getenv("SUGAR_PREFIX"),"share","tutorius","data")
+def __get_bundle_root():
+ return os.path.join(os.getenv("SUGAR_BUNDLE_PATH"),"data","tutorius","data")
+
+INI_ACTIVITY_SECTION = "RELATED_ACTIVITIES"
+INI_METADATA_SECTION = "GENERAL_METADATA"
+INI_GUID_PROPERTY = "GUID"
+INI_NAME_PROPERTY = "NAME"
+INI_XML_FSM_PROPERTY = "FSM_FILENAME"
class TutorialStore:
@@ -38,20 +49,20 @@ class TutorialStore:
given activity.
"""
- TUT_STORE_ROOT = os.getenv("$SUGAR_PREFIX") + "/share/tutorius/Data"
- TUT_BUNDLE_ROOT = os.getenv("$SUGAR_BUNDLE_PATH") + "/data/tutorius/Data"
+ store_root = __get_store_root()
+ bundle_root = __get_bundle_root()
- logging.debug("*********** Path of TUT_STORE_ROOT : " + TUT_STORE_ROOT)
+ logging.debug("*********** Path of store_root : " + store_root)
# Create /data/tutorius if no exists
- if not os.path.exists(TUT_STORE_ROOT):
- os.mkdir(TUT_STORE_ROOT)
- logging.debug("************* Creating /data/tutorius folder")
+ if not os.path.exists(store_root):
+ os.mkdir(store_root)
+ logging.debug("************* Creating %s folder" % store_root)
tutoGuidName = {}
- # iterate for each ".ini" file in the activity TUT_STORE_ROOT folder
- for file_name in os.listdir(TUT_STORE_ROOT):
+ # iterate for each ".ini" file in the activity store_root folder
+ for file_name in os.listdir(store_root):
if file_name.endswith(".ini"):
logging.debug("************** .ini file found : " + file_name)
@@ -94,10 +105,10 @@ class Serializer:
def save_fsm(self,fsm, guid = None):
"""
Save fsm to disk. If a GUID parameter is provided, the existing GUID is
- located in the .ini files in TUT_STORRE_ROOT and TUT_BUNDLE_ROOT and
+ located in the .ini files in the store root and bundle root and
the corresponding FSM is/are overwritten. If the GUId is not found, an
exception occur. If no GUID is provided, FSM is written in a new file
- in TUT_STORE_ROOT.
+ in the store root.
"""
NotImplementedError
@@ -162,11 +173,6 @@ class TutorialBundler:
editor.
"""
- INI_ACTIVITY_SECTION = "RELATED_ACTIVITIES"
- INI_METADATA_SECTION = "GENERAL_METADATA"
- INI_GUID_PROPERTY = "GUID"
- INI_NAME_PROPERTY = "NAME"
- INI_XML_FSM_PROPERTY = "FSM_FILENAME"
def __init__(self,generated_guid = None):
@@ -176,41 +182,36 @@ class TutorialBundler:
Tutorial_bundler object will be associated with it. If no GUID is given,
a new GUID will be generated,
"""
+ self.__guid = generated_guid or uuid.uuid1()
- def __SetGuid(self, value):
- self.__guid = value
-
- def __GetGuid(self):
- return self.__guid
-
- def __DelGuid(self):
- del self.__guid
-
- def __SetPath(self, value):
- self.__path = value
-
- def __GetPath(self):
- return self.__path
-
- def __DelPath(self):
- del self.__path
-
- Guid = property(fget=__SetGuid,
- fset=__GetGuid,
- fdel=__DelGuid,
- doc="The guid associated with the Tutoria_Bundler")
-
- Path = property(fget=__SetPath,
- fset=__GetPath,
- fdel=__DelPath,
- doc="The path associated with the Tutoria_Bundler")
+ def __SetGuid(self, value):
+ self.__guid = value
+
+ def __GetGuid(self):
+ return self.__guid
+
+ def __DelGuid(self):
+ del self.__guid
+
+ def __SetPath(self, value):
+ self.__path = value
- if generated_gui is not None:
- self.Guid = generated_guid
- else:
- self.Guid = uuid.uuid1()
+ def __GetPath(self):
+ return self.__path
+
+ def __DelPath(self):
+ del self.__path
+
+ Guid = property(fget=__SetGuid,
+ fset=__GetGuid,
+ fdel=__DelGuid,
+ doc="The guid associated with the Tutoria_Bundler")
+
+ Path = property(fget=__SetPath,
+ fset=__GetPath,
+ fdel=__DelPath,
+ doc="The path associated with the Tutoria_Bundler")
- #TODO : GUID generation if no guid is given in entry to the constructor.
def write_metadata_file(self, data):
"""
@@ -224,21 +225,21 @@ class TutorialBundler:
"""
Return the path of the .ini file associated with the guiven guid set in
the Guid property of the Tutorial_Bundler. If the guid is present in
- more than one path, the TUT_STORE_ROOT is given priority.
+ more than one path, the store_root is given priority.
"""
- TUT_STORE_ROOT = os.getenv("$SUGAR_PREFIX") + "/share/tutorius/Data"
- TUT_BUNDLE_ROOT = os.getenv("$SUGAR_BUNDLE_PATH") + "/data/tutorius/Data"
+ store_root = __get_store_root()
+ bundle_root = __get_bundle_root()
config = SafeConfigParser()
path = None
- logging.debug("************ Path of TUT_STORE_ROOT folder of activity : " \
- + TUT_STORE_ROOT)
+ logging.debug("************ Path of store_root folder of activity : " \
+ + store_root)
- # iterate for each .ini file in the TUT_STORE_ROOT folder
+ # iterate for each .ini file in the store_root folder
- for file_name in os.listdir(TUT_STORE_ROOT):
+ for file_name in os.listdir(store_root):
if file_name.endswith(".ini"):
logging.debug("******************* Found .ini file : " \
+ file_name)
@@ -247,20 +248,20 @@ class TutorialBundler:
xml_filename = config.get(INI_METADATA_SECTION,
INI_XML_FSM_PROPERTY)
- path = TUT_STORE_ROOT + "/" + self.Guid
+ path = os.path.join(store_root, self.Guid)
return path
- logging.debug("************ Path of TUT_BUNDLE_ROOT folder of activity : " \
- + TUT_BUNDLE_ROOT)
+ logging.debug("************ Path of bundle_root folder of activity : " \
+ + bundle_root)
- # iterate for each .ini file in the TUT_BUNDLE_ROOT folder
- for file_name in os.listdir(TUT_BUNDLE_ROOT):
+ # iterate for each .ini file in the bundle_root folder
+ for file_name in os.listdir(bundle_root):
if file_name.endswith(".ini"):
logging.debug("******************* Found .ini file : " \
+ file_name)
config.read(file_name)
if config.get(INI_METADATA_SECTION, INI_GUID_PROPERTY) == guid:
- path = TUT_BUNDLE_ROOT + "/" + self.Guid
+ path = os.path.join(bundle_root, self.Guid)
return path
if path is None:
@@ -271,7 +272,7 @@ class TutorialBundler:
"""
Save fsm to disk. If a GUID parameter is provided, the existing GUID is
- located in the .ini files in TUT_STORRE_ROOT and TUT_BUNDLE_ROOT and
+ located in the .ini files in the store root and bundle root and
the corresponding FSM is/are created or overwritten. If the GUID is not
found, an exception occur.
"""
@@ -282,11 +283,11 @@ class TutorialBundler:
path = get_tutorial_path() + "/meta.ini"
config.read(path)
xml_filename = config.get(INI_METADATA_SECTION, INI_XML_FSM_PROPERTY)
- save_fsm(fsm, xml_filename, TUT_STORE_ROOT)
+ save_fsm(fsm, xml_filename, store_root)
def add_resources(self, typename, file):
"""
Add ressources to metadata.
"""
- NotImplementedError \ No newline at end of file
+ raise NotImplementedError("add_resources not implemented")