-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path42PyChecker.py
251 lines (217 loc) · 13.5 KB
/
42PyChecker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
"""
Copyright (C) 2018 Jules Lasne <jules.lasne@gmail.com>
See full notice in `LICENSE'
"""
import os
import argparse
import platform
from PyChecker.projects import libft, ft_commandements, other, fillit
from PyChecker.window import Application
import sys
import logging
def check_args_rules(parser, args):
"""
--verbose: Optionnal, no rules there.
--no-gui: Enabled by default,
--project: Required, Has a choice.
--path: Required.
--no-author: Optionnal, no rules here expect 42commandements
--no-forbidden-functions: Optionnal, can only be set when project=fdf|fillit|ft_ls|ft_p|ft_printf|gnl\libft|libftasm|minishell|pushswap
--no-makefile: Optionnal, no rules here expect 42commandements
--no-norm: Optionnal, no rules here expect 42commandements
--no-static: Optionnal, can only be set when project=libft
--no-extra: Optionnal, can only be set when project=libft
--no-required: Optionnal, can only be set when project=libft
--no-bonus: Optionnal, can only be set when project=libft
--do-benchmark: Optionnal, can only be set when project=libft
--no-tests: Optionnal, can only be set when project is not other.
--no-libftest: Optionnal, can only be set when project=libft
--no-maintest: Optionnal, can only be set when project=libft|gnl|ft_ls
--no-moulitest: Optionnal, can only be set when project=libft|gnl|ft_ls|ft_printf|libftasm
--no-fillit-checker: Optionnal, can only be set when project=fillit
--no-libft-unit-test: Optionnal, can only be set when project=libft
:param args: the parsed arguments passed to the program
"""
logging.info("Starting argument checking.")
# If no project is given the parser sends an error.
if args.project is None:
logging.critical('You need to specify a project.')
parser.error("You need to specify a project.")
# If the path of the selected project is empty, the parser prints an error.
if args.path == "":
logging.critical("`--path' needs to be specified in order for 42PyChecker"
" to know where your project is.")
parser.error("`--path' needs to be specified in order for 42PyChecker"
" to know where your project is.")
if args.path[0] != '/':
logging.critical("`--path' needs to have an absolute path")
parser.error("`--path' needs to have an absolute path")
# If a test is disabled and the libft project is selected, the parser will
# return an error.
# Here, if the `--no-tests` option is set, all the testing suites will be
# disabled, no matter the project.
if args.project == "other" and args.no_tests:
logging.critical("`--no-tests' Can only be applied on projects, not when 'other' is selected.")
parser.error("`--no-tests' Can only be applied on projects, not when 'other' is selected.")
if args.no_author and args.project == "42commandements":
logging.critical("`--no-author' Can only be applied on project, but not on 42commandements.")
parser.error("`--no-author' Can only be applied on project, but not on 42commandements.")
forbidden_functions_projects = ['fdf', 'fillit', 'ft_ls', 'ft_p', 'ft_printf', 'gnl', 'get_next_line', 'libft', 'libftasm', 'libft_asm', 'minishell', 'pushswap', 'push_swap']
if args.no_forbidden_functions and args.project not in forbidden_functions_projects:
logging.critical("`--no-forbidden-functions' Cannot be set if project isn't one of " + str(forbidden_functions_projects))
parser.error("`--no-forbidden-functions' Cannot be set if project isn't one of " + str(forbidden_functions_projects))
if args.no_makefile and args.project == "42commandements":
logging.critical("`--no-makefile' Can only be applied on project, but not on 42commandements.")
parser.error("`--no-makefile' Can only be applied on project, but not on 42commandements.")
if args.no_norm and args.project == "42commandements":
logging.critical("`--no-norm' Can only be applied on project, but not on 42commandements.")
parser.error("`--no-norm' Can only be applied on project, but not on 42commandements.")
if args.no_static and args.project != "libft":
logging.critical("`--no-static' Can only be applied project `libft'")
parser.error("`--no-static' Can only be applied project `libft'")
if args.no_extra and args.project != "libft":
logging.critical("`--no-extra' Can only be applied project `libft'")
parser.error("`--no-extra' Can only be applied project `libft'")
if args.no_required and args.project != "libft":
logging.critical("`--no-required' Can only be applied project `libft'")
parser.error("`--no-required' Can only be applied project `libft'")
if args.no_bonus and args.project != "libft":
logging.critical("`--no-bonus' Can only be applied project `libft'")
parser.error("`--no-bonus' Can only be applied project `libft'")
if args.do_benchmark and args.project != "libft":
logging.critical("`--do-benchmark' Can only be applied project `libft'")
parser.error("`--do-benchmark' Can only be applied project `libft'")
if args.no_libftest and args.project != "libft":
logging.critical("`--no-libftest' can only be applied if libft is selected "
"with `--project'")
parser.error("`--no-libftest' can only be applied if libft is selected "
"with `--project'")
if args.no_maintest and args.project != "libft":
logging.critical("`--no-maintest' can only be applied if libft is selected "
"with `--project'")
parser.error("`--no-maintest' can only be applied if libft is selected "
"with `--project'")
if args.no_moulitest and args.project != "libft":
logging.critical("`--no-moulitest' can only be applied if libft is selected"
" with `--project'")
parser.error("`--no-moulitest' can only be applied if libft is selected"
" with `--project'")
if args.no_libft_unit_test and args.project != "libft":
logging.critical("`--no-libft-unit-test' can only be applied if libft is selected"
" with `--project'")
parser.error("`--no-libft-unit-test' can only be applied if libft is selected"
" with `--project'")
if args.no_fillit_checker and args.project != "fillit":
logging.critical("`--no-fillit-checker' can only be applied if fillit is selected"
" with `--project'")
parser.error("`--no-fillit-checker' can only be applied if fillit is selected"
" with `--project'")
if args.no_tests:
logging.debug("Option `--no-tests` selected. Setting all tests options to 'True' to disable them all")
args.no_libftest = True
args.no_maintest = True
args.no_moulitest = True
args.no_libft_unit_test = True
args.no_fillit_checker = True
logging.info("Argument checking done.")
def print_header():
"""
This function simply prints the warranty and condition statement.
Might be removed in the future
"""
print("\t42PyChecker Copyright (C) 2018-present Jules Lasne "
"<jules.lasne@gmail.com>\n\tThis program comes with"
" ABSOLUTELY NO WARRANTY; for details run with `--show-w'.\n\tThis is free"
" software, and you are welcome to redistribute it\n\tunder certain"
" conditions; run with `--show-c' for details.")
def main():
"""
Main function where arguments are parse and where the GUI is created.
"""
# Initialize the parser and get the path of the script to use as a reference.
root_path = os.path.dirname(os.path.realpath(__file__))
parser = argparse.ArgumentParser()
# @todo: Add verbose output
# Adds all the arguments one by one.
parser.add_argument("--log", help="Sets up the log output.",
choices=['debug', 'DEBUG', 'info', 'INFO', 'warning', 'WARNING', 'error', 'ERROR', 'critical', 'CRITICAL'], default='warning', const='warning', nargs='?',)
parser.add_argument("--no-gui", help="disables the Graphical User Interface",
action="store_true")
parser.add_argument("--project", help="Specifies the type of project you want to check", choices=['libft', '42commandements', 'other', 'fillit'], default=None)
parser.add_argument("--no-libftest", help="Disables Libftest", action="store_true")
parser.add_argument("--no-maintest", help="Disables Maintest", action="store_true")
parser.add_argument("--no-moulitest", help="Disables Moulitest", action="store_true")
parser.add_argument("--no-author", help="Disables author file check", action="store_true")
parser.add_argument("--no-forbidden-functions", help="Disables forbidden functions check", action="store_true")
parser.add_argument("--no-makefile", help="Disables Makefile check", action="store_true")
parser.add_argument("--no-norm", help="Disables norm check", action="store_true")
parser.add_argument("--no-static", help="Disables static functions check", action="store_true")
parser.add_argument("--no-extra", help="Disables stats and checks on your extra functions", action="store_true")
parser.add_argument("-p", "--path", help="The path of the project you want to test.", default="", type=str)
parser.add_argument("--show-w", help="Displays the warranty warning from the license.", action="store_true")
parser.add_argument("--show-c", help="Displays the conditions warning from the license.", action="store_true")
parser.add_argument("--no-tests", help="Disables all the testing suites for the project.", action="store_true")
parser.add_argument("--no-required", help="Disables required functions check", action="store_true")
parser.add_argument("--no-libft-unit-test", help="Disables libft-unit-test", action="store_true")
parser.add_argument("--do-benchmark", help="Enables libft-unit-test benchmarking", action="store_true")
parser.add_argument("--no-fillit-checker", help="Disables fillit_checker", action="store_true")
parser.add_argument("--no-bonus", help="Disables the bonus check for the libft", action="store_true")
# Calls the parser for the arguments we asked to implement.
args = parser.parse_args()
# If the argument `--show-w` is passed, the program will display the warranty
# statement and exit.
if args.show_w:
print("THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY"
" APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING\n"
" THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM"
" “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR\n"
" IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES"
" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE\n"
" ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS"
" WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME\n"
" THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.")
sys.exit()
# If the `--show-c` argument is passed, the program will display the License
# and exit.
if args.show_c:
with open(root_path + '/.github/LICENSE.lesser', 'r') as file:
print(file.read())
sys.exit()
# @todo: Fix error when log option not provided
# @todo: Check for log file size and delete it if needed.
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')
logging.info("************************************************************")
logging.info("***********Starting new instance of 42PyChecker*************")
logging.info("************************************************************")
# @todo: Format the args to be printed in log
logging.debug("Arguments passed : {}".format(args))
# Here we create the directory where the testing suites will be cloned
if not os.path.exists(root_path + '/testing_suites'):
logging.debug("The directory `{}/testing_suites` doesn't exist. Creating it".format(root_path))
os.makedirs(root_path + '/testing_suites')
if not args.no_gui:
app = Application(args)
check_args_rules(parser, args)
# Here we select the project and start the check based on the argument `--project`
if args.project == "libft":
logging.info("Starting {} project check".format(args.project))
libft.check(root_path, args)
if args.project == "42commandements":
logging.info("Starting {} project check".format(args.project))
ft_commandements.check(args)
if args.project == "fillit":
logging.info("Starting {} project check".format(args.project))
fillit.check(root_path, args)
if args.project == "other":
logging.info("Starting {} project check".format(args.project))
other.check(root_path, args)
if __name__ == '__main__':
if not platform.system() == "Windows":
try:
print_header()
main()
except KeyboardInterrupt:
sys.exit(1)
else:
#raise OSError("Sorry, this script can't be run on windows !")
main()