Exemplo n.º 1
0
    def setUp(self):
        from klangbecken.cli import _check_data_dir, import_cmd

        self.current_path = os.path.dirname(os.path.realpath(__file__))
        self.data_dir = tempfile.mkdtemp()
        _check_data_dir(self.data_dir, create=True)

        self.playlog_script = os.path.join(self.data_dir, "playlog.sh")
        self.out_file = os.path.join(self.data_dir, "out.txt")

        # create simple script that writes some command line arguments into a file
        with open(self.playlog_script, "w") as f:
            print("#!/bin/sh", file=f)
            print(f"echo $1 > {self.out_file}", file=f)
            print(f"echo $3 >> {self.out_file}", file=f)
            print(f"echo $5 >> {self.out_file}", file=f)
        os.chmod(self.playlog_script, 0o700)

        # Correctly import a couple of files
        files = [
            os.path.join(self.current_path, "audio", "padded" + ext)
            for ext in "-jointstereo.mp3 -stereo.mp3".split()
        ]
        try:
            args = [self.data_dir, "jingles", files, True]
            with capture(import_cmd, *args) as (out, err, ret):
                pass
        except SystemExit as e:
            if e.code != 0:
                print(e, file=sys.stderr)
                raise (RuntimeError("Command execution failed"))
Exemplo n.º 2
0
    def testDataDirCheckOnly(self):
        from klangbecken.cli import _check_data_dir
        from klangbecken.settings import PLAYLISTS

        for playlist in PLAYLISTS + ("log", "upload"):
            path = os.path.join(self.tempdir, playlist)
            with self.assertRaises(Exception) as cm:
                _check_data_dir(self.tempdir, False)
            self.assertIn("Directory", cm.exception.args[0])
            self.assertIn("does not exist", cm.exception.args[0])
            os.mkdir(path)

        for playlist in PLAYLISTS:
            path = os.path.join(self.tempdir, playlist + ".m3u")
            with self.assertRaises(Exception) as cm:
                _check_data_dir(self.tempdir, False)
            self.assertIn("Playlist", cm.exception.args[0])
            self.assertIn("does not exist", cm.exception.args[0])
            with open(path, "a"):
                pass

        with self.assertRaises(Exception) as cm:
            _check_data_dir(self.tempdir, False)
        self.assertIn("File", cm.exception.args[0])
        self.assertIn("does not exist", cm.exception.args[0])

        with open(os.path.join(self.tempdir, "index.json"), "w"):
            pass

        _check_data_dir(self.tempdir, False)
Exemplo n.º 3
0
    def testDataDirCreation(self):
        from klangbecken.cli import _check_data_dir
        from klangbecken.settings import PLAYLISTS

        _check_data_dir(self.tempdir, create=True)
        for playlist in PLAYLISTS:
            path = os.path.join(self.tempdir, playlist)
            self.assertTrue(os.path.isdir(path))
            path += ".m3u"
            self.assertTrue(os.path.isfile(path))

        path = os.path.join(self.tempdir, "index.json")
        self.assertTrue(os.path.isfile(path))
        with open(path) as f:
            self.assertEqual(json.load(f), {})
Exemplo n.º 4
0
    def setUp(self):
        from klangbecken.cli import _check_data_dir, import_cmd

        self.current_path = os.path.dirname(os.path.realpath(__file__))
        self.data_dir = tempfile.mkdtemp()
        _check_data_dir(self.data_dir, create=True)

        # Correctly import a couple of files
        files = [
            os.path.join(self.current_path, "audio", "padded" + ext)
            for ext in "-jointstereo.mp3 -stereo.mp3".split()
        ]
        self.file_count = len(files)

        try:
            args = [self.data_dir, "jingles", files, True]
            with capture(import_cmd, *args) as (out, err, ret):
                pass
        except SystemExit as e:
            if e.code != 0:
                print(e, file=sys.stderr)
                raise (RuntimeError("Command execution failed"))

        for filename in os.listdir(os.path.join(self.data_dir, "jingles")):
            mutagenFile = File(os.path.join(self.data_dir, "jingles",
                                            filename),
                               easy=True)
            mutagenFile["cue_in"] = "0.0"
            mutagenFile["cue_out"] = "5.0"
            mutagenFile["track_gain"] = "-3.0 dB"
            mutagenFile.save()

        with open(os.path.join(self.data_dir, "index.json"), "r+") as f:
            data = json.load(f)
            for entry in data.values():
                entry["cue_in"] = 0.0
                entry["cue_out"] = 5.0
                entry["track_gain"] = "-3.0 dB"
            f.seek(0)
            f.truncate()
            json.dump(data, f)
Exemplo n.º 5
0
    def setUp(self):
        from klangbecken.cli import _check_data_dir, import_cmd

        self.current_path = os.path.dirname(os.path.realpath(__file__))
        self.tempdir = tempfile.mkdtemp()
        self.jingles_dir = os.path.join(self.tempdir, "jingles")
        _check_data_dir(self.tempdir, create=True)

        # Correctly import a couple of files
        files = [
            os.path.join(self.current_path, "audio", "padded" + ext)
            for ext in "-stereo.mp3 -jointstereo.mp3 -end-stereo.mp3".split()
        ]
        try:
            args = [self.tempdir, "jingles", files, True]
            with capture(import_cmd, *args) as (out, err, ret):
                pass
        except SystemExit as e:
            if e.code != 0:
                print(e, file=sys.stderr)
                raise (RuntimeError("Command execution failed"))