From f7442163bf2180d107f729b9d20fe549b4ec7020 Mon Sep 17 00:00:00 2001 From: charles Date: Thu, 16 Apr 2009 15:26:14 +0000 Subject: Add add_ressource --- diff --git a/src/sugar/tutorius/bundler.py b/src/sugar/tutorius/bundler.py index fc25b7a..d88c9e6 100644 --- a/src/sugar/tutorius/bundler.py +++ b/src/sugar/tutorius/bundler.py @@ -22,6 +22,7 @@ This module contains all the data handling class of Tutorius import logging import os +import shutil import uuid from sugar.tutorius import gtkutils, overlayer @@ -287,6 +288,28 @@ class TutorialBundler: def add_resources(self, typename, file): """ - Add ressources to metadata. + Add ressource in tutorial directory + return True if success or if file is already in tutorial directory + return False if file is a directory """ - NotImplementedError \ No newline at end of file + path = get_tutorial_path() + if os.path.isfile(file): + filename = os.split(file) + target = os.path.join(path,filename) + if os.path.samefile(file,target): + return True + else: + try: + shutil.copy(file,target) + return True + #This error is raised if the file already exists + except shutil.Error, err: + logger.debug(err) + return True + #General error for copying file + except IOError,err: + logger.debug(err) + return False + else: + logger.debug("file is a directory :"+file) + return False \ No newline at end of file -- cgit v0.9.1