Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar/tutorius
diff options
context:
space:
mode:
authorJean-Christophe Savard <savard.jean.christophe@gmail.com>2009-04-16 15:18:36 (GMT)
committer Jean-Christophe Savard <savard.jean.christophe@gmail.com>2009-04-16 15:18:36 (GMT)
commitd2a771ba52c1376fd43e18c7924b51ebf17696f0 (patch)
treea50215d4eda3a19019ef3259569747093f04fb36 /src/sugar/tutorius
parent53d84425869acd2b5e151aae3cb72a15c97b7437 (diff)
Bundler.py
Diffstat (limited to 'src/sugar/tutorius')
-rw-r--r--src/sugar/tutorius/bundler.py116
1 files changed, 64 insertions, 52 deletions
diff --git a/src/sugar/tutorius/bundler.py b/src/sugar/tutorius/bundler.py
index 4f25d8c..2026fb3 100644
--- a/src/sugar/tutorius/bundler.py
+++ b/src/sugar/tutorius/bundler.py
@@ -23,6 +23,7 @@ This module contains all the data handling class of Tutorius
import logging
import os
import uuid
+import xml.dom.minidom
from sugar.tutorius import gtkutils, overlayer
from sugar.tutorius.core import Tutorial, State, FiniteStateMachine
@@ -60,39 +61,32 @@ class TutorialStore:
logging.debug("************* Creating %s folder" % store_root)
tutoGuidName = {}
-
- # 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)
- # Filter for just .ini files who metadata ACTIVITY_NAME
- # match 'activity_name' given in argument.
- config = SafeConfigParser()
- config.read(file_name)
- # Get all activity tuples (Activity_Name: Activity_Version)
- file_activity_tuples = config.items(INI_ACTIVITY_SECTION)
+
+ # iterate in each GUID subfolder
+ for dir in os.listdir(store_root):
+ # iterate for each ".ini" file in the activity store_root folder
+ for file_name in os.listdir(store_root + "/" + dir):
- for i in range(0, len(file_activity_tuples) - 1):
+ if file_name.endswith(".ini"):
+ logging.debug("************** .ini file found : " + file_name)
+ # Filter for just .ini files who metadata ACTIVITY_NAME
+ # match 'activity_name' given in argument.
+ config = SafeConfigParser()
+ config.read(file_name)
+ # Get all activity tuples (Activity_Name: Activity_Version)
+ file_activity_tuples = config.items(INI_ACTIVITY_SECTION)
- if file_activity_tuples[i][0] == activity_name and \
- int(file_activity_tuples[i][1]) == activity_vers:
- # Add this tutorial guid and name in the dictionary
- file_activity_guid = config.get(INI_METADATA_SECTION,
- INI_GUID_PROPERTY)
- file_activity_name = config.get(INI_METADATA_SECTION,
- INI_NAME_PROPERTY)
- tutoGuidName[file_activity_name] = file_activity_guid
-
-## # Get the key line (always 1st line of .tml file)
-## key_line = linecache.getline(path + file_name, 1)
-## key_line = key_line.split("\n")[0]`
-## # Get the name line (always 2nd line of .tml file)
-## name_line = linecache.getline(path + file_name, 2)
-## name_line = name_line.split("\n")[0]
-## # Create dictionary
-## tutoKeyName[key_line.split("--KEY::")[1]] = \
-## name_line.split("--NAME::")[1]
+ for i in range(0, len(file_activity_tuples) - 1):
+
+ if file_activity_tuples[i][0] == activity_name and \
+ int(file_activity_tuples[i][1]) == activity_vers:
+ # Add this tutorial guid and name in the dictionary
+ file_activity_guid = config.get(INI_METADATA_SECTION,
+ INI_GUID_PROPERTY)
+ file_activity_name = config.get(INI_METADATA_SECTION,
+ INI_NAME_PROPERTY)
+ tutoGuidName[file_activity_name] = file_activity_guid
+
return tutoGuidName
@@ -124,11 +118,22 @@ class XMLSerializer(Serializer):
used in the tutorials to/from a .xml file. Inherit from Serializer
"""
+
+
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)
+
+
+ _element = doc.createElementNS("http://tutorius.org", "fsm")
+ tutorial_element.appendChild(fsm_element)
## logging.debug("************ found .tml file : " + file_name)
@@ -238,32 +243,39 @@ class TutorialBundler:
logging.debug("************ Path of store_root folder of activity : " \
+ store_root)
- # iterate for each .ini file in the store_root folder
+ # iterate in each GUID subfolder
+ for dir in os.listdir(store_root):
+
+ # iterate for each .ini file in the store_root folder
+
+ for file_name in os.listdir(store_root + "/" + dir):
+ 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) == self.Guid:
+ xml_filename = config.get(INI_METADATA_SECTION,
+ INI_XML_FSM_PROPERTY)
- for file_name in os.listdir(store_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) == self.Guid:
- xml_filename = config.get(INI_METADATA_SECTION,
- INI_XML_FSM_PROPERTY)
-
- path = os.path.join(store_root, self.Guid)
- return path
+ path = os.path.join(store_root, self.Guid)
+ return path
logging.debug("************ Path of bundle_root folder of activity : " \
+ 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 = os.path.join(bundle_root, self.Guid)
- return path
+
+ # iterate in each GUID subfolder
+ for dir in os.listdir(bundle_root):
+
+ # iterate for each .ini file in the bundle_root folder
+ for file_name in os.listdir(bundle_root + "/" + dir):
+ 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 = os.path.join(bundle_root, self.Guid)
+ return path
if path is None:
logging.debug("**************** Error : GUID not found")