From 53d84425869acd2b5e151aae3cb72a15c97b7437 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Savard Date: Thu, 16 Apr 2009 13:00:37 +0000 Subject: Merge branch 'jc' of ssh://bobthebuilder.mine.nu:8080/home/git into jc --- diff --git a/src/sugar/tutorius/bundler.py b/src/sugar/tutorius/bundler.py index 5ece68c..4f25d8c 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 @@ -163,11 +174,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): @@ -177,41 +183,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): """ @@ -225,21 +226,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) @@ -248,20 +249,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: @@ -272,7 +273,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. """ @@ -283,11 +284,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") -- cgit v0.9.1