Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJCTutorius <charlie@tutorius-dev.(none)>2009-10-23 15:11:13 (GMT)
committer JCTutorius <charlie@tutorius-dev.(none)>2009-10-23 15:11:13 (GMT)
commit229dd3d18bb47df6de058110b8e625a1cb2120eb (patch)
tree51fd43b485d2e01053cb7c9c0aae7eeb24d0d722
parent1bd3c269aaf1eaeba942f039ec00185e1f951756 (diff)
Coded the vault ressource functions, started the tests for them.
-rw-r--r--tests/vaulttests.py7
-rw-r--r--tutorius/vault.py64
2 files changed, 71 insertions, 0 deletions
diff --git a/tests/vaulttests.py b/tests/vaulttests.py
index d1d1c8d..70a81f1 100644
--- a/tests/vaulttests.py
+++ b/tests/vaulttests.py
@@ -277,6 +277,13 @@ class VaultInterfaceTest(unittest.TestCase):
# TODO : Compare the initial and reloaded metadata when vault.Query() will accept specifc argument
# (so we can specifiy that we want only the metadata for this particular tutorial
+
+ def test_add_ressource(self):
+ """
+ This test verify that the vault interface function add_ressource succesfully add ressource in the vault
+ and return the new ressource id.
+ """
+
def tearDown(self):
diff --git a/tutorius/vault.py b/tutorius/vault.py
index 9215e8d..0fdf862 100644
--- a/tutorius/vault.py
+++ b/tutorius/vault.py
@@ -320,6 +320,70 @@ class Vault(object):
else:
return False
+
+ @staticmethod
+ def add_ressource(tutorial_guid, file_path):
+ """
+ Returns a unique name for this resource composed from the original name of the file
+ and a suffix to make it unique ( ex: name_1.jpg ) and add it to the resources for the tutorial.
+ @param tutorial_guid The guid of the tutorial
+ @param file_path the fiel path of the ressource to add
+ @returns the ressource_id of the ressource
+ """
+
+ # Get the tutorial path
+ bundler = TutorialBundler(tutorial_guid)
+ tutorial_path = bundler.get_tutorial_path(tutorial_guid)
+ # Get the file name
+ fname_splitted = file_path.rsplit('/')
+ file_name = fname_splitted[fname_splitted.__len__() - 1]
+ # Append unique name to file name
+ file_name_appended = file_name + '_' + str(uuid.uuid1())
+ # Check if the ressource file exists
+ file_path = os.path.join(tutorial_path, ressource_id)
+ if os.path.isfile(file_path):
+ # Copy the ressource file in the vault
+ shutil.copyfile(file_path, os.path.join(tutorial_path, file_name_appended))
+ return file_name_appended
+ else:
+ return None
+
+
+ @staticmethod
+ def delete_ressource(tutorial_guid, ressource_id):
+ """
+ Delete the resource from the resources of the tutorial.
+ @param tutorial_guid the guid of the tutorial
+ @param ressource_id the ressource id of the ressource to delete
+ """
+ # Get the tutorial path
+ bundler = TutorialBundler(tutorial_guid)
+ tutorial_path = bundler.get_tutorial_path(tutorial_guid)
+ # Check if the ressource file exists
+ file_path = os.path.join(tutorial_path, ressource_id)
+ if os.path.isfile(file_path):
+ # Delete the ressource
+ os.delete(os.path.join(tutorial_path, ressource_id))
+
+
+ @staticmethod
+ def get_ressource_path(tutorial_guid, ressource_id):
+ """
+ Returns the absolute file path to the resourceID
+ @param tutorial_guid the guid of the tutorial
+ @param ressource_id the ressource id of the ressource to find the path for
+ @returns the absolute path of the ressource file
+ """
+ # Get the tutorial path
+ bundler = TutorialBundler(tutorial_guid)
+ tutorial_path = bundler.get_tutorial_path(tutorial_guid)
+ # Check if the ressource file exists
+ file_path = os.path.join(tutorial_path, ressource_id)
+ if os.path.isfile(file_path):
+ return file_path
+ else:
+ return None
+
class Serializer(object):
"""