Coverage for vallenato_fr.py: 100%

49 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-10-01 05:56 +0000

1#!/usr/bin/env python 

2 

3# This file is part of Vallenato.fr. 

4# 

5# Vallenato.fr is free software: you can redistribute it and/or modify 

6# it under the terms of the GNU Affero General Public License as published by 

7# the Free Software Foundation, either version 3 of the License, or 

8# (at your option) any later version. 

9# 

10# Vallenato.fr is distributed in the hope that it will be useful, 

11# but WITHOUT ANY WARRANTY; without even the implied warranty of 

12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

13# GNU Affero General Public License for more details. 

14# 

15# You should have received a copy of the GNU Affero General Public License 

16# along with Vallenato.fr. If not, see <http://www.gnu.org/licenses/>. 

17 

18import argparse 

19import logging 

20import sys 

21 

22from aprender import aprender 

23from website import website 

24 

25logger = logging.getLogger(__name__) 

26 

27 

28def parse_args(arguments): 

29 parser = argparse.ArgumentParser(description="Update the Vallenato.fr website") 

30 group = parser.add_mutually_exclusive_group(required=True) 

31 group.add_argument( 

32 "-a", 

33 "--aprender", 

34 action="store_true", 

35 required=False, 

36 help="Create a new tutorial for vallenato.fr/aprender", 

37 ) 

38 group.add_argument( 

39 "-w", 

40 "--website", 

41 action="store_true", 

42 required=False, 

43 help="Regenerate the Vallenato.fr website (but not the /aprender section)", 

44 ) 

45 

46 # These arguments are only to be used in conjunction with --aprender 

47 parser.add_argument( 

48 "-tf", 

49 "--temp-folder", 

50 action="store_true", 

51 required=False, 

52 help="Create the new tutorial in the ./temp folder, do not update the index page with the new links", 

53 ) 

54 parser.add_argument( 

55 "-nd", 

56 "--no-download", 

57 action="store_true", 

58 required=False, 

59 help="Do not download the videos from YouTube", 

60 ) 

61 

62 # These arguments are only to be used in conjunction with --website 

63 # TODO 

64 parser.add_argument( 

65 "-duv", 

66 "--dump-uploaded-videos", 

67 action="store_true", 

68 required=False, 

69 help="Dump the list of uploaded videos from YouTube, so as not to have to download it again", 

70 ) 

71 parser.add_argument( 

72 "-nf", 

73 "--no-fetch", 

74 action="store_true", 

75 required=False, 

76 help="Do not fetch anything from YouTube, rebuild the website from the " 

77 "already-committed website/src/data.js instead (e.g. to rebuild the " 

78 "production Docker image without live YouTube API credentials)", 

79 ) 

80 

81 # General arguments (can be used both with --aprender and --website) 

82 parser.add_argument( 

83 "-d", 

84 "--debug", 

85 help="Print lots of debugging statements", 

86 action="store_const", 

87 dest="loglevel", 

88 const=logging.DEBUG, 

89 default=logging.WARNING, 

90 ) 

91 parser.add_argument( 

92 "-v", 

93 "--verbose", 

94 help="Be verbose", 

95 action="store_const", 

96 dest="loglevel", 

97 const=logging.INFO, 

98 ) 

99 args = parser.parse_args(arguments) 

100 

101 # Validate if the arguments are used correctly 

102 if args.temp_folder and not args.aprender: 

103 logger.critical( 

104 "The --temp-folder argument can only be used in conjunction with --aprender. Exiting..." 

105 ) 

106 sys.exit(16) 

107 if args.no_download and not args.aprender: 

108 logger.critical( 

109 "The --no-download argument can only be used in conjunction with --aprender. Exiting..." 

110 ) 

111 sys.exit(17) 

112 if args.dump_uploaded_videos and not args.website: 

113 logger.critical( 

114 "The --dump-uploaded-videos argument can only be used in conjunction with --website. Exiting..." 

115 ) 

116 sys.exit(18) 

117 if args.no_fetch and not args.website: 

118 logger.critical( 

119 "The --no-fetch argument can only be used in conjunction with --website. Exiting..." 

120 ) 

121 sys.exit(22) 

122 if args.no_fetch and args.dump_uploaded_videos: 

123 logger.critical( 

124 "The --no-fetch and --dump-uploaded-videos arguments cannot be used together. Exiting..." 

125 ) 

126 sys.exit(23) 

127 

128 # Configure logging level 

129 if args.loglevel: 

130 logging.basicConfig(level=args.loglevel) 

131 args.logging_level = logging.getLevelName(args.loglevel) 

132 

133 # Needed for the Youtube integration 

134 args.noauth_local_webserver = True 

135 

136 logger.debug(f"These are the parsed arguments:\n'{args}'") 

137 return args 

138 

139 

140def main(): 

141 # Parse the provided command-line arguments 

142 args = parse_args(sys.argv[1:]) 

143 

144 # --aprender 

145 if args.aprender: 

146 aprender(args) 

147 elif args.website: 

148 website(args) 

149 

150 

151def init(): 

152 if __name__ == "__main__": 

153 main() 

154 

155 

156init()