Skip to content

Commit e7a0c2a

Browse files
committed
[FEATURE] Finished the check_norme method.
1 parent fa19646 commit e7a0c2a

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

42PyChecker.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
22
import sys
33
import glob
4+
import subprocess
5+
46

57
def check_author_file(project_path: str):
68
"""
@@ -46,18 +48,28 @@ def check_norme(project_path: str):
4648
:param project_path: The path of the project where you want to check the author file
4749
4850
:return: Returns 0 if everything is ok,
49-
1 if there isn't any file to check
51+
1 if there isn't any file to check,
52+
2 if some errors/warnings were found
5053
"""
5154
# @todo: Add a skip if norme is set as optional
5255
files = ""
53-
with open(os.path.dirname(os.path.realpath(__file__)) + "/.mynorme", 'w+') as file:
54-
for filename in glob.iglob(project_path + '/**/*.c', recursive=True):
55-
files = files + ' ' + filename
56-
for filename in glob.iglob(project_path + '/**/*.h', recursive=True):
57-
files = files + ' ' + filename
58-
if file == "":
56+
for filename in glob.iglob(project_path + '/**/*.c', recursive=True):
57+
files = files + ' ' + filename
58+
for filename in glob.iglob(project_path + '/**/*.h', recursive=True):
59+
files = files + ' ' + filename
60+
if files == "":
5961
print("No source file (.c) or header (.h) to check")
6062
return 1
63+
with open(os.path.dirname(os.path.realpath(__file__)) + "/.mynorme", 'w+') as file:
64+
result = subprocess.run('norminette' + files, shell=True, stdout=subprocess.PIPE).stdout.decode('utf-8')
65+
file.write(result)
66+
error_count = result.count('Error')
67+
warning_count = result.count('Warning')
68+
if error_count != 0 and warning_count != 0:
69+
print("Found {} errors and {} warnings".format(error_count, warning_count))
70+
return 2
71+
print("Normed passed")
72+
return 0
6173

6274

63-
sys.exit(check_norme("C:/Users/Jules/Share/ft_printf"))
75+
sys.exit(check_norme("/Users/jlasne/Clion/libft"))

0 commit comments

Comments
 (0)