Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius
diff options
context:
space:
mode:
authormike <michael.jmontcalm@gmail.com>2009-11-06 03:30:36 (GMT)
committer mike <michael.jmontcalm@gmail.com>2009-11-06 03:30:36 (GMT)
commit134d1333acc68ac2ccd3b0459df1be948500f1a7 (patch)
treecf1bede0add5d00fda74a00e3bc6f72f4f310fcf /tutorius
parentc7c7f94fc5d7e9f7e4f175c06dd52628aa357e3d (diff)
parenta4bb559bee98c48a6a372a7ffc15b027e365ff6c (diff)
Merge branch 'lp458452' of ../mainline
Conflicts: tests/vaulttests.py tutorius/vault.py
Diffstat (limited to 'tutorius')
-rw-r--r--tutorius/vault.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/tutorius/vault.py b/tutorius/vault.py
index d6b4720..22fa940 100644
--- a/tutorius/vault.py
+++ b/tutorius/vault.py
@@ -74,6 +74,7 @@ NODE_SUBCOMPONENTLIST = "listproperty"
NAME_ATTR = "__name__"
NEXT_STATE_ATTR = "__next_state__"
START_STATE_ATTR = "__start_state__"
+RESSOURCES_FOLDER = 'ressources'
class Vault(object):
@@ -340,6 +341,74 @@ class Vault(object):
else:
return False
+
+ @staticmethod
+ def add_resource(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 file 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]
+ base_name, extension = os.path.splitext(file_name)
+ # Append unique name to file name
+ file_name_appended = base_name + '_' + str(uuid.uuid1()) + extension
+ # Check if the ressource file already exists
+ new_file_path = os.path.join(tutorial_path, RESSOURCES_FOLDER, file_name_appended)
+ if os.path.isfile(new_file_path) == False:
+ # Copy the ressource file in the vault
+ if os.path.isdir(os.path.join(tutorial_path, RESSOURCES_FOLDER)) == False:
+ os.makedirs(os.path.join(tutorial_path, RESSOURCES_FOLDER))
+ assert os.path.isfile(file_path)
+ shutil.copyfile(file_path, new_file_path)
+
+ return file_name_appended
+
+
+ @staticmethod
+ def delete_resource(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, RESSOURCES_FOLDER, ressource_id)
+ if os.path.isfile(file_path):
+ # Delete the ressource
+ os.remove(file_path)
+ else:
+ print('File not found, no delete took place')
+
+ @staticmethod
+ def get_resource_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, RESSOURCES_FOLDER, ressource_id)
+ if os.path.isfile(file_path):
+ return file_path
+ else:
+ return None
+
class Serializer(object):
"""