77import platform
88from PyChecker .projects import libft , ft_commandements , other , fillit
99import sys
10+ import logging
1011
1112
1213def check_args_rules (parser , args ):
@@ -34,77 +35,103 @@ def check_args_rules(parser, args):
3435
3536 :param args: the parsed arguments passed to the program
3637 """
37-
38+ logging . info ( "Starting argument checking." )
3839 # If no project is given the parser sends an error.
3940 if args .project is None :
41+ logging .critical ('You need to specify a project.' )
4042 parser .error ("You need to specify a project." )
4143 # If the path of the selected project is empty, the parser prints an error.
4244 if args .path == "" :
45+ logging .critical ("`--path' needs to be specified in order for 42PyChecker"
46+ " to know where your project is." )
4347 parser .error ("`--path' needs to be specified in order for 42PyChecker"
4448 " to know where your project is." )
4549 if args .path [0 ] != '/' :
50+ logging .critical ("`--path' needs to have an absolute path" )
4651 parser .error ("`--path' needs to have an absolute path" )
4752 # If a test is disabled and the libft project is selected, the parser will
4853 # return an error.
4954
5055 # Here, if the `--no-tests` option is set, all the testing suites will be
5156 # disabled, no matter the project.
5257 if args .project == "other" and args .no_tests :
58+ logging .critical ("`--no-tests' Can only be applied on projects, not when 'other' is selected." )
5359 parser .error ("`--no-tests' Can only be applied on projects, not when 'other' is selected." )
5460
5561 if args .no_author and args .project == "42commandements" :
62+ logging .critical ("`--no-author' Can only be applied on project, but not on 42commandements." )
5663 parser .error ("`--no-author' Can only be applied on project, but not on 42commandements." )
5764
5865 forbidden_functions_projects = ['fdf' , 'fillit' , 'ft_ls' , 'ft_p' , 'ft_printf' , 'gnl' , 'get_next_line' , 'libft' , 'libftasm' , 'libft_asm' , 'minishell' , 'pushswap' , 'push_swap' ]
5966 if args .no_forbidden_functions and args .project not in forbidden_functions_projects :
67+ logging .critical ("`--no-forbidden-functions' Cannot be set if project isn't one of " + str (forbidden_functions_projects ))
6068 parser .error ("`--no-forbidden-functions' Cannot be set if project isn't one of " + str (forbidden_functions_projects ))
6169
6270 if args .no_makefile and args .project == "42commandements" :
71+ logging .critical ("`--no-makefile' Can only be applied on project, but not on 42commandements." )
6372 parser .error ("`--no-makefile' Can only be applied on project, but not on 42commandements." )
6473
6574 if args .no_norm and args .project == "42commandements" :
75+ logging .critical ("`--no-norm' Can only be applied on project, but not on 42commandements." )
6676 parser .error ("`--no-norm' Can only be applied on project, but not on 42commandements." )
6777
6878 if args .no_static and args .project != "libft" :
79+ logging .critical ("`--no-static' Can only be applied project `libft'" )
6980 parser .error ("`--no-static' Can only be applied project `libft'" )
7081
7182 if args .no_extra and args .project != "libft" :
83+ logging .critical ("`--no-extra' Can only be applied project `libft'" )
7284 parser .error ("`--no-extra' Can only be applied project `libft'" )
7385
7486 if args .no_required and args .project != "libft" :
87+ logging .critical ("`--no-required' Can only be applied project `libft'" )
7588 parser .error ("`--no-required' Can only be applied project `libft'" )
7689
7790 if args .no_bonus and args .project != "libft" :
91+ logging .critical ("`--no-bonus' Can only be applied project `libft'" )
7892 parser .error ("`--no-bonus' Can only be applied project `libft'" )
7993
8094 if args .do_benchmark and args .project != "libft" :
95+ logging .critical ("`--do-benchmark' Can only be applied project `libft'" )
8196 parser .error ("`--do-benchmark' Can only be applied project `libft'" )
8297
8398 if args .no_libftest and args .project != "libft" :
99+ logging .critical ("`--no-libftest' can only be applied if libft is selected "
100+ "with `--project'" )
84101 parser .error ("`--no-libftest' can only be applied if libft is selected "
85102 "with `--project'" )
86103
87104 if args .no_maintest and args .project != "libft" :
105+ logging .critical ("`--no-maintest' can only be applied if libft is selected "
106+ "with `--project'" )
88107 parser .error ("`--no-maintest' can only be applied if libft is selected "
89108 "with `--project'" )
90109
91110 if args .no_moulitest and args .project != "libft" :
111+ logging .critical ("`--no-moulitest' can only be applied if libft is selected"
112+ " with `--project'" )
92113 parser .error ("`--no-moulitest' can only be applied if libft is selected"
93114 " with `--project'" )
94115
95116 if args .no_libft_unit_test and args .project != "libft" :
117+ logging .critical ("`--no-libft-unit-test' can only be applied if libft is selected"
118+ " with `--project'" )
96119 parser .error ("`--no-libft-unit-test' can only be applied if libft is selected"
97120 " with `--project'" )
98121
99122 if args .no_fillit_checker and args .project != "fillit" :
123+ logging .critical ("`--no-fillit-checker' can only be applied if fillit is selected"
124+ " with `--project'" )
100125 parser .error ("`--no-fillit-checker' can only be applied if fillit is selected"
101126 " with `--project'" )
102127 if args .no_tests :
128+ logging .debug ("Option `--no-tests` selected. Setting all tests options to 'True' to disable them all" )
103129 args .no_libftest = True
104130 args .no_maintest = True
105131 args .no_moulitest = True
106132 args .no_libft_unit_test = True
107133 args .no_fillit_checker = True
134+ logging .info ("Argument checking done." )
108135
109136
110137def print_header ():
@@ -130,8 +157,8 @@ def main():
130157
131158 # @todo: Add verbose output
132159 # Adds all the arguments one by one.
133- parser .add_argument ("-v" , "--verbose " , help = "Increases output verbosity " ,
134- action = "store_true" )
160+ parser .add_argument ("--log " , help = "Sets up the log output. " ,
161+ choices = [ 'debug' , 'DEBUG' , 'info' , 'INFO' , 'warning' , 'WARNING' , 'error' , 'ERROR' , 'critical' , 'CRITICAL' ] )
135162 parser .add_argument ("--no-gui" , help = "disables the Graphical User Interface" ,
136163 action = "store_true" )
137164 parser .add_argument ("--project" , help = "Specifies the type of project you want to check" , choices = ['libft' , '42commandements' , 'other' , 'fillit' ], default = None )
@@ -176,22 +203,33 @@ def main():
176203 with open (root_path + '/.github/LICENSE.lesser' , 'r' ) as file :
177204 print (file .read ())
178205 sys .exit ()
179-
206+ # @todo: Check for log file size and delete it if needed.
207+ logging .basicConfig (filename = '42PyChecker.log' , level = args .log .upper (), format = '%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s' , datefmt = '%d-%m-%Y:%H:%M:%S' )
208+ logging .info ("************************************************************" )
209+ logging .info ("***********Starting new instance of 42PyChecker*************" )
210+ logging .info ("************************************************************" )
211+ # @todo: Format the args to be printed in log
212+ logging .debug ("Arguments passed : {}" .format (args ))
180213 check_args_rules (parser , args )
181214
182215 # Here we create the directory where the testing suites will be cloned
183216 if not os .path .exists (root_path + '/testing_suites' ):
217+ logging .debug ("The directory `{}/testing_suites` doesn't exist. Creating it" .format (root_path ))
184218 os .makedirs (root_path + '/testing_suites' )
185219
186220 # Here we select the project and start the check based on the argument `--project`
187221 if args .project == "libft" :
222+ logging .info ("Starting {} project check" .format (args .project ))
188223 libft .check (root_path , args )
189224 if args .project == "42commandements" :
225+ logging .info ("Starting {} project check" .format (args .project ))
190226 ft_commandements .check (args )
191- if args .project == "other" :
192- other .check (root_path , args )
193227 if args .project == "fillit" :
228+ logging .info ("Starting {} project check" .format (args .project ))
194229 fillit .check (root_path , args )
230+ if args .project == "other" :
231+ logging .info ("Starting {} project check" .format (args .project ))
232+ other .check (root_path , args )
195233
196234
197235if __name__ == '__main__' :
0 commit comments