Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2015 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of toktokkie.
6toktokkie is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11toktokkie is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with toktokkie. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20from abc import ABC
21from typing import Dict, Any
22from puffotter.os import listdir
23from toktokkie.exceptions import InvalidDirectoryState
24from toktokkie.metadata.base.Prompter import Prompter
25from toktokkie.metadata.book_series.BookSeriesExtras import BookSeriesExtras
28class BookSeriesPrompter(Prompter, BookSeriesExtras, ABC):
29 """
30 Implements the Prompter functionality for book series metadata
31 """
33 @classmethod
34 def pre_prompt_check(cls, directory_path: str):
35 """
36 Makes sure that the book series directory has at least one volume
37 :param directory_path: The path to the directory to check
38 :return: None
39 """
40 super().pre_prompt_check(directory_path)
41 filecount = len(listdir(directory_path, no_dirs=True))
42 if filecount == 0:
43 raise InvalidDirectoryState("No book files")
45 @classmethod
46 def prompt(cls, directory_path: str) -> Dict[str, Any]:
47 """
48 Generates new Metadata JSON using prompts for a directory
49 :param directory_path: The path to the directory for which to generate
50 the metadata object
51 :return: The generated metadata JSON
52 """
53 base = super().prompt(directory_path)
54 volumes = {} # type: Dict[str, Any]
55 id_fetcher = cls.create_id_fetcher(directory_path)
57 for i, (volume_name, _) in enumerate(
58 listdir(directory_path, no_dirs=True)
59 ):
60 print("Volume {} ({}):".format(i + 1, volume_name))
61 ids = cls.prompt_component_ids(
62 cls.valid_id_types(), base["ids"], id_fetcher
63 )
64 volumes[str(i + 1)] = {
65 "ids": ids
66 }
68 base.update({
69 "volumes": volumes
70 })
71 return base