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#!/usr/bin/env python 

2# -*- coding: utf-8 -*- 

3 

4# This file is part of Vallenato.fr. 

5# 

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

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

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

9# (at your option) any later version. 

10# 

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

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

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

14# GNU Affero General Public License for more details. 

15# 

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

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

18 

19import argparse 

20import logging 

21import sys 

22from aprender import aprender 

23from website import website 

24 

25def parse_args(arguments): 

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

27 group = parser.add_mutually_exclusive_group(required=True) 

28 group.add_argument("-a", "--aprender", action='store_true', required=False, help="Create a new tutorial for vallenato.fr/aprender") 

29 group.add_argument("-w", "--website", action='store_true', required=False, help="Regenerate the Vallenato.fr website (but not the /aprender section)") 

30 

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

32 parser.add_argument("-tf", "--temp-folder", action='store_true', required=False, help="Create the new tutorial in the ./temp folder, do not update the index page with the new links") 

33 parser.add_argument("-nd", "--no-download", action='store_true', required=False, help="Do not download the videos from YouTube") 

34 

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

36 #TODO 

37 parser.add_argument("-duv", "--dump-uploaded-videos", action='store_true', required=False, help="Dump the list of uploaded videos from YouTube, so as not to have to download it again") 

38 

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

40 parser.add_argument( 

41 '-d', '--debug', 

42 help="Print lots of debugging statements", 

43 action="store_const", dest="loglevel", const=logging.DEBUG, 

44 default=logging.WARNING, 

45 ) 

46 parser.add_argument( 

47 '-v', '--verbose', 

48 help="Be verbose", 

49 action="store_const", dest="loglevel", const=logging.INFO, 

50 ) 

51 args = parser.parse_args(arguments) 

52 

53 # Validate if the arguments are used correctly 

54 if args.temp_folder and not args.aprender: 

55 logging.critical("The --temp-folder argument can only be used in conjunction with --aprender. Exiting...") 

56 sys.exit(16) 

57 if args.no_download and not args.aprender: 

58 logging.critical("The --no-download argument can only be used in conjunction with --aprender. Exiting...") 

59 sys.exit(17) 

60 if args.dump_uploaded_videos and not args.website: 

61 logging.critical("The --dump-uploaded-videos argument can only be used in conjunction with --website. Exiting...") 

62 sys.exit(18) 

63 

64 # Configure logging level 

65 if args.loglevel: 

66 logging.basicConfig(level=args.loglevel) 

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

68 

69 # Needed for the Youtube integration 

70 args.noauth_local_webserver = True 

71 

72 logging.debug("These are the parsed arguments:\n'%s'" % args) 

73 return args 

74 

75def main(): 

76 # Parse the provided command-line arguments 

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

78 

79 # --aprender 

80 if args.aprender: 

81 aprender(args) 

82 elif args.website: 

83 website(args) 

84 

85def init(): 

86 if __name__ == "__main__": 

87 main() 

88 

89init()