Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar
diff options
context:
space:
mode:
authorVincent Vinet <vince.vinet@gmail.com>2009-04-16 15:23:00 (GMT)
committer Jean-Christophe Savard <savard.jean.christophe@gmail.com>2009-04-16 19:09:44 (GMT)
commitea1ab3e176b39b264b6ce6e375f8999708bfaa62 (patch)
tree85214df16d7f9848f2e83fb168631282d909b618 /src/sugar
parent36ec0dd4afb4046624cc1e1df529b54a3b4e0a7f (diff)
add write_metadata_file implementation
Diffstat (limited to 'src/sugar')
-rw-r--r--src/sugar/tutorius/bundler.py49
1 files changed, 39 insertions, 10 deletions
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