From f02b9202add548f259f4d05b7edb2d39a9206b2a Mon Sep 17 00:00:00 2001 From: charles Date: Thu, 16 Apr 2009 15:31:35 +0000 Subject: Merge branch 'jc' of ssh://charles@bobthebuilder.mine.nu:8080/home/git into jc --- diff --git a/src/sugar/tutorius/bundler.py b/src/sugar/tutorius/bundler.py index 0db8711..74b9eac 100644 --- a/src/sugar/tutorius/bundler.py +++ b/src/sugar/tutorius/bundler.py @@ -24,6 +24,7 @@ import logging import os import shutil import uuid +import xml.dom.minidom from sugar.tutorius import gtkutils, overlayer from sugar.tutorius.core import Tutorial, State, FiniteStateMachine @@ -63,39 +64,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 @@ -127,11 +121,21 @@ 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) + fsm_element = doc. + tutorial_element.appendChild(fsm_element) + ## logging.debug("************ found .tml file : " + file_name) ## key_line = linecache.getline(path + file_name, 1) @@ -267,32 +271,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") -- cgit v0.9.1