Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Christophe Savard <savard.jean.christophe@gmail.com>2009-04-16 18:57:52 (GMT)
committer Jean-Christophe Savard <savard.jean.christophe@gmail.com>2009-04-16 19:09:47 (GMT)
commit8bc24968b7703310c8ca52be5f5d7c2f29343530 (patch)
tree73695d95f96d7cc3498d980d7ed9d7f3e41ff85a
parenta8b23e7f46d46f13a82d2abfbe8302fc7b338fbc (diff)
bundler.py devlopment
-rw-r--r--src/sugar/tutorius/bundler.py159
1 files changed, 78 insertions, 81 deletions
diff --git a/src/sugar/tutorius/bundler.py b/src/sugar/tutorius/bundler.py
index edcf55d..74aecd1 100644
--- a/src/sugar/tutorius/bundler.py
+++ b/src/sugar/tutorius/bundler.py
@@ -27,8 +27,8 @@ import xml.dom.minidom
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
+import sugar.tutorius.actions
+import sugar.tutorius.filters
from ConfigParser import SafeConfigParser
def __get_store_root():
@@ -41,8 +41,6 @@ INI_METADATA_SECTION = "GENERAL_METADATA"
INI_GUID_PROPERTY = "GUID"
INI_NAME_PROPERTY = "NAME"
INI_XML_FSM_PROPERTY = "FSM_FILENAME"
-INI_FILENAME = "meta.ini"
-TUTORIAL_FILENAME = "tutorial.xml"
class TutorialStore:
@@ -120,39 +118,45 @@ class XMLSerializer(Serializer):
used in the tutorials to/from a .xml file. Inherit from Serializer
"""
+ def create_state_dict_node(self, state_dict, doc):
+ """
+ Create and return a xml Node from a State dictionnary.
+ """
+ statesList = doc.createElement("States")
+ for state_name, state in state_dict.items():
+ stateNode = statesList.appendChild("State")
+ stateNode.setAttribute("State:Name", state_name)
+ stateNode = stateNode.appendChild(create_action_list_node(state.action_list, doc))
+ stateNode = stateNode.appendChild(create_event_filters_node(state.event_filters, doc))
+ return statesList
-
- def save_fsm(self,fsm, xml_filename, path):
+ def create_state_dict_node(self, action_list, doc):
+ """
+ Create and return a xml Node from a Action list.
+ """
+ actionsList = doc.createElement("Actions")
+ for action in action_list:
+ actionNode = actionsList.appendChild("Action")
+ if type(action) is DialogMessage:
+ actionNode.setAttribute("Action:Message", action._message)
+
+ stateNode = stateNode.appendChild(create_action_list_node(state.action_list, doc))
+ stateNode = stateNode.appendChild(create_event_filters_node(state.event_filters, doc))
+ return stateNode
+
+ def save_fsm(self, fsm, xml_filename, path):
"""
Save fsm to disk, in the xml file specified by "xml_filename", in the
"path" folder. If the specified file dont exist, it will be created.
"""
- fsm_xml = xml.dom.minidom.Document()
- fsm_element = doc.createElementNS("http://tutorius.org", "FSM")
- fsm_xml.appendChild(fsm_element)
- fsm_element.setAttributeNS("http://tutorius.org", "fsm:Name", fsm.name)
- fsm_element.setAttributeNS("http://tutorius.org", "fsm:StartStateName", fsm.start_state_name)
- fsm_element = doc.
- tutorial_element.appendChild(fsm_element)
-
-
-## logging.debug("************ found .tml file : " + file_name)
-## key_line = linecache.getline(path + file_name, 1)
-## key_line = key_line.split("\n")[0]
-## fileKey = key_line.split("--KEY::")[1]
-## logging.debug("************ fileKey = " + fileKey)
-## if key == fileKey:
-## logging.debug("************ Key : " + key + \
-## " = fileKey : " + fileKey)
-## tml = file(path + file_name, "r")
-## str = tml.read()
-## pick = str.split("--PICKLE::")[1]
-##
-## fsm = pickle.loads(pick)
-## tuto = {key:Tutorial(key,fsm)}
-##
-## return tuto
-
+ doc = xml.dom.minidom.Document()
+ fsm_element = doc.createElement("FSM")
+ doc.appendChild(fsm_element)
+ fsm_element.setAttribute("fsm:Name", fsm.name)
+ fsm_element.setAttribute("fsm:StartStateName", fsm.start_state_name)
+ fsm_element = fsm_element.appendChild(create_state_dict_node(fsm.state_dict, doc))
+ fsm_element = fsm_element.appendChild(create_action_list_node(fsm.action_list, doc))
+
def load_fsm(self, guid):
"""
@@ -179,14 +183,14 @@ class TutorialBundler:
editor.
"""
-
-
def __init__(self,generated_guid = None):
"""
+ TODO.
Tutorial_bundler constructor. If a GUID is given in the parameter, the
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()
#Look for the file in the path if a uid is supplied
@@ -204,56 +208,49 @@ class TutorialBundler:
raise IOError(2,"Unable to locate metadata file for guid '%s'" % generated_guid)
else:
- #Create the folder, any failure will go through to the caller for now
- store_path = os.path.join(__get_store_root(), generated_guid)
- os.mkdir(store_path)
- self.Path = store_path
-
- 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 Tutorial_Bundler")
-
- Path = property(fget=__SetPath,
- fset=__GetPath,
- fdel=__DelPath,
- doc="The path associated with the Tutorial_Bundler")
-
+ #Create the folder, any failure will go through to the caller for now
+ store_path = os.path.join(__get_store_root(), generated_guid)
+ os.mkdir(store_path)
+ self.Path = store_path
+
+
+ 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 write_metadata_file(self, tutorial):
+ def write_metadata_file(self, data):
"""
- Write metadata to the property file.
- @param tutorial Tutorial for which to write metadata
+ Write metadata to a property file. If a GUID is provided, TutorialBundler
+ will try to find and overwrite the existing property file who contain the
+ given GUID, and will raise an exception if it cannot find it.
"""
- #Create the Config Object and populate it
- cfg = SafeConfigParser()
- cfg.add_section(INI_METADATA_SECTION)
- cfg.set(INI_METADATA_SECTION, INI_GUID_PROPERTY, self.Guid)
- cfg.set(INI_METADATA_SECTION, INI_NAME_PROPERTY, tutorial.name)
- cfg.set(INI_METADATA_SECTION, INI_XML_FSM_PROPERTY, TUTORIAL_FILENAME)
-
-
- #Write the ini file
- cfg.write( file( os.path.join(self.Path, INI_FILENAME) ) )
-
+ NotImplementedError
+
def get_tutorial_path(self):
"""
Return the path of the .ini file associated with the guiven guid set in