コード例 #1
0
ファイル: generator.py プロジェクト: asrashley/music-bingo
 def check_options(cls, options: Options, songs: Sequence[Song]):
     """
     Check that the given options and song list allow a game to be
     generated.
     """
     num_songs = len(songs)
     if num_songs == 0:
         raise ValueError("Song list cannot be empty")
     if options.mode == GameMode.QUIZ:
         max_songs = len(Assets.QUIZ_COUNTDOWN_POSITIONS)
         if num_songs > max_songs:
             raise ValueError(
                 f'Maximum number of songs for a quiz is {max_songs}')
         return
     if options.mode != GameMode.BINGO:
         raise ValueError(f'Invalid mode {options.mode}')
     if options.game_id == '':
         raise ValueError("Game ID cannot be empty")
     min_songs = int(round(1.5 * options.songs_per_ticket() + 0.5))
     if num_songs < min_songs:
         raise ValueError(f'At least {min_songs} songs are required')
     if num_songs > cls.MAX_SONGS:
         raise ValueError(f'Maximum number of songs is {cls.MAX_SONGS}')
     if options.number_of_cards < cls.MIN_CARDS:
         raise ValueError(f'At least {cls.MIN_CARDS} tickets are required')
     max_cards = cls.combinations(num_songs, options.songs_per_ticket())
     if options.number_of_cards > max_cards:
         raise ValueError(f'{num_songs} songs only allows ' +
                          f'{max_cards} cards to be generated')
コード例 #2
0
ファイル: generator.py プロジェクト: asrashley/music-bingo
def main(args: Sequence[str]) -> int:
    """used for testing game generation without needing to use the GUI"""
    #pylint: disable=import-outside-toplevel
    from musicbingo.mp3 import MP3Factory

    options = Options.parse(args)
    if options.game_id == '':
        options.game_id = datetime.date.today().strftime("%y-%m-%d")
    progress = TextProgress()
    mp3parser = MP3Factory.create_parser()
    clips = Directory(None, 0, options.clips())
    progress = TextProgress()
    clips.search(mp3parser, progress)
    sys.stdout.write('\n')
    sys.stdout.flush()
    num_songs = options.columns * options.rows * 2
    songs = clips.songs[:num_songs]
    if len(songs) < num_songs:
        for subdir in clips.subdirectories:
            todo = num_songs - len(songs)
            if todo < 1:
                break
            songs += subdir.songs[:todo]
    print('Selected {0} songs'.format(len(songs)))
    sys.stdout.flush()
    if len(songs) == 0:
        print('Error: failed to find any songs')
        return 1
    if options.title == '':
        options.title = Song.choose_collection_title(songs)
    mp3editor = MP3Factory.create_editor(options.mp3_engine)
    pdf = DocumentFactory.create_generator('pdf')
    gen = GameGenerator(options, mp3editor, pdf, progress)
    gen.generate(songs)
    return 0
コード例 #3
0
ファイル: directory.py プロジェクト: jdizzle1988/music-bingo
def main(args: Sequence[str]) -> int:
    """used for testing directory searching from the command line"""
    #pylint: disable=import-outside-toplevel
    from musicbingo.options import Options
    from musicbingo.mp3 import MP3Factory

    opts = Options.parse(args)
    mp3parser = MP3Factory.create_parser()
    clips = Directory(None, 1, Path(opts.clip_directory), mp3parser,
                      Progress())
    clips.search()
    return 0
コード例 #4
0
    def test_complete_bingo_game_pipeline(self, mock_randbelow, mock_shuffle):
        """
        Test of complete Bingo game generation
        """
        self.maxDiff = 500
        filename = self.fixture_filename(
            "test_complete_bingo_game_pipeline.json")
        with filename.open('r') as jsrc:
            expected = json.load(jsrc)
        mrand = MockRandom()
        mock_randbelow.side_effect = mrand.randbelow
        mock_shuffle.side_effect = mrand.shuffle
        opts = Options(
            game_id='test-pipeline',
            games_dest=str(self.tmpdir),
            number_of_cards=24,
            title='Game title',
            crossfade=0,
        )
        editor = MockMP3Editor()
        docgen = MockDocumentGenerator()
        progress = Progress()
        gen = GameGenerator(opts, editor, docgen, progress)
        gen.generate(self.directory.songs[:40])
        with open('results.json', 'w') as rjs:
            json.dump({
                "docgen": docgen.output,
                "editor": editor.output
            },
                      rjs,
                      indent=2,
                      sort_keys=True)
        self.assertEqual(len(docgen.output), 3)
        ticket_file = "test-pipeline Bingo Tickets - (24 Tickets).pdf"
        self.assert_dictionary_equal(expected['docgen'][ticket_file],
                                     docgen.output[ticket_file])

        results_file = "test-pipeline Ticket Results.pdf"
        self.assert_dictionary_equal(expected['docgen'][results_file],
                                     docgen.output[results_file])

        listings_file = "test-pipeline Track Listing.pdf"
        self.assert_dictionary_equal(expected['docgen'][listings_file],
                                     docgen.output[listings_file])

        self.assertEqual(len(editor.output), 1)
        mp3_file = "test-pipeline Game Audio.mp3"
        self.assert_dictionary_equal(expected['editor'][mp3_file],
                                     editor.output[mp3_file])
コード例 #5
0
 def mainloop(cls):
     """main loop"""
     root = tk.Tk()
     root.resizable(0, 0)
     root.wm_title("Music Bingo Game Generator")
     ico_file = Assets.icon_file()
     if ico_file.exists():
         if sys.platform.startswith('win'):
             root.iconbitmap(str(ico_file))
         else:
             logo = tk.PhotoImage(file=str(ico_file))
             root.call('wm', 'iconphoto', root._w, logo)
     options = Options.parse(sys.argv[1:])
     MainApp(root, options)
     root.mainloop()
コード例 #6
0
ファイル: directory.py プロジェクト: asrashley/music-bingo
def main(args: Sequence[str]) -> int:
    """used for testing directory searching from the command line"""
    #pylint: disable=import-outside-toplevel
    from musicbingo.options import Options
    from musicbingo.mp3 import MP3Factory

    log_format = "%(filename)s:%(lineno)d %(message)s"
    logging.basicConfig(format=log_format)
    logging.getLogger(__name__).setLevel(logging.DEBUG)
    opts = Options.parse(args)
    mp3parser = MP3Factory.create_parser()
    clips = Directory(None, 1, Path(opts.clip_directory))
    progress = TextProgress()
    clips.search(mp3parser, progress)
    print()
    print(clips.dump())
    return 0
コード例 #7
0
def main(args: Sequence[str]) -> int:
    """used for testing game generation without needing to use the GUI"""
    #pylint: disable=import-outside-toplevel
    from musicbingo.mp3 import MP3Factory
    class TextProgress(Progress):
        """displays progress on console"""
        def on_change_total_percent(self, total_percentage: float) -> None:
            print('{0}: {1:0.3f}'.format(self._text, total_percentage))

    options = Options.parse(args)
    if options.game_id == '':
        options.game_id = datetime.date.today().strftime("%y-%m-%d")
    progress = TextProgress()
    mp3parser = MP3Factory.create_parser()
    mp3editor = MP3Factory.create_editor()
    pdf = DocumentFactory.create_generator('pdf')
    clips = Directory(None, 0, options.clips(), mp3parser, progress)
    clips.search()
    gen = GameGenerator(options, mp3editor, pdf, progress)
    gen.generate(clips.songs[:30])
    return 0
コード例 #8
0
 def test_filename_generation(self):
     """
     Check filename generation
     """
     opts = Options.parse(['--id', '2020-02-14-1', 'Clips'])
     cwd = Path.cwd()
     self.assertEqual(opts.clips(), cwd / "Clips")
     games_dest = cwd / Path(opts.games_dest)
     self.assertEqual(opts.game_destination_dir(),
                      games_dest / 'Game-2020-02-14-1')
     outdir = opts.game_destination_dir()
     self.assertEqual(opts.mp3_output_name(),
                      outdir / '2020-02-14-1 Game Audio.mp3')
     self.assertEqual(opts.bingo_tickets_output_name(),
                      outdir / '2020-02-14-1 Bingo Tickets - (24 Tickets).pdf')
     self.assertEqual(opts.game_info_output_name(),
                      outdir / 'gameTracks.json')
     self.assertEqual(opts.track_listing_output_name(),
                      outdir / '2020-02-14-1 Track Listing.pdf')
     self.assertEqual(opts.ticket_results_output_name(),
                      outdir / '2020-02-14-1 Ticket Results.pdf')
     self.assertEqual(opts.ticket_checker_output_name(),
                      outdir / 'ticketTracks')