Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius/vault.py
diff options
context:
space:
mode:
authorJCTutorius <charlie@tutorius-dev.(none)>2009-11-05 23:01:32 (GMT)
committer JCTutorius <charlie@tutorius-dev.(none)>2009-11-05 23:01:32 (GMT)
commitd667a0a9b02f9768c8b80ce0717ddc05d1cd1e2b (patch)
treebbf6cc2be8fa8b984499f374efe50ece848218d6 /tutorius/vault.py
parentb30a273d6d2926fb404a1e87d9e31e6ef62d0d5f (diff)
Middle of ciding update_metatdata
Diffstat (limited to 'tutorius/vault.py')
-rw-r--r--tutorius/vault.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/tutorius/vault.py b/tutorius/vault.py
index 7ec0a23..e0554f1 100644
--- a/tutorius/vault.py
+++ b/tutorius/vault.py
@@ -342,6 +342,80 @@ class Vault(object):
else:
return False
+
+ @staticmethod
+ def update_metadata(guid, metadata_dict):
+ """
+ Modify the metadata of given tutorial found whit his guid.
+ @params guid of the tutorial to update the metadata.
+ @params metadata_dict the new metadata to update from
+ """
+
+ bundle = TutorialBundler(guid)
+ bundle_path = bundle.get_tutorial_path(guid)
+ # Create the metadata file
+ ini_file_path = os.path.join(tutorial_path, "meta.ini")
+ parser = SafeConfigParser()
+ parser.add_section(INI_METADATA_SECTION)
+ for key, value in metadata_dict.items():
+ if key != 'activities':
+ parser.set(INI_METADATA_SECTION, key, value)
+ else:
+ related_activities_dict = value
+ parser.add_section(INI_ACTIVITY_SECTION)
+ for related_key, related_value in related_activities_dict.items():
+ parser.set(INI_ACTIVITY_SECTION, related_key, related_value)
+
+ # Delete the old metadata file
+ if os.path.isfile(ini_file_path):
+ os.remove(ini_file_path)
+
+ # Write the new metadata file to disk
+ with open(ini_file_path, 'wb') as configfile:
+ parser.write(configfile)
+
+ if os.path.isfile(ini_file_path):
+ return True
+ else:
+ return False
+
+
+ @staticmethod
+ def get_tutorial_archive(guid):
+ """
+ Zip the files of the tutorial indentified with is guid and returns it.
+ @params guid the guid of the tutorial to zip
+ @returns a zip archive containing the files of the tutorial
+ """
+ bundle = TutorialBundler(guid)
+ bundle_path = bundle.get_tutorial_path(guid)
+
+ #Zip the tutorials files in the pkzip file format in a temp file
+ archive_list = [os.path.join(bundle_path, 'meta.ini'), os.path.join(bundle_path, 'tutorial.xml')] #, os.path.join(bundle_path, RESOURCES_FOLDER)]
+
+ zfilename = str(guid) + ".zip"
+
+ zout = zipfile.ZipFile(os.path.join(bundle_path, zfilename), "w")
+ for fname in archive_list:
+ fname_splitted = fname.rsplit('/')
+ file_only_name = fname_splitted[fname_splitted.__len__() - 1]
+ zout.write(fname, file_only_name)
+ zout.close()
+
+ # test if the temp file is a valid pkzip file
+ assert zipfile.is_zipfile(os.path.join(bundle_path, zfilename)) == True, "The zipping of the tutorial files failed."
+
+ # open the temp archive file in read mode
+ zin = open(os.path.join(bundle_path, zfilename), "r")
+ archive_data = zin.read()
+ zin.close()
+
+ # delete temp file
+ os.remove(os.path.join(bundle_path, zfilename))
+
+ # return zip object data
+ return archive_data
+
@staticmethod
def add_resource(tutorial_guid, file_path):