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"""
20import argparse
21from toktokkie.Directory import Directory
22from toktokkie.enums import MediaType
23from toktokkie.commands.Command import Command
24from toktokkie.exceptions import InvalidDirectoryState
27class MetadataGenCommand(Command):
28 """
29 Class that encapsulates behaviour of the metadata-gen command
30 """
32 @classmethod
33 def name(cls) -> str:
34 """
35 :return: The command name
36 """
37 return "metadata-gen"
39 @classmethod
40 def help(cls) -> str:
41 """
42 :return: The help message for the command
43 """
44 return "Creates new metadata configuration for a directory"
46 @classmethod
47 def prepare_parser(cls, parser: argparse.ArgumentParser):
48 """
49 Prepares an argumentparser for this command
50 :param parser: The parser to prepare
51 :return: None
52 """
53 # noinspection PyTypeChecker
54 media_types = list(map(lambda x: x.value, list(MediaType)))
55 parser.add_argument("media_type", choices=set(media_types),
56 help="The media type of the metadata")
57 cls.add_directories_arg(parser)
59 def execute(self):
60 """
61 Executes the commands
62 :return: None
63 """
64 for directory in self.args.directories:
66 try:
67 generated = Directory.prompt(
68 directory,
69 self.args.media_type
70 ).metadata
71 generated.print_folder_icon_source()
72 except InvalidDirectoryState as e:
73 self.logger.warning(f"Invalid state for directory {directory}:"
74 f" {e}")