示例#1
0
    def import_activity_from_file(self, activity_file):
        from activities.PhotoPresentation import PhotoPresentation
        from activities.SoundPresentation import SoundPresentation
        from activities.VideoPresentation import VideoPresentation
        from activities.AssociatedKeyActivity import AssociatedKeyActivity
        from activities.ManualDefinedActivity import ManualDefinedActivity

        try:
            activity_folder = CONF_DIR
            unpack_tar_file_and_remove(activity_file, activity_folder)
            files = os.listdir(os.path.join(activity_folder, "activity_auxiliary_folder"))
            class_dict = {
                "photo.xml": PhotoPresentation,
                "sound.xml": SoundPresentation,
                "video.xml": VideoPresentation,
                "key.xml": AssociatedKeyActivity,
                "manual.xml": ManualDefinedActivity,
            }
            for file_name in class_dict.keys():
                if file_name in files:
                    shutil.rmtree(os.path.join(activity_folder, "activity_auxiliary_folder"))
                    activity = class_dict[file_name].import_from_file(activity_file)
                    self.xml_mapper.save_activity(activity)
                    self.refresh_activities()
                    break
        except OSError:
            raise TarFileNotValid()
    def import_from_file(cls, file_path):
        from dao.XMLUtils import get_activity_object_from_xml

        activity_folder = CONF_DIR
        unpack_tar_file_and_remove(file_path, activity_folder)
        with open(os.path.join(activity_folder, "activity_auxiliary_folder", "manual.xml"), "rt") as f:
            activity = get_activity_object_from_xml(f)
            shutil.rmtree(os.path.join(activity_folder, "activity_auxiliary_folder"))
        return activity
示例#3
0
    def import_from_file(cls, file_path):
        from dao.XMLUtils import get_activity_object_from_xml

        activity_folder = CONF_DIR
        unpack_tar_file_and_remove(file_path, activity_folder)
        folder_name = os.path.join(activity_folder, str(uuid.uuid4()))
        os.rename(os.path.join(activity_folder, "activity_auxiliary_folder"), folder_name)
        with open(os.path.join(folder_name, "video.xml"), "rt") as f:
            activity = get_activity_object_from_xml(f)
        for i, tag in enumerate(activity.tags):
            tag.path = os.path.join(folder_name, str(i), os.path.basename(tag.path))
        return activity
    def import_from_file(cls, file_path):
        from dao.XMLUtils import get_activity_object_from_xml

        activity_folder = CONF_DIR
        unpack_tar_file_and_remove(file_path, activity_folder)
        with open(
                os.path.join(activity_folder, "activity_auxiliary_folder",
                             "key.xml"), "rt") as f:
            activity = get_activity_object_from_xml(f)
            shutil.rmtree(
                os.path.join(activity_folder, "activity_auxiliary_folder"))
        return activity
示例#5
0
    def import_from_file(cls, file_path):
        from dao.XMLUtils import get_activity_object_from_xml

        activity_folder = CONF_DIR
        unpack_tar_file_and_remove(file_path, activity_folder)
        folder_name = os.path.join(activity_folder, str(uuid.uuid4()))
        os.rename(os.path.join(activity_folder, "activity_auxiliary_folder"), folder_name)
        with open(os.path.join(folder_name, "photo.xml"), "rt") as f:
            activity = get_activity_object_from_xml(f)
        for i, tag in enumerate(activity.tags):
            tag.path = os.path.join(folder_name, str(i))
            for sound in tag.sounds:
                sound.path = os.path.join(tag.path, "sounds", os.path.basename(sound.path))
        return activity
示例#6
0
 def import_activity_from_file(self, activity_file):
     from activities.PhotoPresentation import PhotoPresentation
     from activities.SoundPresentation import SoundPresentation
     from activities.VideoPresentation import VideoPresentation
     from activities.AssociatedKeyActivity import AssociatedKeyActivity
     from activities.ManualDefinedActivity import ManualDefinedActivity
     try:
         activity_folder = CONF_DIR
         unpack_tar_file_and_remove(activity_file, activity_folder)
         files = os.listdir(os.path.join(activity_folder, "activity_auxiliary_folder"))
         class_dict = {"photo.xml": PhotoPresentation,
                       "sound.xml": SoundPresentation,
                       "video.xml": VideoPresentation,
                       "key.xml": AssociatedKeyActivity,
                       "manual.xml": ManualDefinedActivity}
         for file_name in class_dict.keys():
             if file_name in files:
                 shutil.rmtree(os.path.join(activity_folder, "activity_auxiliary_folder"))
                 activity = class_dict[file_name].import_from_file(activity_file)
                 self.xml_mapper.save_activity(activity)
                 self.refresh_activities()
                 break
     except OSError:
         raise TarFileNotValid()