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 argparse 

21from toktokkie.commands.Command import Command 

22from toktokkie.Directory import Directory 

23from toktokkie.utils.update import updaters, perform_update 

24 

25 

26class UpdateCommand(Command): 

27 """ 

28 Class that encapsulates behaviour of the update command 

29 """ 

30 

31 @classmethod 

32 def name(cls) -> str: 

33 """ 

34 :return: The command name 

35 """ 

36 return "update" 

37 

38 @classmethod 

39 def help(cls) -> str: 

40 """ 

41 :return: The help message for the command 

42 """ 

43 return "Updates directory with new episodes/chapters etc" 

44 

45 @classmethod 

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

47 """ 

48 Prepares an argumentparser for this command 

49 :param parser: The parser to prepare 

50 :return: None 

51 """ 

52 cls.add_directories_arg(parser) 

53 

54 parser.add_argument("--dry-run", action="store_true", 

55 help="Does not download or rename anything") 

56 

57 # xdcc 

58 parser.add_argument("--create", action="store_true", 

59 help="If this flag is set, " 

60 "will generate new update instructions") 

61 parser.add_argument("-t", "--throttle", default=-1, 

62 help="Limits the download speed of xdcc-dl. " 

63 "Append K,M or G for more convenient units") 

64 parser.add_argument("--timeout", default=120, type=int, 

65 help="Sets a timeout for starting " 

66 "the xdcc-dl download") 

67 

68 # manga 

69 parser.add_argument("--no-check-newest-chapter-length", 

70 action="store_true", 

71 help="Deactivates checking the latest manga " 

72 "chapter for completeness") 

73 parser.add_argument("--skip-special", action="store_true", 

74 help="Skips updating special manga chapters") 

75 

76 def execute(self): 

77 """ 

78 Executes the commands 

79 :return: None 

80 """ 

81 for directory in Directory.load_directories(self.args.directories): 

82 

83 metadata = directory.metadata 

84 args = { 

85 "dry_run": False, 

86 "create": False, 

87 "throttle": -1, 

88 "timeout": 120, 

89 "no_check_newest_chapter_length": False, 

90 "skip_special": False 

91 } 

92 args.update(dict(self.args.__dict__)) 

93 

94 applicable_updaters = [ 

95 x for x in updaters 

96 if metadata.media_type() in x.applicable_media_types() 

97 ] 

98 perform_update(args, metadata, applicable_updaters)