Hide keyboard shortcuts

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> 

3 

4This file is part of toktokkie. 

5 

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. 

10 

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. 

15 

16You should have received a copy of the GNU General Public License 

17along with toktokkie. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19 

20import os 

21import argparse 

22from subprocess import Popen 

23from toktokkie.commands.Command import Command 

24from toktokkie.enums import MediaType 

25from toktokkie.Directory import Directory 

26 

27 

28class SetComicCoverCommand(Command): 

29 """ 

30 Class that encapsulates behaviour of the set-comic-cover command 

31 """ 

32 

33 @classmethod 

34 def name(cls) -> str: 

35 """ 

36 :return: The command name 

37 """ 

38 return "set-comic-cover" 

39 

40 @classmethod 

41 def help(cls) -> str: 

42 """ 

43 :return: The help message for the command 

44 """ 

45 return "Creates a comic cover cbz file" 

46 

47 @classmethod 

48 def prepare_parser(cls, parser: argparse.ArgumentParser): 

49 """ 

50 Prepares an argumentparser for this command 

51 :param parser: The parser to prepare 

52 :return: None 

53 """ 

54 cls.add_directories_arg(parser) 

55 

56 def execute(self): 

57 """ 

58 Executes the commands 

59 :return: None 

60 """ 

61 for directory in Directory.load_directories( 

62 self.args.directories, restrictions=[MediaType.COMIC] 

63 ): 

64 

65 cover = os.path.join(directory.metadata.icon_directory, "main.png") 

66 target = os.path.join(directory.path, "cover.cbz") 

67 if os.path.isfile(cover): 

68 if not os.path.isfile(target): 

69 Popen(["zip", "-j", target, cover]).wait() 

70 else: 

71 self.logger.warning("No cover for {}".format(directory.path))