예제 #1
0
    def test_can_convert_android_incompatible_to_compatible_wav_file(self):
        for wav_path in self.adpcm_wavfile_paths():
            assert not wavconverter.is_android_compatible_wav(wav_path)
            converted_wav_path = os.path.join(self._testresult_folder_path, os.path.basename(wav_path))

            wavconverter.convert_to_android_compatible_wav(wav_path, converted_wav_path)

            assert wavconverter.is_android_compatible_wav(converted_wav_path)
예제 #2
0
        def write_mediafiles(original_to_converted_catrobat_resource_file_name):
            def resource_name_for(file_path):
                return common.md5_hash(file_path) + os.path.splitext(file_path)[1]

            for scratch_md5_name, src_path in self.scratch_project.md5_to_resource_path_map.iteritems():
                if scratch_md5_name in self.scratch_project.unused_resource_names:
                    log.info("Ignoring unused resource file: %s", src_path)
                    continue

                file_ext = os.path.splitext(scratch_md5_name)[1].lower()
                converted_file = False

                # TODO: refactor to a MediaConverter class
                if file_ext in {".png", ".svg", ".jpg", ".gif"}:
                    target_dir = images_path

                    if file_ext == ".svg":
                        # converting svg to png -> new md5 and filename
                        src_path = svgtopng.convert(src_path)
                        if not os.path.exists(src_path):
                            assert False, "Not existing: {}. Available files in directory: {}".format(src_path, os.listdir(os.path.dirname(src_path)))
                        converted_file = True

                elif file_ext in {".wav", ".mp3"}:
                    target_dir = sounds_path
                    if file_ext == ".wav":
                        if not wavconverter.is_android_compatible_wav(src_path):
                            temp_path = src_path.replace(".wav", "converted.wav")
                            wavconverter.convert_to_android_compatible_wav(src_path, temp_path)
                            src_path = temp_path
                            converted_file = True

                else:
                    assert file_ext in {".json"}, "Unknown media file extension: %s" % src_path
                    continue

                assert os.path.exists(src_path), "Not existing: {}. Available files in directory: {}".format(src_path, os.listdir(os.path.dirname(src_path)))

                # for Catrobat separate file is needed for resources which are used multiple times but with different names
                for scratch_resource_name in self.scratch_project.find_all_resource_names_for(scratch_md5_name):
                    catrobat_resource_file_name = self._catrobat_resource_file_name_for(scratch_md5_name, scratch_resource_name)
                    if converted_file:
                        original_resource_file_name = catrobat_resource_file_name
                        converted_scratch_md5_name = resource_name_for(src_path)
                        converted_resource_file_name = self._catrobat_resource_file_name_for(converted_scratch_md5_name, scratch_resource_name)
                        catrobat_resource_file_name = original_to_converted_catrobat_resource_file_name[original_resource_file_name] = converted_resource_file_name
                        assert catrobat_resource_file_name != original_resource_file_name
                    shutil.copyfile(src_path, os.path.join(target_dir, catrobat_resource_file_name))
                if converted_file:
                    os.remove(src_path)
예제 #3
0
 def test_can_convert_android_incompatible_to_compatible_wav_file(self):
     for wav_path in self.adpcm_wavfile_paths():
         assert not wavconverter.is_android_compatible_wav(wav_path)
         converted_wav_path = wavconverter.convert_to_android_compatible_wav(
             wav_path)
         assert wavconverter.is_android_compatible_wav(converted_wav_path)
         os.remove(converted_wav_path)
예제 #4
0
 def test_fail_on_missing_sox_binary(self):
     saved_path_env = os.environ[_ENV_PATH]
     os.environ[_ENV_PATH] = ""
     dummy_wav = self.adpcm_wavfile_paths()[0]
     try:
         wavconverter.is_android_compatible_wav(dummy_wav)
         self.fail("Expected exception 'EnvironmentError' not thrown")
     except EnvironmentError:
         try:
             wavconverter.convert_to_android_compatible_wav(dummy_wav, "dummy.wav")
             self.fail("Expected exception 'EnvironmentError' not thrown")
         except EnvironmentError:
             pass
         finally:
             assert not os.path.exists("dummy.wav")
     finally:
         os.environ[_ENV_PATH] = saved_path_env
    def run(self):
        old_src_path = self._kwargs["data"]["src_path"]
        media_type = self._kwargs["data"]["media_type"]
        info = self._kwargs["data"]["info"]

        if media_type == MediaType.UNCONVERTED_SVG:
            # converting svg to png -> new md5 and filename
            new_src_path = svgtopng.convert(old_src_path, info["rotationCenterX"], info["rotationCenterY"], ns_registry_lock)
        elif media_type == MediaType.UNCONVERTED_WAV:
            # converting Android-incompatible wav to compatible wav
            new_src_path = wavconverter.convert_to_android_compatible_wav(old_src_path)
        else:
            assert False, "Unsupported Media Type! Cannot convert media file: %s" % old_src_path

        self._kwargs["new_src_paths"][old_src_path] = new_src_path
        progress_bar = self._kwargs["progress_bar"]
        if progress_bar != None:
            progress_bar.update(ProgressType.CONVERT_MEDIA_FILE)
        assert os.path.exists(new_src_path), "Not existing: {}. Available files in directory: {}" \
               .format(new_src_path, os.listdir(os.path.dirname(new_src_path)))
예제 #6
0
    def run(self):
        old_src_path = self._kwargs["data"]["src_path"]
        media_type = self._kwargs["data"]["media_type"]
        info = self._kwargs["data"]["info"]

        if media_type == MediaType.UNCONVERTED_SVG:
            # converting svg to png -> new md5 and filename
            new_src_path = svgtopng.convert(old_src_path, info["rotationCenterX"], info["rotationCenterY"])
        elif media_type == MediaType.UNCONVERTED_WAV:
            # converting Android-incompatible wav to compatible wav
            new_src_path = wavconverter.convert_to_android_compatible_wav(old_src_path)
        else:
            assert False, "Unsupported Media Type! Cannot convert media file: %s" % old_src_path

        self._kwargs["new_src_paths"][old_src_path] = new_src_path
        progress_bar = self._kwargs["progress_bar"]
        if progress_bar != None:
            progress_bar.update(ProgressType.CONVERT_MEDIA_FILE)
        assert os.path.exists(new_src_path), "Not existing: {}. Available files in directory: {}" \
               .format(new_src_path, os.listdir(os.path.dirname(new_src_path)))
 def test_fail_on_missing_sox_binary(self):
     saved_path_env = os.environ[_ENV_PATH]
     os.environ[_ENV_PATH] = ""
     dummy_wav = self.adpcm_wavfile_paths()[0]
     output_path = None
     try:
         wavconverter.is_android_compatible_wav(dummy_wav)
         self.fail("Expected exception 'EnvironmentError' not thrown")
     except EnvironmentError:
         try:
             output_path = wavconverter.convert_to_android_compatible_wav(dummy_wav)
             self.fail("Expected exception 'EnvironmentError' not thrown")
         except EnvironmentError:
             pass
         finally:
             if output_path is not None:
                 output_file_exists = os.path.exists(output_path)
                 if output_file_exists:
                     os.remove(output_path)
                 assert not output_file_exists
     finally:
         os.environ[_ENV_PATH] = saved_path_env
예제 #8
0
 def test_fail_on_missing_sox_binary(self):
     saved_path_env = os.environ[_ENV_PATH]
     os.environ[_ENV_PATH] = ""
     dummy_wav = self.adpcm_wavfile_paths()[0]
     output_path = None
     try:
         wavconverter.is_android_compatible_wav(dummy_wav)
         self.fail("Expected exception 'EnvironmentError' not thrown")
     except EnvironmentError:
         try:
             output_path = wavconverter.convert_to_android_compatible_wav(
                 dummy_wav)
             self.fail("Expected exception 'EnvironmentError' not thrown")
         except EnvironmentError:
             pass
         finally:
             if output_path is not None:
                 output_file_exists = os.path.exists(output_path)
                 if output_file_exists:
                     os.remove(output_path)
                 assert not output_file_exists
     finally:
         os.environ[_ENV_PATH] = saved_path_env
 def test_can_convert_android_incompatible_to_compatible_wav_file(self):
     for wav_path in self.adpcm_wavfile_paths():
         assert not wavconverter.is_android_compatible_wav(wav_path)
         converted_wav_path = wavconverter.convert_to_android_compatible_wav(wav_path)
         assert wavconverter.is_android_compatible_wav(converted_wav_path)
         os.remove(converted_wav_path)