From ea1ab3e176b39b264b6ce6e375f8999708bfaa62 Mon Sep 17 00:00:00 2001 From: Vincent Vinet Date: Thu, 16 Apr 2009 15:23:00 +0000 Subject: add write_metadata_file implementation --- (limited to 'src') diff --git a/src/sugar/tutorius/bundler.py b/src/sugar/tutorius/bundler.py index 2026fb3..6bd92a2 100644 --- a/src/sugar/tutorius/bundler.py +++ b/src/sugar/tutorius/bundler.py @@ -41,6 +41,8 @@ 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: @@ -183,12 +185,31 @@ class TutorialBundler: 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() + self.Guid = generated_guid or uuid.uuid1() + + #Look for the file in the path if a uid is supplied + if generated_guid: + #General store + store_path = os.path.join(__get_store_root(), generated_guid, INI_FILENAME) + if os.path.isfile(store_path): + self.Path = os.path.dirname(store_path) + else: + #Bundle store + bundle_path = os.path.join(__get_bundle_root(), generated_guid, INI_FILENAME) + if os.path.isfile(bundle_path): + self.Path = os.path.dirname(bundle_path) + else: + 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 @@ -211,22 +232,30 @@ class TutorialBundler: Guid = property(fget=__SetGuid, fset=__GetGuid, fdel=__DelGuid, - doc="The guid associated with the Tutoria_Bundler") + doc="The guid associated with the Tutorial_Bundler") Path = property(fget=__SetPath, fset=__GetPath, fdel=__DelPath, - doc="The path associated with the Tutoria_Bundler") + doc="The path associated with the Tutorial_Bundler") - def write_metadata_file(self, data): + def write_metadata_file(self, tutorial): """ - 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. + Write metadata to the property file. + @param tutorial Tutorial for which to write metadata """ - NotImplementedError - + #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) ) ) + def get_tutorial_path(self): """ Return the path of the .ini file associated with the guiven guid set in -- cgit v0.9.1